Results 1 to 5 of 5
- 07-23-2012, 08:52 PM #1
Member
- Join Date
- May 2012
- Posts
- 15
- Rep Power
- 0
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:
And in the second class happend the same... I call my main JFrame class and I add this.dispose() to close that frame.Java Code:if(e.getSource()== openSecond){ secondClass.main(null); // open my second class this.dispose(); // close this one }
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!
- 07-23-2012, 11:01 PM #2
Re: How to call JDialog class from JFrame class?
Find and go through the Oracle tutorial on How to Make Dialogs.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 07-24-2012, 01:13 AM #3
Member
- Join Date
- May 2012
- Posts
- 15
- Rep Power
- 0
Re: How to call JDialog class from JFrame class?
Thanks!
I know how to make JDialogs this is mi class file called altaEmprendedor.class
I'm calling this from a JFrame class called main.class with the commented lines: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); } } } }
So when you press a button in the main.class it opens altaEmprendedor.classJava 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 } } }
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.gif)
Thanks in advance!
- 07-24-2012, 02:21 AM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Re: How to call JDialog class from JFrame class?
Read post #2...in the tutorials, there is mention of modality which may be of interest to you.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
- 07-24-2012, 03:29 AM #5
Member
- Join Date
- May 2012
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
Eclipse Compile Error: Call validateValue(Class<T>, String, Object, Class<?>...)
By Tomshi in forum EclipseReplies: 0Last Post: 03-27-2011, 05:49 AM -
how call from inner class(anonymous or not), a method of parent class?
By lse123 in forum AWT / SwingReplies: 2Last Post: 05-01-2010, 08:59 AM -
How can I call abstract class methods from another class
By srinivas2828 in forum New To JavaReplies: 13Last Post: 03-12-2010, 02:33 PM -
How can I call method from class in other class??
By Hisham in forum New To JavaReplies: 6Last Post: 02-14-2010, 03:49 PM -
problem in accessing array values of one class in to jframe class
By cenafu in forum AWT / SwingReplies: 8Last Post: 03-21-2009, 09:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks