【发布时间】:2020-08-25 02:36:09
【问题描述】:
这是我第一次在这个网站上寻求帮助。我需要从 public static void main(String[] args) 中移动 JFrame 和 JMenubar。
public static void main(String[] args){
ResourceBundle res = ResourceBundle.getBundle("georglider.grandom.lang.lang");
JFrame F = new JFrame(res.getString("GRandom"));
F.setContentPane(new GRandom().JP1);
F.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
F.pack();
F.setVisible(true);
F.setSize(300,163);
F.setResizable(false);
JMenuBar gmenu = new JMenuBar();
JMenu Mode = new JMenu("Режим");
JMenu Display = new JMenu("После генерации");
JMenu GenerateOptions = new JMenu("Опции для генерации");
gmenu.add(Mode);
gmenu.add(Display);
gmenu.add(GenerateOptions);
Icon dicon = new Icon() {
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
}
@Override
public int getIconWidth() {
return 0;
}
@Override
public int getIconHeight() {
return 0;
}
};
//M = Menu | D = Display | GO = GenerateOptions
JRadioButtonMenuItem Mnumbers = new JRadioButtonMenuItem("Генерировать числа",dicon,true);
Mnumbers.setActionCommand("Mnumbers");
JRadioButtonMenuItem Mstring = new JRadioButtonMenuItem("Генерировать заданные строки");
Mstring.setActionCommand("Mstring");
JRadioButtonMenuItem Ddefault = new JRadioButtonMenuItem("По умолчанию",dicon,true);
Ddefault.setActionCommand("Ddefault");
JRadioButtonMenuItem Dopen = new JRadioButtonMenuItem("Открыть файл");
Dopen.setActionCommand("Dopen");
JRadioButtonMenuItem Dshowhere = new JRadioButtonMenuItem("Показать здесь");
Dshowhere.setActionCommand("Dshowhere");
JRadioButtonMenuItem GOninclude = new JRadioButtonMenuItem("Не включать числа");
Dshowhere.setActionCommand("GOninclude");
Mode.add(Mnumbers);
Mode.add(Mstring);
Display.add(Ddefault);
Display.add(Dopen);
Display.add(Dshowhere);
GenerateOptions.add(GOninclude);
F.setJMenuBar(gmenu);
}
这是我需要从 public static void main(String[] args) 移出的代码
我尝试将其移至 GRandom() 类(它是主类)并使 public static void main(String[] args) 看起来像这样:
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
new JMenuTest();
}
它没有任何错误,但没有任何显示:(
请帮助我,如何将其移至 GRandom() 类,或制作另一个
【问题讨论】:
-
欢迎使用 stackoverflow。参观并获得您的第一个徽章-stackoverflow.com/tour
-
添加类名代码,让这个问题更清晰
-
变量名不应以大写字符开头。有些是正确的,有些则不是。保持一致并从您阅读的教科书和教程中通过示例学习。