Unable to update JDialog GUI inside a thread

tamer137

New Member
Please have a look at the following code\[code\]private class EmergencyAlertNotifier implements Runnable, ActionListener { JDialog dialog = new JDialog(); int number=0; JLabel message; JButton yes,no; String messageStr; public EmergencyAlertNotifier() { dialog.setLayout(new BorderLayout()); //The JLabel which will display the number of seconds left //before alerting emergency services message = new JLabel(); messageStr="number"; yes = new JButton("OK"); yes.addActionListener(this); no = new JButton("Cancel"); no.addActionListener(this); JPanel btnPanel = new JPanel(); btnPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); btnPanel.add(yes); btnPanel.add(no); dialog.add(message,"Center"); dialog.add(btnPanel,"South"); dialog.setTitle("Ready To Notify Emergency Fire Services"); dialog.setVisible(true); dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } @Override public void run() { for(int i=10;i>0;i--) { message.setText(messageStr+i+" Sec."); try { Thread.sleep(1000); } catch(Exception e) { e.printStackTrace(); } } } @Override public void actionPerformed(ActionEvent e) { if(e.getSource()==yes) { } else { dialog.dispose(); } } }\[/code\]Thread is started outside the above class\[code\] new Thread(new EmergencyAlertNotifier()).start();\[/code\]I am trying to update the JLabel with the changing numbers inside the thread. But instead, the JLabel is not coming to the GUI. Why is that? Please help!
 
Back
Top