我尝试只使用 add.method 将按钮添加到框架。但只有框架弹出。 我没有看到任何按钮。
import javax.swing.*;
public class okd {
public static void main() {
JFrame frame = new JFrame();
JButton b1 = new JButton();
frame.setSize(500,500);
frame.add(b1);
b1.setSize(400,400);
b1.setVisible(true);
frame.setVisible(true);
}
}
最佳答案
那里有一个按钮。向其中添加一些文本,它就会神奇地出现。
public static void main(String[] args){
JFrame frame = new JFrame();
JButton b1 = new JButton();
frame.setSize(500,500);
b1.setSize(400,400);
b1.setVisible(true);
b1.setText("HelloWorld");
frame.add(b1);
frame.setVisible(true);
}//SSCCE1
关于Java:如何将按钮添加到框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20601505/