你们可以看到我在将面板添加到框架中时遇到了麻烦...我知道这可能很容易......但是我看不到它......如果你们能指出我的话方向:)
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);
}
}
答案 0 :(得分:2)
您尝试从静态上下文创建非静态类。
尝试让你的内部面板静止......
public static class StudentPanel extends JPanel {
除非这只是一些测试,否则我会避免在课程中混合你的课程。您没有向StudentInfo
信息类