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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 16 Files and Streams 909<br />

13 // Deitel packages<br />

14 import com.deitel.jhtp4.ch16.BankUI;<br />

15 import com.deitel.jhtp4.ch16.AccountRecord;<br />

16<br />

17 public class CreateSequentialFile extends JFrame {<br />

18 private ObjectOutputStream output;<br />

19 private BankUI userInterface;<br />

20 private JBut<strong>to</strong>n enterBut<strong>to</strong>n, openBut<strong>to</strong>n;<br />

21<br />

22 // set up GUI<br />

23 public CreateSequentialFile()<br />

24 {<br />

25 super( "Creating a Sequential File of Objects" );<br />

26<br />

27 // create instance of reusable user interface<br />

28 userInterface = new BankUI( 4 ); // four textfields<br />

29 getContentPane().add(<br />

30 userInterface, BorderLayout.CENTER );<br />

31<br />

32 // get reference <strong>to</strong> generic task but<strong>to</strong>n doTask1 in BankUI<br />

33 // and configure but<strong>to</strong>n for use in this program<br />

34 openBut<strong>to</strong>n = userInterface.getDoTask1But<strong>to</strong>n();<br />

35 openBut<strong>to</strong>n.setText( "Save in<strong>to</strong> File ..." );<br />

36<br />

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

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

39<br />

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

41 new ActionListener() {<br />

42<br />

43 // call openFile when but<strong>to</strong>n pressed<br />

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

45 {<br />

46 openFile();<br />

47 }<br />

48<br />

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

50<br />

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

52<br />

53 // get reference <strong>to</strong> generic task but<strong>to</strong>n doTask2 in BankUI<br />

54 // and configure but<strong>to</strong>n for use in this program<br />

55 enterBut<strong>to</strong>n = userInterface.getDoTask2But<strong>to</strong>n();<br />

56 enterBut<strong>to</strong>n.setText( "Enter" );<br />

57 enterBut<strong>to</strong>n.setEnabled( false ); // disable but<strong>to</strong>n<br />

58<br />

59 // register listener <strong>to</strong> call addRecord when but<strong>to</strong>n pressed<br />

60 enterBut<strong>to</strong>n.addActionListener(<br />

61<br />

62 // anonymous inner class <strong>to</strong> handle enterBut<strong>to</strong>n event<br />

63 new ActionListener() {<br />

64<br />

Fig. Fig. 16.6 16.6 16.6 Creating a sequential file (part 2 of 6).

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

Saved successfully!

Ooh no, something went wrong!