为什么我的 GUI 没有显示任何按钮、标签或文本字段?
我想我已经设置好了,但是当我运行它时,只显示框架,没有任何内容出现。
package BasicGame;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class Gui extends JFrame{
private static final long serialVersionUID = 1L;
private JLabel label;
private JTextField textField;
private JButton button;
private buttonHandler bHandler;
public Gui(){
setTitle("Basic Gui");
setResizable(false);
setSize(500, 200);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container pane = getContentPane();
pane.setLayout(null);
button = new JButton("button");
button.setBounds(50, 60, 50, 70);
bHandler = new buttonHandler();
button.addActionListener(bHandler);
label = new JLabel("Hello", SwingConstants.RIGHT);
label.setBounds(50, 60, 50, 70);
textField = new JTextField(10);
textField.setBounds(50, 60, 50, 70);
pane.add(button);
pane.add(label);
pane.add(textField);
}
public class buttonHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}
@SuppressWarnings("unused")
public static void main(String[] args){
Gui gui = new Gui();
}
}