Also, does anyone know how to add actionListeners to JOptionPane.showConfirmDialog buttons? That way I can tell what the input is when I ask the yes/no/cancel questions. Thanks so much for your help!
Edit: Sorry about not showing code, here it is.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
* Write a description of class GUI here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class GUI
{
private static Student student = new Student();
private static JFrame frame = new JFrame ("EDSOFT");
public static void main()
{
GUI.mainScreen(frame.getContentPane());
}
/**
* the default screen seen when the program starts.
*/
public static void mainScreen(Container pane)
{
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JLabel greeting = new JLabel ("Hello Elaine, what would you like to do?");
JButton changeName = new JButton ("Change the student's name");
JButton changeID = new JButton ("Change the student's ID#");
JButton enterGrades = new JButton ("Enter the student's grades");
JButton printReport = new JButton ("Print a grade report");
c.gridwidth = 4;
c.gridx = 0;
c.gridy = 0;
pane.add(greeting, c);
c.fill = GridBagConstraints.BOTH;
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 1;
pane.add(changeName, c);
changeName.addActionListener (new ActionListener()
{
/**
* go into changing the student's name.
*
* @param theEvent and ActionEvent
*/
public void actionPerformed (ActionEvent theEvent)
{
frame.setVisible(false);
frame.dispose();
GUI.changeStudentsName();
GUI.main();
}
});
c.gridx = 1;
c.gridy = 1;
pane.add(changeID, c);
changeID.addActionListener (new ActionListener()
{
/**
* respond to a button press.
*
* @param theEvent and ActionEvent
*/
public void actionPerformed (ActionEvent theEvent)
{
frame.setVisible(false);
frame.dispose();
GUI.changeStudentsID();
GUI.main();
}
});
c.gridx = 2;
c.gridy = 1;
pane.add(enterGrades, c);
enterGrades.addActionListener (new ActionListener()
{
/**
* respond to a button press.
*
* @param theEvent and ActionEvent
*/
public void actionPerformed (ActionEvent theEvent)
{
frame.setVisible(false);
frame.dispose();
GUI.changeGrades(frame.getContentPane());
GUI.main();
}
});
c.gridx = 3;
c.gridy = 1;
pane.add(printReport, c);
printReport.addActionListener (new ActionListener()
{
/**
* respond to a button press.
*
* @param theEvent and ActionEvent
*/
public void actionPerformed (ActionEvent theEvent)
{
System.out.println("This is a placeholder:");
System.out.println("The student is named " + student.getLastName() + ", " + student.getFirstName() + ".");
System.out.println("The student has the ID# of " + student.getID());
System.out.println("The student has gotten " + student.findGPA() + "% in the class");
}
});
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
/**
* changeStudentsName starts the window for changing the student's name.
*/
public static void changeStudentsName ()
{
String name = JOptionPane.showInputDialog (null, "Please enter the student's name as 'Last Name, First Name'.");
try
{
name.indexOf(", ");
}
catch (Exception e)
{
name = JOptionPane.showInputDialog (null, "That is not a valid name, please enter the student's name as 'Last Name, First Name' again.");
}
int i = name.indexOf(", ");
student.setLastName(name.substring(0, i));
while (name.substring(i, i + 1).equals(",") || name.substring(i, i + 1).equals(" "))
{
i++;
}
student.setFirstName(name.substring(i));
JOptionPane.showConfirmDialog(null, "The student's name is now " + student.getFirstName() +
" " + student.getLastName() + ". Is this correct?");
}
/**
* changeStudentID starts the window for changing the student's ID.
*/
public static void changeStudentsID ()
{
String ID = JOptionPane.showInputDialog (null, "Please enter the student's ID#.");
while (ID.length() != 8)
{
ID = JOptionPane.showInputDialog (null, "That is not a valid ID#, please enter the ID# again.");
}
try
{
Integer.parseInt(ID);
}
catch (Exception e)
{
ID = JOptionPane.showInputDialog (null, "That is not a valid ID#, please enter the ID# again.");
}
student.setID(ID);
JOptionPane.showConfirmDialog(null, "The student's ID is now " + student.getID() + ". Is this correct?");
}
/**
* changeGrades starts the window for changing the student's grades.
*/
public static void changeGrades (Container pane)
{
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JLabel greeting = new JLabel ("Would you like to enter all the grades at once, or just a specific assignment?");
JButton allGrades = new JButton ("Enter all the grades at once");
JButton oneGrade = new JButton ("Just enter a specific assignment");
c.gridwidth = 2;
c.gridx = 0;
c.gridy = 0;
pane.add(greeting, c);
c.fill = GridBagConstraints.BOTH;
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 1;
pane.add(allGrades, c);
allGrades.addActionListener (new ActionListener()
{
/**
* respond to a button press.
*
* @param theEvent and ActionEvent
*/
public void actionPerformed (ActionEvent theEvent)
{
System.exit(0);
}
});
c.gridx = 1;
c.gridy = 1;
pane.add(oneGrade, c);
oneGrade.addActionListener (new ActionListener()
{
/**
* respond to a button press.
*
* @param theEvent and ActionEvent
*/
public void actionPerformed (ActionEvent theEvent)
{
frame.setVisible(false);
frame.dispose();
GUI.setOneGrade();
GUI.main();
}
});
}
/**
* setOneGrade asks the user to select what grade they want to set, and then what it should be set as.
*/
public static void setOneGrade ()
{
}
}
This post has been edited by noctolater: 09 November 2009 - 09:23 PM

New Topic/Question
Reply




MultiQuote




|