正如你们所看到的,我在将面板添加到框架中时遇到了麻烦……我知道这可能很容易……但我看不到……如果你们能指出我正确的方向:)
import java.util.List;
import javax.swing.*;
/**
*
* @author Doohickey
*/
public class StudentInfo {
/**
* @param args the command line arguments
*/
private String firstName, lastName;
private String birthday, studentID;
private String pictureFileLocation;
private char gender;
private List<String> enrolledPapers;
public StudentInfo(String studentID){
this.studentID = studentID;
}
public StudentInfo(String studentID, String firstName, String lastName,
String birthday, char gender){
this.studentID = studentID;
this.firstName = firstName;
this.lastName = lastName;
this.birthday = birthday;
this.gender = gender;
}
public void addPaper(String paper){
enrolledPapers.add(paper);
}
public List<String> getEnrolledPapers(){
return enrolledPapers;
}
public void setPictureFromFileName(String fileName){
pictureFileLocation = fileName;
}
public String getPictureFileName(){
return pictureFileLocation;
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public String getBirthday(){
return birthday;
}
public String getStudentID(){
return studentID;
}
public char getGender(){
return gender;
}
public JComponent getStudentPanel(){
return null;
}
public class StudentPanel extends JPanel{
public StudentPanel(){
JTextField stFirstName = new JTextField("First name: "+firstName);
JTextField stLastName = new JTextField("Last name: "+ lastName);
JComboBox stBirth = new JComboBox();
JRadioButton stGender = new JRadioButton();
JPanel stPanel = new JPanel();
stPanel.add(stFirstName);
stPanel.add(stLastName);
stPanel.add(stBirth);
stPanel.add(stGender);
add(stPanel);
}
}
public static void main(String[] args) {
// TODO code application logic here
JFrame frame = new JFrame("Student info");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new StudentPanel());
frame.pack(); //pack frame
frame.setVisible(true);
}
}