2014-05-06 73 views
0

我最近正在編寫一個關於預訂座位的代碼。在它的guI部分,我需要創建多個窗口。我的意思是窗口應根據用戶的選擇而改變。例如 ; 在其中一個窗口中 1)如果用戶單擊以保留座位按鈕,他將進入名稱登記頁面2)如果用戶單擊關於我們按鈕,他將轉到提供有關開發人員信息的頁面。GUI多窗口

所以在最後頁面會創建複雜的交互mape。

但是我甚至不能創建第一個transition.I已經嘗試過內部幀!

你能給我一個關於它的例子或想法嗎?

這裏是我的主頁

public Main_GUI() { 

     getContentPane().setLayout(null); 

     panel0 =new JPanel(); 
     panel0.setBackground(Color.BLUE); 
     panel0.setBounds(22, 11, 407, 278); 
     panel0.setLayout(null); 
     p1=new About_Us(); 
     p2=new Username(); 
     pnew=new JPanel(); 


     JLabel lblLibraryBooking = new JLabel("LIBRARY BOOKING"); 
     lblLibraryBooking.setForeground(Color.YELLOW); 
     lblLibraryBooking.setFont(new Font("Tahoma", Font.BOLD, 30)); 
     lblLibraryBooking.setBounds(61, 11, 295, 50); 
     panel0.add(lblLibraryBooking); 

     JButton btnNewButton = new JButton("RESERVE A SEAT NOW!"); 
     btnNewButton.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent e) { 

       panel0.setVisible(false); 

       pnew=p2.getPanel(); 
       pnew.setVisible(true); 
       repaint(); 

      } 
     }); 
     btnNewButton.setBounds(93, 80, 198, 50); 
     panel0.add(btnNewButton); 

     JButton btnAboutUs = new JButton("ABOUT US"); 
     btnAboutUs.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent e) { 
       panel0.setVisible(false); 
       p1.getPanel().setVisible(true); 



      } 
     }); 
     btnAboutUs.setBounds(93, 214, 198, 23); 
     panel0.add(btnAboutUs); 


     uri=null; 
     try { 
      uri = new URI("http://library.bilkent.edu.tr/"); 
     } catch (URISyntaxException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 



     JButton btnNewButton_1 = new JButton("Go To Bilkent Library Webpage !"); 
     btnNewButton_1.setBounds(93, 156, 198, 31); 
     btnNewButton_1.setHorizontalAlignment(SwingConstants.LEFT); 
     btnNewButton_1.setBorderPainted(false); 
     btnNewButton_1.setOpaque(false); 
     btnNewButton_1.setBackground(Color.WHITE); 
     btnNewButton_1.setToolTipText(uri.toString()); 
     btnNewButton_1.addActionListener(new theListener()); 

     panel0.add(btnNewButton_1); 



    } 

    public static void open(URI uri) { 
     if (Desktop.isDesktopSupported()) { 
      try { 
      Desktop.getDesktop().browse(uri); 
      } catch (IOException e){ 
        e.printStackTrace(); 
      } 
     } 
     } 

    private class theListener implements ActionListener 
    { 

      public void actionPerformed(ActionEvent e) { 


       open(uri); 

      } 

    } 
    public JPanel getPanel(){ 
     return panel0; 
    } 






} 

這是我的公司簡介代碼

public About_Us() { 
    getContentPane().setLayout(null); 

    panel1 = new JPanel(); 
    panel1.setVisible(false); 
    panel1.setBackground(Color.RED); 
    panel1.setBounds(10, 11, 430, 278); 
    panel1.setLayout(null); 

    JLabel lblAboutUs = new JLabel("ABOUT US"); 
    lblAboutUs.setForeground(Color.GREEN); 
    lblAboutUs.setFont(new Font("Tahoma", Font.BOLD, 33)); 
    lblAboutUs.setBounds(136, 11, 176, 33); 
    panel1.add(lblAboutUs); 

    JTextPane txtpnWeAre = new JTextPane(); 
    txtpnWeAre.setFont(new Font("Tahoma", Font.ITALIC, 14)); 
    txtpnWeAre.setBackground(Color.CYAN); 
    txtpnWeAre.setText("Our group's name is Process Completed. \r\nOur members are:\r\n-P\u0131nar G\u00F6ktepe\r\n-\u0130rem Herg\u00FCner\r\n-Berire G\u00FCnd\u00FCz\r\n-Mavi Nunn Polato\u011Flu\r\n-Fatih Alperen \u015Eahin\r\n-Vedat Mert \u015Een"); 
    txtpnWeAre.setBounds(10, 77, 410, 160); 
    panel1.add(txtpnWeAre); 

    JButton btnBack = new JButton("BACK"); 
    btnBack.setBounds(189, 244, 89, 23); 
    btnBack.addActionListener(new ActionListener() { 
     public void actionPerformed(ActionEvent e) { 
      panel1.removeAll(); 
      Main_GUI Trns1=new Main_GUI(); 
      Trns1.getPanel().setVisible(true); 
      repaint(); 
     } 
    }); 
    panel1.add(btnBack); 

} 

public JPanel getPanel(){ 
    return panel1; 
} 

}

這裏是我工作的代碼,結合了

public class WORK extends JApplet { 

public static void main(String [] args) { 
    JFrame frame=new JFrame(); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

    Main_GUI m1=new Main_GUI(); 
    frame.add(m1.getPanel()); 
    frame.pack(); 
    frame.setVisible(true); 




} 

    } 
+0

發佈代碼.. –

+0

您需要使用面板。 'CardLayout'允許您在不同的面板之間切換。你應該檢查一下 –

回答

2

這聽起來就像一份工作CardLayout manager

實際上,CardLayout允許您在更高級別的容器(例如另一個容器中的JPanel)之間進行切換,以便您的主視圖可以是主菜單,或者是用戶選擇的主視圖,如果需要則返回主菜單。