Results 1 to 5 of 5
  1. #1
    garnachito is offline Member
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default How to call JDialog class from JFrame class?

    Hi guys, please I need some help:

    At this point I only know how to call another JFrame class like this:

    Java Code:
            if(e.getSource()== openSecond){
    	secondClass.main(null);   // open my second class
    	this.dispose();               // close this one
    }
    And in the second class happend the same... I call my main JFrame class and I add this.dispose() to close that frame.

    Now I'm trying to have only one JFrame as main class and JDialog classes as modules of the JFrame, so, when I call JDialog I want to disable de main JFrame until the JDialog class closes.

    I need someone please to help me to point me in the right direction to be able to do this.

    Thanks a lot!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: How to call JDialog class from JFrame class?

    Find and go through the Oracle tutorial on How to Make Dialogs.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    garnachito is offline Member
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default Re: How to call JDialog class from JFrame class?

    Thanks!

    I know how to make JDialogs this is mi class file called altaEmprendedor.class

    Java Code:
    public class altaEmprendedor extends JDialog {
    
    	private final JPanel contentPanel = new JPanel();
    
    	/**
    	 * Launch the application.
    	 */
    	public static void main(String[] args) {
    		try {
    			altaEmprendedor dialog = new altaEmprendedor();
    			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    			dialog.setVisible(true);
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	/**
    	 * Create the dialog.
    	 */
    	public altaEmprendedor() {
    		setBounds(100, 100, 652, 430);
    		getContentPane().setLayout(new BorderLayout());
    		contentPanel.setLayout(new FlowLayout());
    		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    		getContentPane().add(contentPanel, BorderLayout.CENTER);
    		{
    			JPanel buttonPane = new JPanel();
    			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
    			getContentPane().add(buttonPane, BorderLayout.SOUTH);
    			{
    				JButton okButton = new JButton("OK");
    				okButton.setActionCommand("OK");
    				buttonPane.add(okButton);
    				getRootPane().setDefaultButton(okButton);
    			}
    			{
    				JButton cancelButton = new JButton("Cancel");
    				cancelButton.setActionCommand("Cancel");
    				buttonPane.add(cancelButton);
    			}
    		}
    	}
    
    }
    I'm calling this from a JFrame class called main.class with the commented lines:

    Java Code:
    public class main extends JFrame implements ActionListener {
    
    	JButton btnNewButton;
    	private JPanel contentPane;
    
    	/**
    	 * Launch the application.
    	 */
    	public static void main(String[] args) {
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					main frame = new main();
    					frame.setVisible(true);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	}
    
    	/**
    	 * Create the frame.
    	 */
    	public main() {
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setBounds(100, 100, 450, 300);
    		contentPane = new JPanel();
    		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    		setContentPane(contentPane);
    		contentPane.setLayout(null);
    		
    		btnNewButton = new JButton("Open JDialog");
    		btnNewButton.setBounds(149, 125, 134, 23);
    		btnNewButton.addActionListener(this);
    		contentPane.add(btnNewButton);
    	}
    	
    	public void actionPerformed(ActionEvent e){
    		
    		if(e.getSource()== btnNewButton){
    			altaEmprendedor.main(null);          //I'm calling the JDialog class with this line
    		}
    		
    		
    	}
    	
    }
    So when you press a button in the main.class it opens altaEmprendedor.class

    Now the problem is that doing this the main.class window is still enabled and I need to disable that window until the user closes the JDialog window

    Thanks in advance!

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: How to call JDialog class from JFrame class?

    Now the problem is that doing this the main.class window is still enabled and I need to disable that window until the user closes the JDialog window
    Read post #2...in the tutorials, there is mention of modality which may be of interest to you.

  5. #5
    garnachito is offline Member
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default Re: How to call JDialog class from JFrame class?

    You're absolutely right, thanks a lot.

Similar Threads

  1. Replies: 0
    Last Post: 03-27-2011, 05:49 AM
  2. Replies: 2
    Last Post: 05-01-2010, 08:59 AM
  3. How can I call abstract class methods from another class
    By srinivas2828 in forum New To Java
    Replies: 13
    Last Post: 03-12-2010, 02:33 PM
  4. How can I call method from class in other class??
    By Hisham in forum New To Java
    Replies: 6
    Last Post: 02-14-2010, 03:49 PM
  5. Replies: 8
    Last Post: 03-21-2009, 09:34 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
  •