From: <whe...@us...> - 2003-07-24 20:13:28
|
Update of /cvsroot/ordweb/uop/pos407/wayneh/week5 In directory sc8-pr-cvs1:/tmp/cvs-serv14624 Modified Files: MailOrderWrite2.java MailOrderRead2.java Added Files: .classpath .project EventFile.java Log Message: init - samples for using for week5 assignment. --- NEW FILE: .classpath --- <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path=""/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path=""/> </classpath> --- NEW FILE: .project --- <?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>pos407w5</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription> --- NEW FILE: EventFile.java --- /* * Created on Jul 24, 2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ /** * @author Wayne Hernandez * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class EventFile { public static void main(String[] args) { MailOrderWrite2 cef = new MailOrderWrite2(); } } Index: MailOrderWrite2.java =================================================================== RCS file: /cvsroot/ordweb/uop/pos407/wayneh/week5/MailOrderWrite2.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MailOrderWrite2.java 24 Jul 2003 18:54:39 -0000 1.1 --- MailOrderWrite2.java 24 Jul 2003 19:49:39 -0000 1.2 *************** *** 0 **** --- 1,74 ---- + import java.io.*; + import java.awt.*; + import java.awt.event.*; + import javax.swing.*; + /* Writer for MailOrder application */ + + public class MailOrderWrite2 extends JFrame implements ActionListener + { + private JLabel companyName = new JLabel("Event Handlers Incorporated"); + Font bigFont = new Font("Helvetica", Font.ITALIC, 24); + private JLabel prompt = new JLabel("Enter this month's events"); + private JTextField host = new JTextField(10); + private JTextField date = new JTextField(4); + private JTextField guests = new JTextField(4); + private JLabel hLabel = new JLabel("Host"); + private JLabel dLabel = new JLabel("Date"); + private JLabel gLabel = new JLabel("Guests"); + private JButton enterDataButton = new JButton("Enter data"); + private Container con = getContentPane(); + DataOutputStream ostream; + public MailOrderWrite2() + { + super("Create Event File"); + try + { + ostream = new DataOutputStream (new FileOutputStream("events.dat")); + } + catch(IOException e) + { + System.err.println("File not opened"); + System.exit(1); + } + setSize(325,200); + con.setLayout(new FlowLayout()); + companyName.setFont(bigFont); + con.add(companyName); + con.add(prompt); + con.add(hLabel); + con.add(host); + con.add(dLabel); + con.add(date); + con.add(gLabel); + con.add(guests); + con.add(enterDataButton); + enterDataButton.addActionListener(this); + setVisible(true); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + + public void actionPerformed(ActionEvent e1) + { + int numGuests; + try + { + numGuests = Integer.parseInt(guests.getText()); + ostream.writeUTF(host.getText()); + ostream.writeUTF(date.getText()); + ostream.writeInt(numGuests); + host.setText(""); + date.setText(""); + guests.setText(""); + } + catch(NumberFormatException e2) + { + System.err.println("Invalid number of guests"); + } + catch(IOException e3) + { + System.err.println("Error writing file"); + System.exit(1); + } + } + + } \ No newline at end of file Index: MailOrderRead2.java =================================================================== RCS file: /cvsroot/ordweb/uop/pos407/wayneh/week5/MailOrderRead2.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MailOrderRead2.java 24 Jul 2003 18:54:39 -0000 1.1 --- MailOrderRead2.java 24 Jul 2003 19:49:39 -0000 1.2 *************** *** 0 **** --- 1,85 ---- + import java.io.*; + import java.awt.*; + import java.awt.event.*; + import javax.swing.*; + /* Reader for MailOrder application */ + + public class MailOrderRead2 extends JFrame implements ActionListener + { + private JLabel companyName = new JLabel("Event Handlers Incorporated"); + Font bigFont = new Font("Helvetica", Font.ITALIC, 24); + private JLabel prompt = new JLabel("View this month's events"); + private JTextField host = new JTextField(10); + private JTextField date = new JTextField(4); + private JTextField guests = new JTextField(4); + private JButton viewEventButton = new JButton("View Event"); + private JLabel hLabel = new JLabel("Host"); + private JLabel dLabel = new JLabel("Date"); + private JLabel gLabel = new JLabel("Guests"); + private Container con = getContentPane(); + DataInputStream istream; + public void ReadEventFile() + { + super("MailOrderRead2"); + try + { + istream = new DataInputStream(new FileInputStream("C:\\events.dat")); + } + catch(IOException e) + { + System.err.println("File not opened"); + System.exit(1); + } + setSize(325,200); + con.setLayout(new FlowLayout()); + companyName.setFont(bigFont); + con.add(companyName); + con.add(prompt); + con.add(hLabel); + con.add(dLabel); + con.add(date); + con.add(gLabel); + con.add(guests); + con.add(viewEventButton); + viewEventButton.addActionListener(this); + setVisible(true); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + public void actionPerformed(ActionEvent e) + { + String theHost, theDate; + int numGuests; + try + { + theHost = istream.readUTF(); + theDate = istream.readUTF(); + numGuests = istream.readInt(); + host.setText(theHost); + date.setText(theDate); + guests.setText(String.valueOf(numGuests)); + } + catch(EOFException e2) + { + closeFile(); + } + catch(IOException e3) + { + System.err.println("Error reading file"); + System.exit(1); + } + } + public void closeFile() + { + try + { + istream.close(); + System.exit(0); + } + catch(IOException e) + { + System.err.println("Error closing file"); + System.exit(1); + } + } + } + |