import javax.swing.JFrame;Output
public class 测试扩展 JFrame{
public static void main(String[] args) {
//1.创建一个 JFrame
JFrame window = new JFrame(JFrame Test”);
//2.关闭 window
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) 后停止应用程序;
//3.设置维度宽度和高度
window.setSize(400,300);
//4.可选:居中位置
window.setLocationRelativeTo(null);
//5.显示窗口
window.setVisible(true);
}
}
import javax.swing.JFrame;Output
导入 javax.swing.JTextArea;
public class Test extends JFrame{
public static void main(String[] args) {
JFrame frame = new JFrame(JFrame test”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
JTextArea jta = new JTextArea(键入文本”);
//调整textArea
jta.setPreferredSize(new Dimension(400,300));
//在中心放一个文本框
frame.add(jta);
//在南边放一个按钮
frame.add(new JButton(erase”),BorderLayout.SOUTH);
//通过对 JtextArea 和 JButton
frame.pack() 的维度求和,自动计算出窗口大小;
}
}
Please disable your ad blocker and refresh the window to use this website.