Advertisement

07.21.2008 at 11:59PM PDT, ID: 23584316 | Points: 500
[x]
Attachment Details

Acess the JtextArea control from other class running in another Thread

Asked by NaveenKhanna in New to Java Programming

Tags: Java,Swings

Hello

1)My Application Should Run Automatically(Unattended mode) -->solution i have used is Timer
2)My application Must Have tray icon------->Solution i have used Tray icon Class
3)In My application there is 2 control JtextArea displays status message of two classes Ex."Send.java" "Receive.Java"---Solution i have used jtextarea.append("Hello");

problem
1) When Program starts running i am not able to acess the User interface (Form)
2) i want acess the Trayicon where it contains popup "Exit" "Start"

I have tried SwingUtilities.invokeand wait(runnablee)
But it is not working as for me...?
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
//code snippet for timer
actionlistner t_ac=
 t_ac = new ActionListener() {
 
            public void actionPerformed(ActionEvent e) {
//                jButton1ActionPerformed(null);
//                jButton4ActionPerformed(null);
                //t_sendTRD.run();
                // t_RecvTRD.run();
                formWindowOpened(null);
            }
        };
        m_MainTmr = new Timer(1000, t_ac);
        m_MainTmr.start();
 
//To draw trayIcon
 
  private void DrawTrayIcon() {
        SystemTray tray = SystemTray.getSystemTray();
        Image image = Toolkit.getDefaultToolkit().getImage("C:\\Documents and Settings\\XML\\Globe.jpg");
        final JPopupMenu popup = new JPopupMenu();
        JMenuItem item = new JMenuItem("Exit");
        JMenuItem ite = new JMenuItem("jjklk");
 
        popup.add(item);
        popup.add(ite);
        TrayIcon trayIcon = new TrayIcon(image, "Right Click", null);
 
        javax.swing.Action t_acc = new javax.swing.Action() {
 
            public Object getValue(String key) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
 
            public void putValue(String key, Object value) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
 
            public void setEnabled(boolean b) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
 
            public boolean isEnabled() {
                throw new UnsupportedOperationException("Not supported yet.");
            }
 
            public void addPropertyChangeListener(PropertyChangeListener listener) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
 
            public void removePropertyChangeListener(PropertyChangeListener listener) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
 
            public void actionPerformed(ActionEvent e) {
                if (e.getActionCommand().equalsIgnoreCase("EXIT")) {
                    System.exit(0);
                }
            }
        };
 
        ite.addActionListener(t_acc);
        item.addActionListener(t_acc);
 
        trayIcon.addMouseListener(new MouseListener() {
 
            public void mouseClicked(MouseEvent e) {
            }
 
            public void mousePressed(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON3) {
                    if (e.isPopupTrigger()) {
                        try {
                            popup.setLocation(e.getX(), e.getY());
                            popup.setInvoker(popup);
                            popup.setVisible(true);
                            Thread.sleep(MouseEvent.MOUSE_EVENT_MASK);
                        } catch (InterruptedException ex) {
                            Logger.getLogger(ApprovalUtility.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
            }
 
            public void mouseReleased(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON3) {
                    if (e.isPopupTrigger()) {
                        popup.setLocation(e.getX(), e.getY());
                        popup.setInvoker(popup);
                        popup.setVisible(true);
                    }
                }
            }
 
            public void mouseEntered(MouseEvent e) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
 
            public void mouseExited(MouseEvent e) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        });
        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            System.err.println("Can't add to tray");
        }
    }
 
Keywords: Acess the JtextArea control from other…
 
Loading Advertisement...
 
[+][-]07.22.2008 at 12:08AM PDT, ID: 22056945

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 04:18AM PDT, ID: 22058044

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 04:23AM PDT, ID: 22058099

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 04:50AM PDT, ID: 22058291

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 04:54AM PDT, ID: 22058322

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.28.2008 at 11:22AM PDT, ID: 22338055

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628