Results 1 to 5 of 5
  1. #1
    ara
    ara is offline Member
    Join Date
    Jan 2009
    Posts
    8
    Rep Power
    0

    Default [SOLVED] need help..pls.. How to show a new frame?

    ok here's what i want to go When i click on the 'member's corner' button from homePage.java, i would like the wlcmMember.java to be shown.
    Below are the codes:
    ************
    homePage.java
    ************
    Java Code:
    package IT1290;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import TourPlan_User.Tourplan_Mainmenu;
    import Admini.LoginForm;
    import Admini.MainMenu;
    public class homePage extends JFrame {
    
    	private JPanel jContentPane = null;
    	private homePage myFrame = null;
    	private JLabel jLabel_banner = null;
    	private JButton jButton_createMember = null;
    	private JPanel jPanel_1 = null;
    	private JLabel jLabel_farmsInSpore = null;
    	private JLabel jLabel_yes = null;
    	private JButton jButton_farms = null;
    	private JPanel jPanel_2 = null;
    	private JLabel jLabel_getaway = null;
    	private JLabel jLabel_cantPlan = null;
    	private JLabel jLabel_help = null;
    	private JButton jButton_tourPlan = null;
    	private JButton jButton_adminLogin = null;
    	private JButton jButton_memberLogin = null;
    	private JPanel jPanel_memberPanel = null;
    	private JLabel jLabel_beMember = null;
    	private JLabel jLabel_receiveNews = null;
    	private JButton jButton_testimonial = null;
    	private JButton jButton_memberCorner = null;
    	/**
    	 * This method initializes jButtonW1	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButton_createMember() {
    		if (jButton_createMember == null) {
    			jButton_createMember = new JButton();
    			jButton_createMember.setText("Sign up!");
    			jButton_createMember.setBounds(new java.awt.Rectangle(27,93,146,25));
    			jButton_createMember.addActionListener(new java.awt.event.ActionListener() {
    				public void actionPerformed(java.awt.event.ActionEvent e) {
    					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
    					JPanel panel = new createMember(myFrame);
    					/*
    					 * MainMenu mm = new MainMenu();
    				mm.getJFrame().setVisible(true);
    					 */
    					Membership mem = new Membership();
    					mem.getJFrame().setVisible(true);
    				//	myFrame.getContentPane().removeAll();
    				//	myFrame.getContentPane().add(panel);
    				//	myFrame.getContentPane().add(jButton_createMember);
    				//	myFrame.getContentPane().validate();
    				//	myFrame.getContentPane().repaint();
    				}
    			});
    		}
    		return jButton_createMember;
    	}
    
    	/**
    	 * This method initializes jPanel_1	
    	 * 	
    	 * @return javax.swing.JPanel	
    	 */
    	private JPanel getJPanel_1() {
    		if (jPanel_1 == null) {
    			jLabel_yes = new JLabel();
    			jLabel_yes.setText("Yes There are!");
    			jLabel_yes.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 18));
    			jLabel_yes.setBounds(new java.awt.Rectangle(35,74,150,25));
    			jLabel_farmsInSpore = new JLabel();
    			jLabel_farmsInSpore.setText("There are Farms in Singapore??");
    			jLabel_farmsInSpore.setBounds(new java.awt.Rectangle(23,17,182,16));
    			jPanel_1 = new JPanel();
    			jPanel_1.setBounds(new java.awt.Rectangle(228,204,235,181));
    			jPanel_1.add(jLabel_farmsInSpore, null);
    			jPanel_1.add(jLabel_yes, null);
    			jPanel_1.setLayout(null);
    			jPanel_1.setBackground(java.awt.Color.white);
    			jPanel_1.add(getJButton_farms(), null);
    		}
    		return jPanel_1;
    	}
    
    	/**
    	 * This method initializes jButton_btn	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButton_farms() {
    		if (jButton_farms == null) {
    			jButton_farms = new JButton();
    			jButton_farms.setBounds(new java.awt.Rectangle(18,141,202,27));
    			jButton_farms.setText("Click here to check them out!");
    		}
    		return jButton_farms;
    	}
    
    	/**
    	 * This method initializes jPanel_2	
    	 * 	
    	 * @return javax.swing.JPanel	
    	 */
    	private JPanel getJPanel_2() {
    		if (jPanel_2 == null) {
    			jLabel_help = new JLabel();
    			jLabel_help.setBounds(new java.awt.Rectangle(48,82,155,31));
    			jLabel_help.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 18));
    			jLabel_help.setText("Let us help You!");
    			jLabel_cantPlan = new JLabel();
    			jLabel_cantPlan.setBounds(new java.awt.Rectangle(64,48,102,16));
    			jLabel_cantPlan.setText("Cant plan a trip?");
    			jLabel_getaway = new JLabel();
    			jLabel_getaway.setBounds(new java.awt.Rectangle(43,14,155,16));
    			jLabel_getaway.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 12));
    			jLabel_getaway.setText("Need a peaceful getaway?");
    			jPanel_2 = new JPanel();
    			jPanel_2.setBounds(new java.awt.Rectangle(467,203,233,180));
    			jPanel_2.setLayout(null);
    			jPanel_2.setBackground(java.awt.Color.white);
    			jPanel_2.add(jLabel_getaway, null);
    			jPanel_2.add(jLabel_cantPlan, null);
    			jPanel_2.add(jLabel_help, null);
    			jPanel_2.add(getJButton_tourPlan(), null);
    		}
    		return jPanel_2;
    	}
    
    	/**
    	 * This method initializes jButton_tourPlan	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButton_tourPlan() {
    		if (jButton_tourPlan == null) {
    			jButton_tourPlan = new JButton();
    			jButton_tourPlan.setBounds(new java.awt.Rectangle(34,137,187,23));
    			jButton_tourPlan.setText("Click here for a Tour Plan");
    		}
    		return jButton_tourPlan;
    	}
    
    	/**
    	 * This method initializes jButton_adminLogin	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButton_adminLogin() {
    		if (jButton_adminLogin == null) {
    			jButton_adminLogin = new JButton();
    			jButton_adminLogin.setBounds(new java.awt.Rectangle(595,480,125,21));
    			jButton_adminLogin.setText("Admin Login");
    			jButton_adminLogin.addActionListener(new java.awt.event.ActionListener() {
    				public void actionPerformed(java.awt.event.ActionEvent e) {
    					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
    					LoginForm lf = new LoginForm();
    					lf.getJFrame().setVisible(true);
    				}
    			});
    		}
    		return jButton_adminLogin;
    	}
    
    	/**
    	 * This method initializes jButton_memberLogin	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButton_memberLogin() {
    		if (jButton_memberLogin == null) {
    			jButton_memberLogin = new JButton();
    			jButton_memberLogin.setBounds(new java.awt.Rectangle(597,506,122,18));
    			jButton_memberLogin.setText("Member Login");
    		}
    		return jButton_memberLogin;
    	}
    
    	/**
    	 * This method initializes jPanel_memberPanel	
    	 * 	
    	 * @return javax.swing.JPanel	
    	 */
    	private JPanel getJPanel_memberPanel() {
    		if (jPanel_memberPanel == null) {
    			jLabel_receiveNews = new JLabel();
    			jLabel_receiveNews.setBounds(new java.awt.Rectangle(8,62,191,25));
    			jLabel_receiveNews.setText("And Recieve latest updates on Rural Singapore");
    			jLabel_beMember = new JLabel();
    			jLabel_beMember.setBounds(new java.awt.Rectangle(39,14,154,16));
    			jLabel_beMember.setText("Come! Be our Member");
    			jPanel_memberPanel = new JPanel();
    			jPanel_memberPanel.setBounds(new java.awt.Rectangle(5,204,210,184));
    			jPanel_memberPanel.setLayout(null);
    			jPanel_memberPanel.setBackground(java.awt.Color.white);
    			jPanel_memberPanel.add(jLabel_beMember, null);
    			jPanel_memberPanel.add(jLabel_receiveNews, null);
    			jPanel_memberPanel.add(getJButton_createMember(), null);
    			jPanel_memberPanel.add(getJButton_memberCorner(), null);
    		}
    		return jPanel_memberPanel;
    	}
    
    	/**
    	 * This method initializes jButton_testimonial	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButton_testimonial() {
    		if (jButton_testimonial == null) {
    			jButton_testimonial = new JButton();
    			jButton_testimonial.setBounds(new java.awt.Rectangle(47,408,120,19));
    			jButton_testimonial.setText("Testimonial");
    			jButton_testimonial.addActionListener(new java.awt.event.ActionListener() {
    				public void actionPerformed(java.awt.event.ActionEvent e) {
    					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
    				
    				}
    			});
    		}
    		return jButton_testimonial;
    	}
    
    	/**
    	 * This method initializes jButton_memberCorner	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButton_memberCorner() {
    		if (jButton_memberCorner == null) {
    			jButton_memberCorner = new JButton();
    			jButton_memberCorner.setBounds(new java.awt.Rectangle(25,129,150,27));
    			jButton_memberCorner.setText("Member's Corner");
    			jButton_memberCorner.addActionListener(new java.awt.event.ActionListener() {
    				public void actionPerformed(java.awt.event.ActionEvent e) {
    					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
    				wlcmMember welMem = new wlcmMember();
    				welMem.initialize().setVisible(true); //smt wrong here right??....
    				}
    			});
    		}
    		return jButton_memberCorner;
    	}
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		new homePage();
    	}
    
    	/**
    	 * This is the default constructor
    	 */
    	public homePage() {
    		super();
    		//must remember to set myFrame to this!!
    		myFrame = this;
    		initialize();
    	}
    
    	/**
    	 * This method initializes this
    	 * 
    	 * @return void
    	 */
    	private void initialize() {
    		this.setSize(866, 655);
    		//this.setContentPane(getJContentPane());
    		//this.setContentPane(getJContentPane());
    		//this.setContentPane(getJButtonW1());
    		this.setContentPane(getJContentPane());
    		this.setTitle("HomePage");
    		this.setSize(new java.awt.Dimension(714,256));
    		this.setVisible(true);
    	}
    
    	/**
    	 * This method initializes jContentPane
    	 * 
    	 * @return javax.swing.JPanel
    	 */
    	private JPanel getJContentPane() {
    		if (jContentPane == null) {
    			jLabel_banner = new JLabel();
    			jLabel_banner.setBounds(new java.awt.Rectangle(51,-1,699,204));
    			jLabel_banner.setText("Banner");
    			jLabel_banner.setIcon(new ImageIcon("C:/Documents and Settings/User/My Documents/NYP/IT1290_2008/Project/logo_final.jpg"));
    			jContentPane = new JPanel();
    			jContentPane.setLayout(null);
    			jContentPane.setBackground(java.awt.Color.white);
    			jContentPane.add(jLabel_banner, null);
    			jContentPane.add(getJPanel_1(), null);
    			jContentPane.add(getJPanel_2(), null);
    			jContentPane.add(getJButton_adminLogin(), null);
    			jContentPane.add(getJButton_memberLogin(), null);
    			jContentPane.add(getJPanel_memberPanel(), null);
    			jContentPane.add(getJButton_testimonial(), null);
    		}
    		return jContentPane;
    	}
    
    }  //  @jve:decl-index=0:visual-constraint="16,5"
    ***************
    wlcmMember.java
    ***************
    Java Code:
    package IT1290;
    
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JButton;
    
    
    
    public class wlcmMember extends JFrame{
    	private JPanel jContentPane = null;
    	private wlcmMember myWlcmMemberFrame = null;
    	private JLabel jLabel_welcome = null;
    	private JButton jButton_viewMember = null;
    	private JButton jButton_updateMember = null;
    	private JButton jButton_deleteMember = null;
    	
    	/**
    	 * This method initializes jButton_viewMember	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButton_viewMember() {
    		if (jButton_viewMember == null) {
    			jButton_viewMember = new JButton();
    			jButton_viewMember.setText("View Particulars");
    			jButton_viewMember.setBounds(new java.awt.Rectangle(93,301,151,26));
    			jButton_viewMember.addActionListener(new java.awt.event.ActionListener() {
    				public void actionPerformed(java.awt.event.ActionEvent e) {
    					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
    					JPanel panel = new viewMember(myWlcmMemberFrame);
    					myWlcmMemberFrame.getContentPane().removeAll();
    					myWlcmMemberFrame.getContentPane().add(panel);
    					myWlcmMemberFrame.getContentPane().add(jButton_updateMember);
    					myWlcmMemberFrame.getContentPane().add(jButton_deleteMember);
    					myWlcmMemberFrame.getContentPane().validate();
    					myWlcmMemberFrame.getContentPane().repaint();
    				}
    			});
    		}
    		return jButton_viewMember;
    	}
    
    	/**
    	 * This method initializes jButton_updateMember	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButton_updateMember() {
    		if (jButton_updateMember == null) {
    			jButton_updateMember = new JButton();
    			jButton_updateMember.setBounds(new java.awt.Rectangle(257,302,151,26));
    			jButton_updateMember.setText("Update Particulars");
    			jButton_updateMember.addActionListener(new java.awt.event.ActionListener() {
    				public void actionPerformed(java.awt.event.ActionEvent e) {
    					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
    					JPanel panel = new updateMember(myWlcmMemberFrame);
    					myWlcmMemberFrame.getContentPane().removeAll();
    					myWlcmMemberFrame.getContentPane().add(panel);
    					myWlcmMemberFrame.getContentPane().add(jButton_viewMember);
    					myWlcmMemberFrame.getContentPane().add(jButton_deleteMember);
    					myWlcmMemberFrame.getContentPane().validate();
    					myWlcmMemberFrame.getContentPane().repaint();
    				}
    			});
    		}
    		return jButton_updateMember;
    	}
    
    	/**
    	 * This method initializes jButton_deleteMember	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButton_deleteMember() {
    		if (jButton_deleteMember == null) {
    			jButton_deleteMember = new JButton();
    			jButton_deleteMember.setBounds(new java.awt.Rectangle(421,302,151,26));
    			jButton_deleteMember.setText("Cancel Membership");
    			jButton_deleteMember.addActionListener(new java.awt.event.ActionListener() {
    				public void actionPerformed(java.awt.event.ActionEvent e) {
    					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
    					JPanel panel = new deleteMember(myWlcmMemberFrame);
    					myWlcmMemberFrame.getContentPane().removeAll();
    					myWlcmMemberFrame.getContentPane().add(panel);
    					myWlcmMemberFrame.getContentPane().add(jButton_viewMember);
    					myWlcmMemberFrame.getContentPane().add(jButton_updateMember);
    					myWlcmMemberFrame.getContentPane().validate();
    					myWlcmMemberFrame.getContentPane().repaint();
    				}
    			});
    		}
    		return jButton_deleteMember;
    	}
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		new wlcmMember();
    	}
    	
    	public wlcmMember() {
    		super();
    		//must remember to set myFrame to this!!
    		myWlcmMemberFrame = this;
    		initialize();
    	}
    	
    	private void initialize() {
    		this.setSize(701, 387);
    		//this.setContentPane(getJContentPane());
    		//this.setContentPane(getJContentPane());
    		//this.setContentPane(getJButtonW1());
    		this.setContentPane(getJContentPane());
    		this.setTitle("JFrame");
    		this.setVisible(true);
    		this.setLayout(null);
    	}
    
    	/**
    	 * This method initializes jContentPane
    	 * 
    	 * @return javax.swing.JPanel
    	 */
    	private JPanel getJContentPane() {
    		if (jContentPane == null) {
    			jLabel_welcome = new JLabel();
    			jLabel_welcome.setBounds(new java.awt.Rectangle(219,14,179,17));
    			jLabel_welcome.setText("Welcome to Members' corner");
    			jContentPane = new JPanel();
    			jContentPane.setLayout(null);
    			jContentPane.add(jLabel_welcome, null);
    			jContentPane.add(getJButton_updateMember(), null);
    			jContentPane.add(getJButton_deleteMember(), null);
    			jContentPane.add(getJButton_viewMember(), null);
    		}
    		return jContentPane;
    	}
    }  //  @jve:decl-index=0:visual-constraint="10,10"
    Thanks a lot for ur time in helping me... =)

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    change: welMem.initialize().setVisible(true); //smt wrong here right??....

    to: welMem.setVisible(true); //smt wrong here right??....

    then what happens?
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    This is a general suggestion. Typically, a Swing application needs just one JFrame. JFrame is the Window frame in which the application is displayed.

    You can create multiple JPanel's, one for each "screen" you want to display. Simply add each JPanel to the JFrame and control which one is displaying setVisible(), or add and remove them from the JFrame.

  4. #4
    ara
    ara is offline Member
    Join Date
    Jan 2009
    Posts
    8
    Rep Power
    0

    Default

    yes yes.... it works... =)
    thanks alot... again!... =)

  5. #5
    ara
    ara is offline Member
    Join Date
    Jan 2009
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Replies: 6
    Last Post: 04-07-2008, 04:57 AM
  2. How to Show Calendar
    By praveen.kb in forum AWT / Swing
    Replies: 2
    Last Post: 02-09-2008, 09:23 AM
  3. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 07:20 AM
  4. show a RTF FORMAT
    By Jack in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 04:37 AM

Posting Permissions

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