Need Help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Need Help

  1. #1
    Join Date
    Sep 2002
    Posts
    6

    Unhappy Need Help

    Yes I am a New student to Java and we were given a project were we have to make a java program to enroll students and then write to the txt file and also add the student number and add +1 to each enrolled student , but we can not find out how to do the increment the number with each student: this is what we have so far ? any help would be greatly appreciated.
    thank you
    Louie

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

    public class Student extends Frame implements ActionListener {
    MessageBox savedBox;
    MessageBox errorBox;
    DataOutputStream output;
    //Construct components
    Panel dataFields = new Panel();
    Panel firstRow = new Panel();
    Panel secondRow = new Panel();
    Panel thirdRow = new Panel();
    Panel fourthRow = new Panel();
    Panel fifthRow = new Panel();
    Panel sixthRow = new Panel();
    Panel seventhRow = new Panel();
    Panel buttonArea = new Panel();


    Button enrolled = new Button("New enroll");
    Button Returning = new Button("Returning");


    Label titleLabel = new Label("Welcome to Brad's school of Thought: ");


    Label studentLabel = new Label("StudentNumber: ");
    TextField student = new TextField(10);
    Label PhoneLabel = new Label("Phone: ");
    TextField Phone = new TextField(10);
    Label courseLabel = new Label("course: ");
    TextField course = new TextField(10);
    Label majorLabel = new Label("major: ");
    TextField major = new TextField(10);
    Label firstNameLabel = new Label("Enter First Name: ");
    TextField firstName = new TextField(15);
    Label lastNameLabel = new Label("Enter Last Name:");
    TextField lastName = new TextField(20);
    Label addressLabel = new Label("Enter Student Addresss:");
    TextField address = new TextField (35);



    public static void main(String[] args)
    {
    Student window = new Student();
    window.setTitle("Registation");
    window.setSize(550, 450);
    window.setVisible(true);
    }
    public Student()
    {
    Color myGray = new Color(227,203,168);
    //Set background and layout managers
    setBackground(myGray);
    Font titleFont = new Font(" Arial", Font.BOLD, 28);
    setLayout(new BorderLayout());
    dataFields.setLayout(new GridLayout(7,1));
    FlowLayout rowSetup = new FlowLayout(FlowLayout.LEFT,5,2);
    firstRow.setLayout(rowSetup);
    secondRow.setLayout(rowSetup);
    thirdRow.setLayout(rowSetup);
    fourthRow.setLayout(rowSetup);
    fifthRow.setLayout(rowSetup);
    sixthRow.setLayout(rowSetup);
    seventhRow.setLayout(rowSetup);

    buttonArea.setLayout(new FlowLayout());

    //Add fields to rows
    firstRow.add(titleLabel);
    firstRow.setFont(titleFont);

    secondRow.add(studentLabel);
    secondRow.add(PhoneLabel);
    secondRow.add(courseLabel);
    secondRow.add(majorLabel);


    thirdRow.add(student);
    thirdRow.add(Phone);
    thirdRow.add(course);
    thirdRow.add(major);

    fourthRow.add(firstNameLabel);
    fourthRow.add(lastNameLabel);

    fifthRow.add(firstName);
    fifthRow.add(lastName);

    sixthRow.add(addressLabel);


    //sixthRow.add(titleLabel);
    seventhRow.add(address);



    //Add rows to Panel
    dataFields.add(firstRow);
    dataFields.add(secondRow);
    dataFields.add(thirdRow);
    dataFields.add(fourthRow);
    dataFields.add(fifthRow);
    dataFields.add(sixthRow);
    dataFields.add(seventhRow);


    //Addbuttons to panel
    buttonArea.add(enrolled);
    buttonArea.add(Returning);

    //add panels to frame
    add(dataFields, BorderLayout.NORTH);
    add(buttonArea, BorderLayout.SOUTH);

    //Add Functionality to buttons
    enrolled.addActionListener(this);
    Returning.addActionListener(this);

    // Open the file
    try
    {
    output = new DataOutputStream(new FileOutputStream("Admin.dat",true));
    }
    catch(IOException ex)
    {
    System.exit(1);
    }
    //Construct window listener
    addWindowListener
    (
    new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    }
    );

    }
    public void actionPerformed(ActionEvent e)
    {
    String arg = e.getActionCommand();
    String code;
    if (arg == "New Student")
    code ="N";
    else
    code ="R";
    if
    (
    (student.getText().compareTo("")<1) ||
    (Phone.getText().compareTo("")<1) ||
    (course.getText().compareTo("")<1) ||
    (major.getText().compareTo("")<1) ||
    (firstName.getText().compareTo("")<1) ||
    (lastName.getText().compareTo("")<1) ||
    (address.getText().compareTo("")<1)
    )
    {
    errorBox = new MessageBox(this, "Data Entry Error", "You Must fill this out correctly cause Brad said!.");
    errorBox.setVisible(true);
    }
    else
    {
    try
    {
    output.writeUTF(code);
    output.writeUTF(student.getText());
    output.writeUTF(Phone.getText());
    output.writeUTF(course.getText());
    output.writeUTF(major.getText());
    output.writeUTF(firstName.getText());
    output.writeUTF(lastName.getText());
    output.writeUTF(address.getText());

    savedBox = new MessageBox(this, "Data submitted", "Your Student information has been saved.");
    savedBox.setVisible(true);
    }
    catch(IOException c)
    {
    System.exit(1);
    }
    clearFields();
    }
    }

    public void clearFields()
    {
    // Clear fields and reset the focus
    student.setText("");
    Phone.setText("");
    course.setText("");
    major.setText("");
    firstName.setText("");
    lastName.setText("");
    address.setText("");
    student.requestFocus();
    }

    }
    Louie Larabie

  2. #2
    Join Date
    Aug 2002
    Posts
    94
    Hi,
    can you just post the logic or flow of your code. Makes it simpler for others to point out solutions and attach lengthy codes as attachments or as URLs.

    After pointing the possible solution one just has to check the relevant portion of the code. It saves time for others who do not have to read voluminous code just to understand the logic/fucntionality of your program to even start thinking about solutions.


    bye

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center