新的netbeans项目输出代码,但不输出jframe ui

aydmsdu9  于 2023-10-20  发布在  其他
关注(0)|答案(1)|浏览(117)

我刚刚创建了一个新的java项目并打开了一个jframe文件。当我添加了几个按钮并预览它时,它看起来很好。但是当我运行这个文件(indexx.java)时,它只显示了标准的'Hello World'输出,没有其他的。它不显示JFrame。
我看了一些教程,为什么它可能会发生,没有一个工作。- 设置项目配置并将主类设置为indexx不起作用
它只是向我展示了构建成功
这是我的indexx.java文件

import javax.swing.JOptionPane;
public class indexx extends javax.swing.JFrame {

   
    public indexx() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        student = new javax.swing.JButton();
        admin = new javax.swing.JButton();
        exit = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setUndecorated(true);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        student.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        student.setIcon(new javax.swing.ImageIcon(getClass().getResource("/studentedited.png"))); // NOI18N
        student.setText("Student");
        student.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                studentActionPerformed(evt);
            }
        });
        getContentPane().add(student, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 120, 150, -1));

        admin.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        admin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/admin_1.png"))); // NOI18N
        admin.setText("Admin");
        admin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adminActionPerformed(evt);
            }
        });
        getContentPane().add(admin, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 200, 150, -1));

        exit.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        exit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/exitt.png"))); // NOI18N
        exit.setText("Exit");
        exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitActionPerformed(evt);
            }
        });
        getContentPane().add(exit, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 280, 150, -1));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/t.jpg"))); // NOI18N
        jLabel1.setText(" ");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 840, 480));

        pack();
    }// </editor-fold>                        

    private void studentActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
    }                                       

    private void exitActionPerformed(java.awt.event.ActionEvent evt) {                                     

        
    int a = JOptionPane.showConfirmDialog(null, "Exit Application?", "Select", JOptionPane.YES_NO_OPTION);
    if(a==0){
        System.exit(0);
    }else{}
// TODO add your handling code here: 
    }                                    

    private void adminActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // TODO add your handling code here:
    }                                     

    /**
     * @param args the command line arguments
     */
    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(indexx.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(indexx.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(indexx.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(indexx.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() {
                new indexx().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton admin;
    private javax.swing.JButton exit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton student;
    // End of variables declaration                   
}

这是我的主要课程

package com.mycompany.quiz_management;
//import javax.swing.JFrame;
/**
 *
 * @author HP
 */
public class Quiz_Management {

    public static void main(String[] args) {

        System.out.println("Hello World!");
    }
}

我几乎没有添加任何东西,我下面的教程没有遇到这个问题。任何建议/帮助将不胜感激。

fcy6dtqo

fcy6dtqo1#

这是因为在**com.mycompany.quiz_management类中的main下,您只打印了“Hello World”,而实际上并没有创建indexxJFrame的示例。
main上示例化indexx**。

public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new indexx().setVisible(true);
            }
        });
    }

相关问题