0

ご覧のとおり、パネルをフレームに追加するのに問題があります...簡単なことかもしれません...しかし、私には見えません...もし皆さんが私を正しい方向に向けることができれば:)

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);
    }
}
4

1 に答える 1

2

静的コンテキストから非静的クラスを作成しようとしています。

内部パネルを静的にしてみてください...

public static class StudentPanel extends JPanel {

これが単なるテストでない限り、あなたのクラスをこのように混在させることは避けたいと思います。StudentInfoinfo クラスに値を追加していません

于 2013-05-01T04:40:54.237 に答える