1/**
2 * Copyright(C) 1998
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : January 1, 1998.
11 * @author : Salih Yurttas.
12 */
13
14
15import java.awt.*;
16import java.awt.event.*;
17
18import java.io.*;
19
20public class NameFile01 extends Frame
21 implements ActionListener {
22
23 public static void main(String[] args)
24 throws IOException
25 {
26 Frame f = new NameFile01();
27
28 f.setSize(400, 200); // frame size set
29 f.setVisible(true); // frame displayed
30 }
31
32 private int NP = 2;
33 private Button[] bList = new Button[NP];
34 private TextField[] tFList = new TextField[NP];
35
36 private static IntegerList givenList;
37
38 class WindowEventClosing extends WindowAdapter {
39 public void windowClosing(WindowEvent e) {
40 System.exit (0);
41 }
42 }
43
44 public NameFile01()
45 throws IOException
46 {
47 setTitle("FileNameUI00");
48 this.addWindowListener(new WindowEventClosing());
49
50 setLayout(new FlowLayout());
51
52 Panel[] pList = new Panel[NP]; // create panels.
53 for(int i=0; i<NP; i++)
54 pList[i] = new Panel();
55
56 String[] lList = {"Input Filename",
57 "Output Filename"};
58
59 for(int i=0; i<NP; i++) {
60 tFList[i] = new TextField("", 24);
61 tFList[i].addActionListener(this);
62 pList[i].add(tFList[i]); // add textfields to the panels.
63 bList[i] = new Button(lList[i]); // create buttons with labels.
64 bList[i].addActionListener(this);
65 pList[i].add(bList[i]); // add buttons to the panels.
66 add(pList[i]); // add panels to the frame.
67 }
68 tFList[0].setText("Enter input filename");
69 tFList[1].setEditable(false);
70 bList[1].setEnabled(false);
71 }
72
73 public void actionPerformed(ActionEvent e) {
74 String arg = e.getActionCommand();
75
76 if (arg.equals("Input Filename")) {
77 try {
78 String inFileName = tFList[0].getText();
79 givenList = new IntegerList();
80 givenList.getIntegerList(inFileName);
81
82 tFList[0].setEditable(false);
83 bList[0].setEnabled(false);
84 tFList[0].setText("Input File is OK.");
85 tFList[1].setText("Enter output filename");
86 tFList[1].setEditable(true);
87 bList[1].setEnabled(true);
88 }
89 catch (IOException ioe) {
90 System.out.println("Error: " + ioe);
91 System.exit(0);
92 }
93 }
94 else {
95 try {
96 String outFileName = tFList[1].getText();
97 givenList.putIntegerList(outFileName);
98
99 tFList[1].setEditable(false);
100 bList[1].setEnabled(false);
101 tFList[1].setText("Output File is OK.");
102 tFList[0].setText("Enter input filename");
103 tFList[0].setEditable(true);
104 bList[0].setEnabled(true);
105 }
106 catch (IOException ioe) {
107 System.out.println("Error: " + ioe);
108 System.exit(0);
109 }
110 }
111 }
112
113}