0

I wanted to use the Windows-Builder plugin of eclipse to design my JFrame. Unfortunately when I create a second JFrame 'f2' it does not show up in Window- Builder as in the picture here: https://i.stack.imgur.com/dlWld.jpg

Here is my code too:

import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class AgeGuesser {
    public static void main(String[] args) 
    {
      AgeGuesser.f1m();
    }

    public static void f1m()
    {
      JFrame f1= new JFrame("AgeGuesser");
      f1.setSize(500,200);
      f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f1.setVisible(true);
      f1.setResizable(false);
      f1.setLocationRelativeTo(null);
      f1.getContentPane().setLayout(null);    

      JLabel lbl1 = new JLabel("Welcome to the AgeGuesser! What do you wish to do?");
      lbl1.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 18));
      lbl1.setBounds(12, 13, 470, 35);
      f1.getContentPane().add(lbl1);

      JLabel lbl2 = new JLabel("do?");
      lbl2.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 18));
      lbl2.setBounds(210, 38, 48, 35);
      f1.getContentPane().add(lbl2);

      JButton guessmyage = new JButton("Guess my Age!!");
      guessmyage.setFont(new Font("Microsoft JhengHei Light", Font.BOLD | Font.ITALIC, 24));
      guessmyage.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) 
        {
          AgeGuesser.f2();
          f1.setVisible(false);
        }
      });
      guessmyage.setBounds(12, 96, 230, 56);
      f1.getContentPane().add(guessmyage);

      JButton Exit = new JButton("Exit");
      Exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e)
        {
          System.exit(0);
        }
      });
      Exit.setFont(new Font("Microsoft JhengHei Light", Font.BOLD | Font.ITALIC, 24));
      Exit.setBounds(254, 96, 230, 56);
      f1.getContentPane().add(Exit);
    }

    public static void f2()
    {
        JFrame f2= new JFrame("AgeGuesser");
          f2.setSize(500,200);
          f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f2.setVisible(true);
          f2.setResizable(false);
          f2.setLocationRelativeTo(null);
          f2.getContentPane().setLayout(null);    
    }
}
Joel Jacob
  • 13
  • 2
  • 1
    The question is, why should it? You've defined a local variable inside a `static` method, how would anybody know it ever existed? If you want to know the solution, it would be, don't use a form editor until you have a better understanding how to make a UI by hand. I would also suggest, if you really want to go this path, start a new project and create your windows from scratch and see how WB creates/handles them, including providing access to your internal components – MadProgrammer Jan 31 '17 at 01:33
  • 1
    See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Jan 31 '17 at 03:07
  • 1
    Also please avoid the use of `null-layout`, see [null Layout is evil](http://www.leepoint.net/GUI/layouts/nulllayout.html) and the answers in [this question](http://stackoverflow.com/questions/6592468/why-is-it-frowned-upon-to-use-a-null-layout-in-swing) – Frakcool Jan 31 '17 at 05:50
  • I do know know that but I have no choice as I need to place the components of the JFrame in an Absolute Location. – Joel Jacob Jan 31 '17 at 23:54

0 Answers0