Results 1 to 3 of 3
  1. #1
    Mokomi is offline Member
    Join Date
    May 2011
    Posts
    32
    Rep Power
    0

    Default getting a set Visible(true) turned false with an actionhandler.

    hello yall! working on a side project with a few friends and i'm getting the Main Menu working correctly. I can open a new JFrame but i cannot get the first menu to either close, or go invisible.
    First page
    Java Code:
    package inter;
    import java.awt.*;
    import javax.swing.*;
    class Main {
    	public static void main(String[]args){
    		boolean main =true;
    	
    		JFrame inter = new Inter();
    		inter.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		inter.setSize(300,300);
    		inter.setLocation(500, 250);
    		inter.setVisible(main);
    
    		
    	}
    	
    
    }
    E
    2ND Page
    Java Code:
    package inter;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Inter extends JFrame{
    	//was trying to get it to work :-P
    public boolean main = true;
    	public JButton create,play,pc,mob,skills,items;
    
    public Inter(){
    	super("RPAGE");
    	setLayout(new FlowLayout());
    	play = new JButton("Play");
    	create = new JButton("Create");
    	add(play);
    	add(create);
    	main=true;
    	
    	cre crea =new cre();
    	create.addActionListener(crea);
    }
    private class cre implements ActionListener{
    public void actionPerformed(ActionEvent create1){
    	JFrame imwithstupid = new JFrame("test");
    	imwithstupid.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	imwithstupid.setSize(300,300);
    	imwithstupid.setVisible(true);
    	mob=new JButton("Create a New Mob");
    	skills= new JButton("Create a New Skill");
    	items=new JButton("Create a New Item");
    	pc = new JButton("Create a New PlayerCharater!");
    	add(mob);
    	add(skills);
    	add(items);
    	add(pc);
    //does nothing
    	main=false;
    	
    }
    
    }
    }
    ]
    TY in advance ^__^

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You may want to look into the dispose method. So the original frames button click will create and setup a new window, then dispose of the original frame.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Where do you use the value of the main variable after you have changed its value?

Similar Threads

  1. while(true)
    By ravian in forum New To Java
    Replies: 7
    Last Post: 06-29-2011, 06:05 AM
  2. how to balance true and false instances per id ?
    By aneuryzma in forum New To Java
    Replies: 1
    Last Post: 03-27-2011, 02:35 PM
  3. Prime Number - true , false
    By pinkdreammsss in forum Java Applets
    Replies: 11
    Last Post: 05-04-2010, 02:49 PM
  4. true && !true
    By SirFalcon in forum New To Java
    Replies: 3
    Last Post: 10-29-2009, 02:33 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
  •