popup window

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 8499 Views - Last Post: 29 May 2010 - 09:52 AM Rate Topic: -----

#16 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: popup window

Posted 25 May 2010 - 06:29 PM

View Postgiuseppe105, on 24 May 2010 - 09:00 PM, said:

I give it the information. click ok. now i have the JFrame make calls to getters to collect the information. and then i have it make the main part of the app.

called after JDialog "OK" is clicked


Does not work that way. When the JDialog is active all the activies in the main frame are frozen.
It is the JDialog that will have to call setters in the JFrame to set the data

class MainFrame extends JFrame {

    int value1, value2;

    void setValue1(int n) {
        value1 = n;
    }
    void setValue2(int n) {
        value2 = n;
    }
...
    MyDialog x = new MyDialog(this, other params
    x.setVisible(true);
    .... you will be frozen here until MyDialog x collapses
...

    class MyDialog extends JDialog {

       MainFrame father;

       MyDialog(MainFrame mf, ....
        
           father = mf;

....
....
       mf.setValue1(val1);
       mf.setValue2(val2);

       this.dispose();          // will return just after setVisible(true) in MainFrame




Hope this makes it clearer
Was This Post Helpful? 0
  • +
  • -

#17 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: popup window

Posted 25 May 2010 - 07:34 PM

Still doesn't work.

here's my code. I'm gonna paste the 2 Classes were working with if you need more of the classes then tell me.

MainFrame
public class ProjectM extends JFrame
{	
	private String fileName;
	private int width;
	private int height;
	private String ImageLocation;
	private int tileSize;
	
	private ContextPane CP = new ContextPane(this);;
	private AppStarter AS;
	
	//Constructor
	public ProjectM()
	{
		//sets the layout manager
		this.setLayout(null);
	
		JMenuBar menuBar = new JMenuBar();
		
		this.setJMenuBar(menuBar);
		
		JMenu fileMenu = new JMenu("File");
		
		menuBar.add(fileMenu);
		
		JMenuItem newAction = new JMenuItem("New");
		
		fileMenu.add(newAction);
		
		newAction.addActionListener(new ActionListener() 
		{
            public void actionPerformed(ActionEvent e) 
            {
            	CP.setVisible(true);
            	ImageLocation = "C:\\Documents and Settings\\user\\My Documents\\Documents\\School\\Programming\\Java game project\\java map maker v0.2.0\\Images\\Tiles";
            	create_as();
            	
                System.out.println("What would you like to call your new map?");
            }
        });
	
		//Sets the size, title, close operation, and visibility of ProjectM JFrame
		this.setSize(937,532);
		this.setTitle("ProjectM");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setResizable(false);
		this.setVisible(true);
	}	
	
	public void Set_File_Name(String fn)
	{
		this.fileName = fn;
	}
	
	public void Set_Tile_Directory(String td)
	{
		this.ImageLocation = td;
	}
	
	public void Set_Tile_Size(int ts)
	{
		this.tileSize = ts;
	}
	
	public void Set_Height(int h)
	{
		this.height = h;
	}
	
	public void Set_Width(int w)
	{
		this.width = w;
	}
	
	public void create_as()
	{
		AS = new AppStarter(this.fileName, this.width, this.height, this.ImageLocation, this.tileSize);
		AS.setBounds(0,0,930,961);
		this.add(AS);
	}
	
	//Main Method 	
	public static void main(String[]args)
	{
		//Creates ProjectM JFrame
		new ProjectM();
	}
}


popup window
public class ContextPane extends JDialog
{
	private String fileName;
	private String tileDirectory;
	private int tileSize;
	private int height;
	private int width;
	
	private JTextField file_name;
	private JTextField width_Text;
	private JTextField height_Text;
	private JTextField tile_size;
	private JTextField tile_directory;
	
	private ProjectM pm;
	
	public ContextPane(ProjectM prm)
	{
		pm = prm;
		//sets the layout manager
		this.setLayout(null);
		this.setModal(true);
		
		file_name = new JTextField();
		file_name.setBounds(10,31,200,23);
		this.add(file_name);
		
		width_Text = new JTextField("20");
		width_Text.setBounds(10,78,60,23);
		this.add(width_Text);
		
		height_Text = new JTextField("15");
		height_Text.setBounds(90,78,60,23);
		this.add(height_Text);
		
		tile_size = new JTextField("32");
		tile_size.setBounds(10,122,60,23);
		this.add(tile_size);
		
		tile_directory = new JTextField();
		tile_directory.setBounds(10,167,200,23);
		this.add(tile_directory);
		
		JLabel file_name_Label = new JLabel("Filename");
		file_name_Label.setBounds(10,10,60,20);
		this.add(file_name_Label);
		
		JLabel width_Label = new JLabel("Width(X)");
		width_Label.setBounds(10,55,60,20);
		this.add(width_Label);
		
		JLabel height_Label = new JLabel("Height(Y)");
		height_Label.setBounds(90,55,60,20);
		this.add(height_Label);
		
		JLabel tile_size_label = new JLabel("Tile Size");
		tile_size_label.setBounds(10,101,60,20);
		this.add(tile_size_label);
		
		JLabel tile_directory_Label = new JLabel("Tile Image Directory");
		tile_directory_Label.setBounds(10,146,200,20);
		this.add(tile_directory_Label);
		
		JButton Browse = new JButton("Browse");
		Browse.setBounds(210,167,80,22);
		this.add(Browse);
		
		JButton OK = new JButton("Ok");
		OK.setBounds(50,201,80,22);
		
		OK.addActionListener(new ActionListener() 
		{
            public void actionPerformed(ActionEvent e) 
            {
            	pm.Set_File_Name(file_name.getText());
            	pm.Set_Tile_Size(Integer.parseInt(tile_size.getText()));
            	pm.Set_Height(Integer.parseInt(height_Text.getText()));
            	pm.Set_Width(Integer.parseInt(width_Text.getText()));
   				System.out.println(file_name.getText());
            	dispose();
            }
        });
		
		this.add(OK);
		
		
		this.setSize(308,260);
		this.setTitle("New");
		this.setResizable(false);
		this.setLocation(500,500);
	}
}


the variable AS is a JPanel that takes the collected information and sends it to the rest of the program.
Was This Post Helpful? 0
  • +
  • -

#18 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: popup window

Posted 25 May 2010 - 08:30 PM

Works for me as a few System.out.println() show it... your problem must be somewhere else

I got ride of your unused variables and the APPStarter class that I do not have

public class ProjectM extends JFrame 
{        
        private String fileName; 
        private int width; 
        private int height; 
        private String ImageLocation; 
        private int tileSize; 
         
        private ContextPane CP = new ContextPane(this);; 
 //       private AppStarter AS; 
         
        //Constructor 
        public ProjectM() 
        { 
                //sets the layout manager 
                this.setLayout(null); 
         
                JMenuBar menuBar = new JMenuBar(); 
                 
                this.setJMenuBar(menuBar); 
                 
                JMenu fileMenu = new JMenu("File"); 
                 
                menuBar.add(fileMenu); 
                 
                JMenuItem newAction = new JMenuItem("New"); 
                 
                fileMenu.add(newAction); 
                 
                newAction.addActionListener(new ActionListener()  
                { 
            public void actionPerformed(ActionEvent e)  
            { 
            	System.out.println("Setting CP to visible");
                CP.setVisible(true); 
            	System.out.println("back after set visible so the JDialog should have dispose");
                System.out.println("What would you like to call your new map?"); 
            } 
        }); 
         
                //Sets the size, title, close operation, and visibility of ProjectM JFrame 
                this.setSize(937,532); 
                this.setTitle("ProjectM"); 
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
                this.setResizable(false); 
                this.setVisible(true); 
        }        
         
        public void Set_File_Name(String fn) 
        { 
                this.fileName = fn; 
                System.out.println("FileName set to: " + this.fileName);
        } 
         
        public void Set_Tile_Directory(String td) 
        { 
                this.ImageLocation = td; 
        } 
         
        public void Set_Tile_Size(int ts) 
        { 
                this.tileSize = ts; 
                System.out.println("TileSize set to: " + this.tileSize);
        } 
         
        public void Set_Height(int h) 
        { 
                this.height = h; 
                System.out.println("Height set to: " + this.height);
        } 
         
        public void Set_Width(int w) 
        { 
                this.width = w; 
                System.out.println("Width set to: " + this.width);
        } 
         
        //Main Method    
        public static void main(String[]args) 
        { 
                //Creates ProjectM JFrame 
                new ProjectM(); 
        } 
}


And here is the console output
Setting CP to visible
FileName set to: heloWorld
TileSize set to: 32
Height set to: 15
Width set to: 20
heloWorld
back after set visible so the JDialog should have dispose
What would you like to call your new map?


Was This Post Helpful? 0
  • +
  • -

#19 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: popup window

Posted 26 May 2010 - 07:07 AM

The app starter part is the problem. Because after you set everything. it is sopposto create the rest of the program.

When i get home ill post the code to the rest of my classes if it helps.

And i think it might work if i create 2 constructors to the app starter class.
Was This Post Helpful? 0
  • +
  • -

#20 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: popup window

Posted 26 May 2010 - 10:37 AM

2 constructors did not work.

This is my app Starter Class.
public class AppStarter extends JPanel
{	
	private MapPanel MP;

	//Constructor
	public AppStarter(String fileName, int width, int height, String ImageLocation, int tileSize)
	{
		//sets the layout manager
		this.setLayout(null);

		MP = new MapPanel(fileName, width, height, tileSize);
		MP.setBounds(289,0,640,480);
		this.add(MP);
		
		MP.set_Layer(0);
		
		//Creates, sets position, sets scroll bar polocys and adds the TSP JscrollPane
		JScrollPane TSP = new JScrollPane(new TileSetPanel(MP,ImageLocation));
		TSP.setBounds(0,0,290,481);
		TSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		this.add(TSP);
	}
}

Was This Post Helpful? 0
  • +
  • -

#21 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: popup window

Posted 26 May 2010 - 03:44 PM

Your AppStarter is a ull layout, it needs bounds
Was This Post Helpful? 0
  • +
  • -

#22 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: popup window

Posted 26 May 2010 - 06:48 PM

View Postpbl, on 26 May 2010 - 02:44 PM, said:

Your AppStarter is a ull layout, it needs bounds


It has bounds there set when its created and there set inside of it. the app starter class and all the other classes inside of it work.

The problem lies in how its added to the Main JFrame
Was This Post Helpful? 0
  • +
  • -

#23 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: popup window

Posted 26 May 2010 - 07:17 PM

You should start to use null layout it is coming very confusing...

As I didn't have access to your MapPanel and TitleSetPanel I did this to color your panel

public class AppStarter extends JPanel 
{        
 //       private MapPanel MP; 
 
        //Constructor 
        public AppStarter(String fileName, int width, int height, String ImageLocation, int tileSize) 
        { 
                //sets the layout manager 
                this.setLayout(null); 
                setBackground(Color.BLUE);
 
//                MP = new MapPanel(fileName, width, height, tileSize); 
//                MP.setBounds(289,0,640,480); 
//                this.add(MP); 
                 
//                MP.set_Layer(0); 
                 
                //Creates, sets position, sets scroll bar polocys and adds the TSP JscrollPane 
//                JScrollPane TSP = new JScrollPane(new TileSetPanel(MP,ImageLocation)); 
                JTextArea x = new JTextArea();
                x.setText("Hello world");
                JScrollPane TSP = new JScrollPane(x); 
                TSP.setBounds(0,0,290,481); 
                TSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 
                this.add(TSP); 
        } 
}



You will see it at the bottom right of your main panel
Make your main frame resizable it will help you
Was This Post Helpful? 0
  • +
  • -

#24 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: popup window

Posted 27 May 2010 - 07:25 PM

@pbl same thing happened it doesn't display anything.

any more ideas?
Was This Post Helpful? 0
  • +
  • -

#25 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: popup window

Posted 28 May 2010 - 11:33 AM

I still think that its the method i call in the main frame thats causing the problem.

the method i call in the main Frame
public void create_as()
        {
                AS = new AppStarter(this.fileName, this.width, this.height, this.ImageLocation, this.tileSize);
                AS.setBounds(0,0,930,961);
                this.add(AS);
        }



Would it be better to make the AppStarter a child of the Main Frame would that work?
Was This Post Helpful? 0
  • +
  • -

#26 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: popup window

Posted 28 May 2010 - 02:27 PM

View Postgiuseppe105, on 28 May 2010 - 12:33 PM, said:

[/code]

Would it be better to make the AppStarter a child of the Main Frame would that work?

Depends what you call a child of the Main Frame
All your problems are coming from your setBounds()

Make your MainFrame a BorderLayout and add your AppStarter BorderLayout.CENTER
Was This Post Helpful? 0
  • +
  • -

#27 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: popup window

Posted 28 May 2010 - 08:45 PM

Sorry PBL still no luck.

by child i mean have a second JFrame inside the first JFrame you know like in Photoshop where you can move windows around inside the application.

Vb6 does it.
Was This Post Helpful? 0
  • +
  • -

#28 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: popup window

Posted 29 May 2010 - 07:53 AM

View Postgiuseppe105, on 28 May 2010 - 07:45 PM, said:

Sorry PBL still no luck.

by child i mean have a second JFrame inside the first JFrame you know like in Photoshop where you can move windows around inside the application.

Vb6 does it.


I found what i meant. its called a JInternalFrame and it must be used with a JDesktopPane or a multy layered pane.
Was This Post Helpful? 0
  • +
  • -

#29 giuseppe105  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 444
  • Joined: 15-May 08

Re: popup window

Posted 29 May 2010 - 08:44 AM

I DID IT! IT WORKS!

first i made a seperate project and tested out how to use the JDesktopPane and JInternalFrame

When i had it putting a button inside a window i began add the JDesktopPane and JinternalFrame to my project.

I added these lines of code to my project.

import javax.swing.JDesktopPane;

private JDesktopPane desktop = new JDesktopPane();

this.setContentPane(desktop);


Now i have a bad habit of pressing the RUN button to compile and save my work.

I ran the program it compiled fine and opened so i tried it and IT WORKED!

it must of had something to do with the content Pane because when i added a new one it worked fine?

anyone know why this worked?
Was This Post Helpful? 0
  • +
  • -

#30 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,438
  • Joined: 20-September 08

Re: popup window

Posted 29 May 2010 - 08:51 AM

I'm a bit confused now. You started with dialogs and ended with internal frames and i'm not sure why ...
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3