person class
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class Person extends JFrame{
Scanner scanner = new Scanner(System.in);
private
int iChoice;
void SetChoiceConv( ) {
String Choice = scanner.next();
iChoice = Integer.parseInt(Choice);
}
int GetChoice( int iiChoice ) {
iiChoice = iChoice;
switch(iiChoice) {
case 1:
int tempYears = 0;
Instructor oInstructor;
oInstructor = new Instructor();
oInstructor.setInstructorInformation();
oInstructor.GetInstructorInformation(tempYears);
break;
case 2:
int tempSYears = 0;
Student oStudent;
oStudent = new Student();
oStudent.setStudentInformation();
oStudent.GetStudentInformation(tempSYears);
break;
case 3:
System.out.print("Goodbye");
break;
}
return 0;
}
public static void main(String[] args) {
Layout frame = new Layout();
frame.setTitle("Information");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(360, 360);
frame.setVisible(true);
int iiChoice = 0;
//Person oPerson;
//oPerson = new Person();
// JFrame frame = new JFrame("Please select from one of the following:");
/*JButton jbtI = new JButton("Instructor");
frame.add(jbtI);
frame.setSize(200,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
JButton jbtS = new JButton("Student");
frame.add(jbtS);
frame.setSize(200,200);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setLocationRelativeTo(jbtI);
frame.setVisible(true);
System.out.print("Please select from one of the following:\n");
System.out.print("\t 1. Instructor \n\n \t 2. Student \n\n \t 3. Exit");
oPerson.SetChoiceConv();
oPerson.GetChoice(iiChoice);
*/
}
}
my student class:
public class Student extends Person{
private
int syears;
void setStudentInformation () {
System.out.print("You have chosen a student\n\n");
System.out.print("How long have you been a student?\n\n");
String StudentYears = scanner.next();
syears = Integer.parseInt(StudentYears);
System.out.print("So you've been an Student for " + syears + " years...");
}
int GetStudentInformation ( int tempSYears ) {
tempSYears = syears;
return syears;
}
}
my instructor class:
public class Instructor extends Person{
private
int iyears;
void setInstructorInformation () {
System.out.print("You have chosen an instructor\n\n");
System.out.print("How long have you been an instructor?\n\n");
String InstructorYears = scanner.next();
iyears = Integer.parseInt(InstructorYears);
System.out.print("So you've been an instructor for " + iyears + " years...");
}
int GetInstructorInformation ( int tempYears ) {
tempYears = iyears;
return iyears;
}
}
my layout class:
import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.event.*;
public class Layout extends JFrame {
public Layout () {
setLayout( new FlowLayout( FlowLayout.LEFT, 10, 20));
add( new JLabel("Please enter the correct information: "));
add( new JLabel("First Name"));
add( new JTextField(8));
add( new JLabel("Last Name"));
add( new JTextField(8));
add( new JCheckBox("Instructor"));
add( new JCheckBox("Student"));
JButton jbtOK = new JButton("OK");
add (jbtOK);
JButton jbtEXIT = new JButton("Exit");
add (jbtEXIT);
jbtOK.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e) {
System.out.println("You have pressed the OK button");
}
});
jbtEXIT.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e) {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
});
}
}
ok, so my questions are this:
1. can someone look over my code and give me advice on how to make it simpler?
2. I'm having trouble with my action listener. My exit button when I click it it recognizes that I have clicked it, but it does not exit the application
3. my OK button I want to bring up the set and get functions of the instructor and student respectively based on whichever checkbox they may have selected.
keep in mind that this has all been written in netbeans 6.1

Start a new topic
Add Reply






MultiQuote


| 


