Opening a new JFrame by clicking a button
-
I want to know how to open this JFrame form (1) when I click a button in the second JFrame (2). The problem is that I am unable to get the .setVisible method in the Form 2. Please help. Thanks & Regards ! :) Form 1 (to be opened when a button is clicked on Form 2 public class FlightForm { public FlightForm() { initialize(); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { FlightForm window = new FlightForm(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } } } } Form 2 public class MainMenu{ private JFrame frame; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { MainMenu window = new MainMenu(); window.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public MainMenu() { frame = new JFrame("Main Menu"); setBounds(100, 100, 830, 574); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); JButton btnNewButton = new JButton("Flight Form"); ); btnNewButton.setFont(new Font("Candara", Font.BOLD, 15)); btnNewButton.setBounds(169, 328, 193, 77); frame.getContentPane().add(btnNewButton); JButton btnNewButton_1 = new JButton("Passenger Form"); btnNewButton_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PassengerForm window = new PassengerForm(); window.setVisible(true); // This is not working
-
Answer:
You can call setVisible(true) on PassengerForm() only if PassengerForm class extends JFrame. If no you should use something like: PassengerForm window = new PassengerForm(); window.getFrame().setVisible(true)
niibz at Stack Overflow Visit the source
Related Q & A:
- What's causing warnings when clicking a link in a newsletter/email message?Best solution by Webmasters
- Can I trade a new Xbox 360 for a new PS3?Best solution by gamestop.com
- How do you deal with a new Boss who has a bad impression about you?Best solution by artofmanliness.com
- How do you stop Yahoo from opening links in a new window?Best solution by answers.yahoo.com
- Opening a New Electronic Store?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.