[英]Jlabel, Jtextfield, Jbutton do not immediately show up in the GUI I mad
我的 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);
}
}
在此先感谢那些审查代码的人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.