Java Reference
In-Depth Information
25.
menu.add(startItem);
26.
MenuListener mListener = new MenuListener();
27.
startItem.addActionListener(mListener);
28. }
29.
30. public static void main(String[] args){
31.
System.out.println("Running in thread "+
Thread.currentThread().getName());
32.
33.
BlockingFrame bf = new BlockingFrame();
34.
bf.showIt("BlockingFrame");
35. }
36.
37. private void lengthyWork(){
38.
// This is the lengthy work
39.
for ( int i=0;i<10; i++){
40.
System.out.println("Working "+i);
41.
System.out.println("Running in thread "+
Thread.currentThread().getName());
42.
display.setText("Working "+i);
43.
try {
44.
Thread.sleep(500);
45.
} catch (Exception ex){
46.
ex.printStackTrace();
47.
}
48.
}// for i
49.
display.setText("Done");
50. }
51.
52. // Internal class
53. class MenuListener implements ActionListener{
54.
55.
public void actionPerformed(ActionEvent evt){
56.
57.
String command = evt.getActionCommand();
58.
if (command.equals("Start")){
59.
lengthyWork();
60.
}
61.
else
62.
{
63.
System.out.println("Unknown ActionCommand");
64.
System.exit(0);
65.
}
66. }
67. }// internal class
68. }
Search WWH ::




Custom Search