Java Netbeans-按钮函数非法启动表达式

Java Netbeans-按钮函数非法启动表达式,java,swing,netbeans,Java,Swing,Netbeans,我创建了一个JFrame表单并在其上放置了一个按钮,然后在源代码内部创建了一个actionformed。程序给出一个错误,如非法启动表达式 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: System.exit(0); }

我创建了一个JFrame表单并在其上放置了一个按钮,然后在源代码内部创建了一个actionformed。程序给出一个错误,如非法启动表达式

 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
    System.exit(0);
}                  
顺便说一下, 在为按钮创建actionformed之前,main函数有相同的错误。当我为按钮创建ActionFormat时,它消失了,程序显示了按钮功能中的错误

这是我的主要功能

    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(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(() -> {
        Login dialog = new Login(new javax.swing.JFrame(), true); 
        dialog.addWindowListener(new java.awt.event.WindowAdapter() {

            @Override
           public void windowClosing(java.awt.event.WindowEvent e) {
               System.exit(0);
           } 
        });
        dialog.setVisible(true);

    });
}
publicstaticvoidmain(字符串参数[]){
/*设置Nimbus的外观和感觉*/
//
/*如果Nimbus(在JavaSE6中引入)不可用,请使用默认的外观。
*详情请参阅http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
*/
试一试{
for(javax.swing.UIManager.LookAndFeelInfo:javax.swing.UIManager.getInstalledLookAndFeels()){
if(“Nimbus”.equals(info.getName())){
setLookAndFeel(info.getClassName());
打破
}
}
}捕获(ClassNotFoundException ex){
getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}catch(实例化异常){
getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}捕获(非法访问例外){
getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}catch(javax.swing.UnsupportedLookAndFeelException ex){
getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}
//
/*创建并显示表单*/
java.awt.EventQueue.invokeLater(()->{
登录对话框=新登录(newjavax.swing.JFrame(),true);
addWindowListener(新java.awt.event.WindowAdapter(){
@凌驾
公共无效窗口关闭(java.awt.event.WindowEvent e){
系统出口(0);
} 
});
对话框.setVisible(true);
});
}

在其上放置一个按钮,然后在源代码中创建一个actionformed
您的意思是在JButton中添加了一个ActionListener吗?请指出在发布的代码中出现错误的位置。@copeg l在JButton中添加了actionPerformed。然后程序创建了JButton函数,它是“private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)”。在该函数(按钮函数)上,出现表达式错误的非法开始图片不是诊断代码问题的最佳方法-请编辑您的问题,以包含需要复制的代码。您的代码未编译,也未包含任何按钮。好的,我已解决了问题。我忘了给第一个公共类加“}”