Results 1 to 2 of 2
  1. #1
    Lehane_9 is offline Member
    Join Date
    Dec 2007
    Posts
    6
    Rep Power
    0

    Default Cannot understand whats wrong

    I dont know why my new panel called welcome will noy open can anybody please help.

    First JFrame is this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;

    public class Example_22_2 extends JFrame implements ActionListener
    {
    private JButton loginBtn, viewTimeTablesBtn,BuyTicketsBtn;
    JPanel cardHolder;
    CardLayout card;
    Container c;
    Example_22_2 panelmgr;





    public Example_22_2(Example_22_2 panelmgr)
    {
    super("Irish Rail Timetabling and Ticketing System ");
    cardHolder=new JPanel();
    card=new CardLayout();
    cardHolder.setLayout(card);

    c=getContentPane();

    welcome panel1 = new welcome(this);
    // adminLogIn panel2 = new adminLogIn(this);

    cardHolder.add(panel1, "panel1",1);
    //cardHolder.add(panel2,"panel2",1);


    loginBtn =new JButton("Login change timetables");
    viewTimeTablesBtn = new JButton("View Timetables");
    BuyTicketsBtn = new JButton ("Buy tickets");


    loginBtn.addActionListener(this);
    viewTimeTablesBtn.addActionListener(this);
    BuyTicketsBtn.addActionListener(this);


    c.add(loginBtn);
    c.add(viewTimeTablesBtn);
    c.add(BuyTicketsBtn);


    setSize (250, 200);
    show();
    }

    public static void main (String args[])
    {
    Example_22_2 example = new Example_22_2();
    }

    public void changePanel(String in)
    {
    card.show(cardHolder,in);
    }

    public void actionPerformed(ActionEvent e)
    {


    if(e.getSource()==viewTimeTablesBtn)
    {
    panelmgr.changePanel("panel1");


    }


    }
    }



    Then welcome.java is

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class welcome extends JPanel implements ActionListener


    {

    private JCheckBox cd1Cbx;
    private JButton resetBtn;

    private Container c;


    public welcome()
    {

    c.add(cd1Cbx);
    c.add(resetBtn);

    }
    public void actionPerformed(ActionEvent e)
    {




    }


    }

    I dont know why it wont work. any help greatly appreciated

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    
    public class E22_2 extends JFrame implements ActionListener
    {
        private JButton loginBtn, viewTimeTablesBtn, BuyTicketsBtn;
        JPanel cardHolder;
        CardLayout card; 
        Container c;
    
        public E22_2()
        {
            super("Irish Rail Timetabling and Ticketing System ");
            cardHolder=new JPanel();
            card=new CardLayout();
            cardHolder.setLayout(card);
    
            c=getContentPane();
    
            Welcome panel1 = new Welcome(this);
    //        adminLogIn panel2 = new adminLogIn(this);
    
            cardHolder.add("welcome", panel1);
    //        cardHolder.add("admin", panel2);
    
            loginBtn =new JButton("Login change timetables");
            viewTimeTablesBtn = new JButton("View Timetables");
            BuyTicketsBtn = new JButton ("Buy tickets");
    
            loginBtn.addActionListener(this);
            viewTimeTablesBtn.addActionListener(this);
            BuyTicketsBtn.addActionListener(this);
    
            System.out.println("JFrame default layout manager = " +
                                getLayout().getClass().getName());
            // no constraint -> default center section
            c.add(cardHolder);
            JPanel buttonPanel = new JPanel();
            buttonPanel.add(loginBtn);
            buttonPanel.add(viewTimeTablesBtn);
            buttonPanel.add(BuyTicketsBtn);
            c.add(buttonPanel, "South");
    
            setSize (450, 200);
            setVisible(true);
        }
    
        public static void main (String args[])
        {
            new E22_2();
        }
    
        public void changePanel(String in)
        {
            card.show(cardHolder, in);
        }
    
        public void actionPerformed(ActionEvent e)
        {
            if(e.getSource()==viewTimeTablesBtn)
            {
                changePanel("welcome"); 
            }
        }
    }
    
    class Welcome extends JPanel implements ActionListener
    {
        private JCheckBox cd1Cbx = new JCheckBox("checkBox");
        private JButton resetBtn = new JButton("reset");
    //    private Container c;
    
        public Welcome(E22_2 e)
        {
            add(cd1Cbx);
            add(resetBtn);
        }
    
        public void actionPerformed(ActionEvent e)
        {
        }
    }

Similar Threads

  1. Errors I don't understand
    By MattyB in forum New To Java
    Replies: 4
    Last Post: 04-01-2008, 11:55 PM
  2. New: Want to understand Drawing...
    By diRisig in forum New To Java
    Replies: 1
    Last Post: 02-05-2008, 08:13 AM
  3. i don understand this error
    By Deon in forum New To Java
    Replies: 4
    Last Post: 01-12-2008, 10:03 AM
  4. Whats wrong with my code???
    By Soda in forum New To Java
    Replies: 2
    Last Post: 12-06-2007, 12:54 PM
  5. whats the difference between Java core,J2EE......
    By prince24 in forum New To Java
    Replies: 2
    Last Post: 07-11-2007, 06:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •