i am using following code in script console, script work in console fine, but not work
from button (basically its user Guide for operation)
'''
Import necessary modules
from java.awt import Color
from javax.swing import DefaultListModel, Timer
from javax.swing import JList
from javax.swing import JScrollPane
from javax.swing import JFrame
from java.awt import BorderLayout
Create a list model to store messages
messageListModel = DefaultListModel()
Function to add a message to the list
def addMessage(message):
messageListModel.addElement(message)
Function to clear all messages from the list
def clearMessages():
messageListModel.clear()
Create a JFrame to display the list
frame = JFrame("UGU")
frame.setSize(400, 300)
#frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
Create a JList with the message list model
messageList = JList(messageListModel)
Set some visual properties for the list
messageList.setBackground(Color.WHITE)
messageList.setForeground(Color.BLACK)
Create a scroll pane to hold the list
scrollPane = JScrollPane(messageList)
Add the scroll pane to the frame
frame.getContentPane().add(scrollPane, BorderLayout.CENTER)
Function to display the frame
def showFrame():
frame.setVisible(True)
Function to close the frame after 3 seconds
def closeFrame():
frame.dispose()
value1=True
value2=True
value3=False
Example usage:
if value1:
addMessage("Error: Pump 1 failure")
if value2:
addMessage("Warning: Tank level low")
if value3:
addMessage("Error: Pump 2 failure")
Call the function to display the frame
showFrame()
Schedule the frame to close after 3 seconds
timer = Timer(2000, lambda e: closeFrame())
timer.setRepeats(False)
timer.start()
'''