在使用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) 我有一个使用JMenu创建的菜单.我想将快捷键Alt-F分配给此菜单.我使用setMnemonic('F')来做到这一点,但菜单无法识别助记符.
解决或调试此问题的最佳方法是什么?我发现设置一个断点并没有多大帮助.
谢谢.
代码片段:
//higher up in variable declaration
/** Menus on the menu bar */
private JMenu uiFindMnu = new JMenu("Find");
...
//inside the constructor
// set mnemonic for the Find menu
uiFindMnu.setMnemonic('F');
Run Code Online (Sandbox Code Playgroud) 我有一个扩展Thread的类,需要在同一个类上扩展JFrame.由于Java中不可能进行多重继承,如何在已经扩展Thread的类中使用JFrame对象?
延伸到JFrame和有区别javax.swing.JFrame吗?
例:
public class Authenticator extends JFrame {
Run Code Online (Sandbox Code Playgroud)
和...
public class Authenticator extends javax.swing.JFrame {
Run Code Online (Sandbox Code Playgroud)