2013-04-20 4 views
0

데이터베이스 용 양식을 만들고 있는데 CardLayout을 사용하고 싶습니다. 나는 상황을 설명한다. 사용자는 두 가지 선택을 할 수있다 : 그는 자신의 accoun에 연결하거나 그가 새 것이거나 계정을 만들어야한다. 테스트 용 첫 번째 패널과 다른 패널 (사용자가 New 버튼을 클릭했을 때 변경 사항을 확인하기 위해 배경색을 Black으로 설정)이 있습니다. 주 프로그램을 시작할 때 제목 만있는 창과 다른 창은 없습니다. 또는 내가 원한 것이 아니며, 신청서의 첫 번째 단계는 양식을 표시하는 것입니다. 내 오류입니다 그래서 누군가가 나를 설명 할 수 있다면, 나는 그것을 가지고 :)CardLayout에 JPanel이 표시되지 않았습니다.

public class Accueil extends JFrame implements ActionListener { 

    private CardLayout l = new CardLayout(); 
    private JPanel main = new JPanel(l); 
    private JPanel change = new JPanel(); 
    private JPanel home = new JPanel(new BorderLayout()); 
    private JPanel title = new JPanel(); 
    private JPanel login = new JPanel(new BorderLayout()); 
    private JPanel login_title = new JPanel(); 
    private JPanel login_info = new JPanel(); 
    private JPanel copyright = new JPanel(); 
    private JLabel welcome = new JLabel("TEST"); 
    private JLabel connexion = new JLabel("Connexion"); 
    private JLabel mail = new JLabel("Mail : "); 
    private JTextField input_mail = new JTextField(); 
    private JLabel mdp = new JLabel("Password : "); 
    private JTextField input_mdp = new JTextField(); 
    private JLabel who = new JLabel ("Are you a : "); 
    private JRadioButton client = new JRadioButton("Client", true); 
    private JRadioButton developpeur = new JRadioButton("Developer", false); 
    private ButtonGroup bg = new ButtonGroup(); 
    private JButton ok = new JButton("Login"); 
    private JButton annule = new JButton("Cancel"); 
    private JButton inscription = new JButton("New ?"); 
    private JLabel align = new JLabel(""); 

    public Accueil() { 

     init_title(); 
     init_login(); 
     add_button(); 
     organize_frame(); 
     inscription.addActionListener(this); 
     main.add(home, "Home"); 
     main.add(change, "Change"); 
     l.show(main, "Home"); 
     change.setBackground(Color.black); 
     this.setTitle("test"); 
     this.setSize(600,600); 
     this.setLocationRelativeTo(null); 
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     this.setVisible(true); 
    } 

    public void actionPerformed(ActionEvent arg0) { 
     l.show(main, "Change"); 
    } 

    private void organize_frame() { 
     home.add(title, BorderLayout.NORTH); 
     home.add(login, BorderLayout.CENTER); 
     home.add(copyright, BorderLayout.SOUTH); 
    } 

    private void init_title() { 
     welcome.setFont(build_font(35)); 
     welcome.setBorder(new EmptyBorder(20,0,0,0)); 
     title.setPreferredSize(new Dimension(600,80)); 
     title.add(welcome); 
    } 

    private void init_login() { 
     setConnexion(); 
     user_input(); 
     align.setPreferredSize(new Dimension(215,50)); 
     organize_button(); 
     login.add(login_title, BorderLayout.NORTH); 
     login.add(login_info, BorderLayout.CENTER); 
    } 

    private void setConnexion() { 
     connexion.setFont(build_font(30)); 
     connexion.setBorder(new EmptyBorder(20,0,0,0)); 
     login_title.add(connexion); 
     login_title.setPreferredSize(new Dimension(600,100)); 
    } 

    private void user_input() { 
     who.setFont(build_font(25)); 
     mail.setFont(build_font(25)); 
     mail.setBorder(new EmptyBorder(0,120,0,0)); 
     mdp.setFont(build_font(25)); 
     input_mdp.setFont(build_font(25)); 
     input_mail.setFont(build_font(25)); 
     input_mail.setPreferredSize(new Dimension(300,40)); 
     input_mdp.setPreferredSize(new Dimension(300,40)); 
     who.setFont(build_font(20)); 
     client.setFont(build_font(20)); 
     developpeur.setFont(build_font(21)); 
     login_info.add(who); 
     login_info.add(client); 
     login_info.add(developpeur); 
     login_info.add(mail); 
     login_info.add(input_mail); 
     login_info.add(mdp); 
     login_info.add(input_mdp); 
     login_info.add(align); 
    } 

답변

3

어디 당신은 아무것도에, 메인 CardLayout-사용 인 JPanel을 추가하는 방법은 무엇입니까?

답변 : 그렇지 않습니다. 이를 작동 시키려면 결국 최상위 창으로 연결되는 구성 요소에 추가되어야합니다. 카드에 "카드"를 표시하려면 표시해야합니다.

+0

오오 다 ** **, 어리석은 오류 !! 도움을 주셔서 감사합니다 – afk

+0

@ user1086267 : 오신 것을 환영합니다. 이와 같은 문제가 발생하면 문제의 본질을 파악하기 위해 코드를 간소화하십시오. 이렇게하면 문제와 해결 방법을 한 눈에 볼 수 있습니다. 그렇지 않은 경우 컴파일되고 실행되는 간단한 작은 코드를 게시하고 문제를 해결하는 데 사용할 수 있습니다. –

관련 문제