Results 1 to 3 of 3
  1. #1
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default Open a new window and drawing map into it

    Hi.
    I want to write small program that have a main window. There is a button in window. When I click on that button, I want to open new window, and in that new window to show map of the museum.

    Please give me suggestion what component I should use for that new window.

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

    Default

    JFrame would work.

  3. #3
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    Yes it works with JFrame. Thank you for advice.

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    
    public class NewWindow {
    	public static void main(String[] args) {
    		SwingUtilities.invokeLater(new Runnable() {
    			
    			@Override
    			public void run() {
    				NewFrame frame = new NewFrame();
    				frame.showGUI();
    			}
    		});
    	}
    }
    
    class NewFrame extends JFrame {
    	JFrame frame;
    	JButton button;
    	
    	public NewFrame() {
    		button = new JButton("open new window");
    		getContentPane().add(button, BorderLayout.NORTH);
    		
    		button.addActionListener(new NewWindowListener());
    	}
    	
    	public void showGUI() {
    		setTitle("First Window");
    		setSize(new Dimension(500,500));
    		setLocationRelativeTo(null);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setVisible(true);
    	}
    	
    	private class NewWindowListener implements ActionListener {
    
    		@Override
    		public void actionPerformed(ActionEvent arg0) {
    			NewWindow window = new NewWindow();
    			window.showIt();
    		}
    		
    	}
    	
    	private class NewWindow extends JFrame {
    		
    		public NewWindow() {
    			
    		}
    		
    		public void showIt() {
    			setTitle("Open new window");
    			setSize(new Dimension(400,200));
    			setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    			setLocationRelativeTo(null);
    			setVisible(true);
    		}
    	}
    }

Similar Threads

  1. window.open problem
    By praveenkumar14 in forum NetBeans
    Replies: 2
    Last Post: 10-12-2009, 11:18 AM
  2. Callback when window is done drawing/loading?
    By rodrigo in forum SWT / JFace
    Replies: 0
    Last Post: 08-21-2009, 02:01 AM
  3. how to open an internet Window
    By loa41 in forum New To Java
    Replies: 3
    Last Post: 07-30-2009, 05:20 AM
  4. drawing window
    By BlitzA in forum New To Java
    Replies: 1
    Last Post: 01-15-2009, 12:55 PM
  5. drawing window
    By BlitzA in forum Advanced Java
    Replies: 0
    Last Post: 12-30-2007, 05:39 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
  •