user3609649
user3609649

Reputation: 3

GUI multiple windows

I am recently writing a code about reserving seats. In its guı part I need to create multiple windows.I mean windows should change according o user's choices. For example ; in one of the windows 1)if user clicks to Reserve a Seat button he will go to the name enterance page 2)if user clicks to About us button he will go to the page that gives info about developers.

so at the end pages will create complex interraction mape.

however I couldnt even create first transition.I have already tried ınternal frames!

Could you give me an example or idea about it?

here is my homepage

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






}

Here is my AboutUs code

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

}

AND here is my Work code that combines both

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




 }

    }

Upvotes: 0

Views: 69

Answers (1)

garbageboy
garbageboy

Reputation: 36

This sounds like a job for the CardLayout manager.

Essentially the CardLayout lets you change between higher level containers like a JPanel in another container, so that your main view could be a main menu, or something specific if the user selects that, and back to the main menu if needed.

Upvotes: 2

Related Questions