26.07.2013 Views

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

940 Files and Streams Chapter 16<br />

35 // register listener <strong>to</strong> call openFile when but<strong>to</strong>n pressed<br />

36 openBut<strong>to</strong>n.addActionListener(<br />

37<br />

38 // anonymous inner class <strong>to</strong> handle openBut<strong>to</strong>n event<br />

39 new ActionListener() {<br />

40<br />

41 // enable user <strong>to</strong> select file <strong>to</strong> open<br />

42 public void actionPerformed( ActionEvent event )<br />

43 {<br />

44 openFile();<br />

45 }<br />

46<br />

47 } // end anonymous inner class<br />

48<br />

49 ); // end call <strong>to</strong> addActionListener<br />

50<br />

51 // configure generic doTask2 but<strong>to</strong>n from BankUI<br />

52 nextBut<strong>to</strong>n = userInterface.getDoTask2But<strong>to</strong>n();<br />

53 nextBut<strong>to</strong>n.setText( "Next" );<br />

54 nextBut<strong>to</strong>n.setEnabled( false );<br />

55<br />

56 // register listener <strong>to</strong> call readRecord when but<strong>to</strong>n pressed<br />

57 nextBut<strong>to</strong>n.addActionListener(<br />

58<br />

59 // anonymous inner class <strong>to</strong> handle nextBut<strong>to</strong>n event<br />

60 new ActionListener() {<br />

61<br />

62 // read a record when user clicks nextBut<strong>to</strong>n<br />

63 public void actionPerformed( ActionEvent event )<br />

64 {<br />

65 readRecord();<br />

66 }<br />

67<br />

68 } // end anonymous inner class<br />

69<br />

70 ); // end call <strong>to</strong> addActionListener<br />

71<br />

72 // register listener for window closing event<br />

73 addWindowListener(<br />

74<br />

75 // anonymous inner class <strong>to</strong> handle windowClosing event<br />

76 new WindowAdapter() {<br />

77<br />

78 // close file and terminate application<br />

79 public void windowClosing( WindowEvent event )<br />

80 {<br />

81 closeFile();<br />

82 }<br />

83<br />

84 } // end anonymous inner class<br />

85<br />

86 ); // end call <strong>to</strong> addWindowListener<br />

87<br />

Fig. Fig. 16.14 16.14 Reading a random-access file sequentially (part 2 of 5).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!