Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java! Help Please!

Options
  • 26-02-2005 7:16pm
    #1
    Registered Users Posts: 1,052 ✭✭✭


    I've been sitting here for the last 2 hours trying to get this working! and i'm down to the last error and i can't get rid of it!

    The error is line 66: setLayout(new Flowlayout());

    heres the code:

    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;

    public class EmployeeWriteApp extends Frame implements ActionListener
    {
    //Declare stream objects
    FileOutputStream outputEmployee; //Stream to create file
    ObjectOutputStream objSaveEmployee; //Stream to save object

    //Declare components
    TextField txtEmployeeName = new TextField(25);
    TextField txtHireDate = new TextField(10);

    Button btnSave = new Button("Save");

    public static void main(String args[])
    {

    //Declare an instance of this application
    EmployeeWriteApp thisApp = new EmployeeWriteApp();
    thisApp.openStream();
    thisApp.createInterface();
    }

    public void openStream()
    {

    try
    {
    //Create file and object streams
    outputEmployee = new FileOutputStream("Employee.txt");
    objSaveEmployee = new ObjectOutputStream(outputEmployee);
    }
    catch(Exception error)
    {
    System.err.println("Error opening file");
    }
    }

    public void closeStream()
    {
    try
    {
    objSaveEmployee.close();//Close the object output stream
    outputEmployee.close();//close the file output stream
    }
    catch (IOException error)
    {
    System.err.println("Error closing file");
    }
    }

    public void createInterface()
    {
    //Set up user interface for this frame
    setTitle("Save Employee object");
    addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent event)
    {
    closeStream();
    System.exit(0);
    }
    });
    setLayout(new Flowlayout());
    add(new Label("Employee Name "));
    add(txtEmployeeName);
    txtEmployeeName.requestFocus();
    add(new Label("Hire Date "));
    add(txtHireDate);
    add(btnSave);
    btnSave.addActionListener(this);
    txtEmployeeName.addActionListener(this);
    txtHireDate.addActionListener(this);
    setSize(400, 300);
    setVisible(true);
    }

    public void actionPerformed(ActionEvent event)
    {
    //Save Employee object
    try
    {
    Employee empCurrent = new Employee(txtEmployeeName.getText(),txtHireDate.getText());
    objSaveEmployee.writeObject(empCurrent);
    objSaveEmployee.flush();
    txtEmployeeName.setText("");
    txtHireDate.setText("");
    txtEmployeeName.requestFocus();
    }
    catch(Exception error)
    {
    System.err.println("Error writing to file");
    }
    }
    }


Comments

  • Registered Users Posts: 3,548 ✭✭✭Draupnir


    wait, im wrong, heres what it is:

    new Flowlayout show be new FlowLayout with a capital L for Layout!!!!!!!!!!!!


  • Registered Users Posts: 1,052 ✭✭✭OmegaRed


    Draupnir wrote:
    wait, im wrong, heres what it is:

    new Flowlayout show be new FlowLayout with a capital L for Layout!!!!!!!!!!!!

    Thanks man! WHY did they have to make java case sensitive!!!!!


Advertisement