在使用Swing创建应用程序时,我看到人们会做两件事之一来创建JFrame.哪种方法更好,为什么?
我是Java和编程的初学者.我唯一的学习来源是书籍,YouTube和Stack Overflow.
import {imports};
public class GuiApp1 {
public static void main(String[] args) {
new GuiApp1();
}
public GuiApp1() {
JFrame guiFrame = new JFrame();
guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
guiFrame.setTitle("Example GUI");
guiFrame.setSize(300,250);
................
}
Run Code Online (Sandbox Code Playgroud)
和
import {imports};
public class GuiApp1 extends JFrame {
public Execute() {
getContentPane().setBackground(Color.WHITE);
getContentPane().setLayout(null);
setSize(800, 600);
.............
}
public static void main(String[] args) {
Execute frame1 = new Execute();
frame1.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)