有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

NetBeans中GUI之前的java JOptionPane

我试图在Netbeans中的JFrame窗体之前放置一个JOptionPane。我尝试将它放置在框架的源中,它会显示optionpane,但当我单击“确定”时,框架不会显示,而只显示窗口显示的“最小”、“最大”和“关闭”按钮。我不知道我应该把optionpane的代码放在哪里,让它在框架前显示。有人能帮我吗

public final class CineVivero extends javax.swing.JFrame {

public void popups(){

    Object[] opening = {
        "Bienvenido a Movie Counter"
            + "\n Esta aplicación fue hecha para Multicines Metro Vivero."
            + "\n Aquí se podra registrar el porcentaje de ocupación de"
            + "\n las instalaciones y los ingresos desde el momento que se"
            + "\n abre la aplicación.",
    };

    JOptionPane.showMessageDialog(null, opening, "Movie Counter", 2);
}


public CineVivero() {
    popups();
}

public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {

            new CineVivero().setVisible(true);
        }
    });
}

共 (1) 个答案

  1. # 1 楼答案

    but when i click ok the frame doesnt appear just the mini,max,close buttons of the window show

    你在相框上加了什么吗?你指定尺寸了吗?默认情况下,窗口为0x0

    当我修改代码并设置其大小(在本例中为100x100)时,它对我来说很好

    import javax.swing.JOptionPane;
    
    public final class CineVivero extends javax.swing.JFrame {
    
        public void popups() {
    
            Object[] opening = {
                "Bienvenido a Movie Counter"
                + "\n Esta aplicación fue hecha para Multicines Metro Vivero."
                + "\n Aquí se podra registrar el porcentaje de ocupación de"
                + "\n las instalaciones y los ingresos desde el momento que se"
                + "\n abre la aplicación.",};
    
            JOptionPane.showMessageDialog(null, opening, "Movie Counter", 2);
        }
    
        public CineVivero() {
            setSize(100, 100);
            setLocationRelativeTo(null);
            popups();
        }
    
        public static void main(String args[]) {
    
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
    
                    new CineVivero().setVisible(true);
                }
            });
        }
    }