gpt4 book ai didi

java - 如何让 JFrame 显示我的 GUI?

转载 作者:行者123 更新时间:2023-12-02 05:13:30 25 4
gpt4 key购买 nike

我正在使用 Netbeans,并且之前已经启动并运行过它,但我弄乱了一些代码,现在它不是了。有人可以告诉我我做错了什么吗?

public class OrderGUI extends javax.swing.JFrame {

ArrayList orders = new ArrayList<>();

public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(OrderGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(OrderGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(OrderGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(OrderGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
OrderGUI gui = new OrderGUI();
gui.setVisible(true);
gui.setTitle("Flexbox Order System");
gui.setResizable(false);
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
});
}
}

最佳答案

您只是忘记设置大小:它在我的系统上运行良好。在这里,我为你清理了一些。

 package developerToolsNotForDeployment;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;


public class OrderGUI extends javax.swing.JFrame {

ArrayList orders = new ArrayList<>();

public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
OrderGUI gui = new OrderGUI();
gui.setTitle("Flexbox Order System");
gui.setResizable(false);
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setSize(new Dimension(400,400));
gui.setVisible(true);
}
});
}

关于java - 如何让 JFrame 显示我的 GUI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27158148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com