我在GUI上显示元素时遇到问题。我正在创建一个非常简单的程序,在该程序中,我要求用户在三个不同的框中输入三个不同的整数,并在按下按钮时将这些数字加在一起。现在,我已经创建了一个按钮,一个文本字段和一个标签,但是有一个问题:该按钮,文本字段和标签没有出现在GUI上。我必须将鼠标悬停在按钮区域上才能使其显示并与文本字段相同。即使我将鼠标悬停在原本应该显示的位置,标签也不会显示。为什么会这样呢?这是我的代码
import javax.swing.*;
public class ButtonPractice extends javax.swing.JFrame
{
public static void main(String[] args)
{
JFrame box = new JFrame("Simple addition");
box.setVisible(true);
box.setSize(500,500);
box.setResizable(false);
box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(null);
box.add(panel);
JTextField inputNumOne = new JTextField("Integer here");
inputNumOne.setBounds(225,50,200,30);
panel.add(inputNumOne);
JLabel labelNumOne = new JLabel("First integer");
labelNumOne.setBounds(100,50,150,50);
panel.add(labelNumOne);
JButton combiner = new JButton("Concactentate");
//positioning of the button on the panel
combiner.setBounds(175,300,125,50);
panel.add(combiner);
}
}
在此先感谢审核代码的人!