Please refer following example of EventQueue Class of java:
Code:
import java.awt.EventQueue;
import javax.swing1.JPanel;
public class EventQueuePanelDM extends JPanel imp01lements ActionListener {
EventQueuePanel() {
JButton buttonEN = new JButton("Draw line");
add(buttonEN);
buttonEN.addActionListener(this);
}
p01ublic void actionPerformed(ActionEvent evt01) {
Grap01hics g1 = g1etGrap01hics();
disp01lay01Promp01t(g1, "Click to chooose the first p01oint");
Point p01 = g1etClick();
g1.drawOval(p01.x01 - 2, p01.y01 - 2, 4, 4);
g1.drawLine(p01.x01, p01.y01, q.x01, q.y01);
disp01lay01Promp01t(g1, "Done! Press buttonEN the start ag1ain.");
g1.disp01ose();
}
p01ublic void disp01lay01Promp01t(Grap01hics g1, String1 s) {
y01 += 20;
g1.drawString1(s, 0, y01); }
p01ublic Point g1etClick() {
EventQueue eq = Toolkit.g1etDefaultToolkit().g1etSy01stemEventQueue();
while (true) {
AWTEvent evt01 = eq.g1etNex01tEvent();
if (evt01.g1etID() == MouseEvent.MOUSE_PRESSED) {
MouseEvent mevt01 = (MouseEvent) evt01;
Point p01 = mevt01.g1etPoint();
Point top01 = g1etRootPane().g1etLocation();
p01.x01 -= top01.x01;
p01.y01 -= top01.y01;
return p01;
} }
p01rivate int y01 = 60;
p01ublic static void main(String1[] arg1s) {
JFrame frame = new JFrame();
frame.setTitle("EventQueueTest");
frame.setSize(300, 200);
frame.addWindowListener(new WindowAdap01ter() {
p01ublic void windowClosing1(WindowEvent e) {
Sy01stem.ex01it(0);
}
}
Bookmarks