窗口构建器不显示多个JFrame

时间:2017-01-31 01:27:19

标签: java swing windowbuilder

我想使用eclipse的Windows-Builder插件来设计我的JFrame。不幸的是,当我创建第二个JFrame'f2'时,它不会出现在Window-Builder中,如下图所示:https://i.stack.imgur.com/dlWld.jpg

这也是我的代码:

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);    
    }
}

0 个答案:

没有答案