Was sent here to get some of code reviewed. Having difficulties with the problem. Wanted to know if I was going in the right direction. Here is the problem:
Create a Java GUI program which has one button, one text box and one textfield. When a user click on the button, the system should pop up a file selection window, which allows the user to select a file from the hard disk. After the file is selected, e.g., “ssn.txt”, your program should read input file “ssn.txt”. Inside the file each line represents a social security number. The program first read all the ssns into the memory. If the format of a ssn is wrong in the file, your program should throw a SSNException object, and catch that Exception object, and display an error message for that line in text box. You are expected to create the SSNException class which inherits the Exception class. It should contain a wrongSSN string. The constructor of SSNException should accept a string parameter (the line that you read from ssn.txt) which initializes the wrongSSN variable. It should also displays an error message with the wrong ssn string After it has read all the ssns, it will display all the valid ssns in the text box, one line for one ssn.
Here is a what I have done so far:
public class SSN_GUI extends JPanel implements ActionListener{
public SSN_GUI(){
makeObject();
doTheLayout();
theButton.addActionListener(this);
}
private JTextField inputSSN;
private JButton theButton;
//Make all the Objects
private void makeObject(){
inputSSN = new JTextField(15);
inputSSN.setEditable(true);
theButton = new JButton();
}
//Layout all the Objects
private void doTheLayout(){
JPanel thePanel = new JPanel();
thePanel.setLayout(new BorderLayout());
thePanel.add(new JLabel("Enter Social Security Number: "));
thePanel.add(inputSSN, "Center");
thePanel.add(theButton, "North");
}
// Handle the button push
public void actionPerformed(ActionEvent evt){
}
}
public class SSNException extends Exception{
private String wrongSSN;
public SSNException(String data){
wrongSSN = data;
}
}
JPanel thePanel = new JPanel(new BorderLayout());
– Landei Nov 8 '11 at 13:42