Java:此行有多个标记-标记“)”上的语法错误;应为-标记“(”,{应为)上的语法错误

Java:此行有多个标记-标记“)”上的语法错误;应为-标记“(”,{应为)上的语法错误,java,syntax-error,Java,Syntax Error,我找不到错误。Eclipse给了我这个错误。每个{}都匹配。请帮助 此行有多个标记-标记“”上出现语法错误;应为 -令牌“”上出现语法错误,应为{ 我的代码如下: import javax.swing.*; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFileChooser; i

我找不到错误。Eclipse给了我这个错误。每个{}都匹配。请帮助

此行有多个标记-标记“”上出现语法错误;应为 -令牌“”上出现语法错误,应为{

我的代码如下:

import javax.swing.*;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTextField;

import matlabcontrol.MatlabConnectionException;
import matlabcontrol.MatlabInvocationException;

import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

class BackgroundImageJFrame1 extends JFrame {

public BackgroundImageJFrame1() {

    JButton b1;
    JLabel l1;
    final JFileChooser fc = null;
    final JTextField textField;
    final JButton jb1 = null;
    setTitle("Parallel Session");
    setSize(400, 400);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);

    getContentPane().setLayout(new BorderLayout());
    setContentPane(new JLabel(new ImageIcon("giphy.gif")));
    getContentPane().setLayout(new FlowLayout());

    l1 = new JLabel("Parallel Simulation Model");
    l1.setForeground(Color.RED);
    l1.setFont(new Font("Palatino Linotype", Font.BOLD, 20));
    l1.setToolTipText("Getting Started");
    l1.setBounds(86, 54, 219, 45);

    b1 = new JButton("\n\n LET'S GO!");
    b1.setVerticalAlignment(SwingConstants.BOTTOM);
    b1.setFont(new Font("Microsoft Sans Serif", Font.PLAIN, 14));
    b1.setForeground(Color.BLUE);
    b1.setBackground(Color.YELLOW);
    b1.setToolTipText("To begin click here!");
    b1.setBounds(120, 210, 272, 186);

    JProgressBar progressBar = new JProgressBar();
    progressBar.setIndeterminate(true);
    progressBar.setToolTipText("Progress");
    progressBar.setBounds(130, 207, 146, 14);

    getContentPane().add(l1);
    getContentPane().add(b1);
    getContentPane().add(progressBar);
    // Just for refresh :) Not optional!
    setSize(399, 399);
    setSize(400, 400);

    b1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JFrame Frame1 = new JFrame();
            final JPanel panel1 = new JPanel();

            JLabel j1 = new JLabel("Select your model");
            panel1.add(j1);
            JTextField jt1 = new JTextField();
            jt1.setPreferredSize(new Dimension(160, 20));
            panel1.add(jt1);
            new JButton("Browse");
            jb1.setPreferredSize(new Dimension(100, 20));
            panel1.add(jb1);

            JLabel label1 = new JLabel("Enter the number instances");
            Frame1.setVisible(true);
            Frame1.setSize(300, 300);
            Frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            panel1.add(label1);
            Frame1.getContentPane().add(panel1);
            panel1.setBackground(Color.CYAN);

            final JTextArea t1 = new JTextArea("Enter here");
            panel1.add(t1);

            JButton b11 = new JButton("SET");
            panel1.add(b11);

            jb1.addActionListener(new java.awt.event.ActionListener() {
                @Override
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnBrowseActionPerformed(null);
                }

            });
            private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {
                if (fc == null) {
                    fc = new JFileChooser(".");
                }

                // Show it.
                int returnVal = fc.showOpenDialog(null);

                // Process the results.
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    textField.setText(fc.getSelectedFile().getPath());
                } else {
                    textField.setText("");
                }

                // Reset the file chooser for the next time it's shown.
                fc.setSelectedFile(null);

            }


             //done
                b11.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                    String a = t1.getText();
                    System.out.println(" " + a);
                    try {
                        int itr = Integer.parseInt(a);
                        for (int i = 1; i <= itr; i++) {
                            multi m = new multi();

                            JLabel l1 = new JLabel("MANUEVER DETAILS");
                            JTextArea p = new JTextArea(
                                    "Enter the manuever here");
                            panel1.add(l1);
                            panel1.add(p);
                        }
                    } catch (InvocationTargetException
                            | InterruptedException
                            | MatlabConnectionException
                            | MatlabInvocationException e) {
                        // TODO Auto-generated catch block
                        ((Throwable) e).printStackTrace();
                    }

                }
            });

        }
    });
}

public static void main(String[] args) throws MatlabConnectionException,
        MatlabInvocationException, IOException {

    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                System.out.println("hey");

                new BackgroundImageJFrame1();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    });

}


}

方法中有方法,将BTNBrowsreactionExecuted方法置于BackgroundImageJFrame1外部

方法中有方法,将BTNBrowsreactionExecuted方法置于BackgroundImageJFrame1外部

无法在方法内部声明方法

jb1.addActionListener(new java.awt.event.ActionListener() {
在BackgroundImageJFrame1构造函数外部取出BTNBrowsreactionPerformed方法

此代码是在方法内部编写的

jb1.addActionListener(new java.awt.event.ActionListener() {
这是一种新方法,不应该在任何方法中

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

注意:@Ranjeet提到,您需要在构造函数外部对级别变量进行分类,您可以在构造函数内部进行初始化。

您不能在方法内部声明方法

jb1.addActionListener(new java.awt.event.ActionListener() {
在BackgroundImageJFrame1构造函数外部取出BTNBrowsreactionPerformed方法

此代码是在方法内部编写的

jb1.addActionListener(new java.awt.event.ActionListener() {
这是一种新方法,不应该在任何方法中

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

注意:@Ranjeet提到,您需要在构造函数外部对级别变量进行分类,您可以在构造函数内部进行初始化。

在发布的代码中,匿名类定义在使用符号的actionPerformed方法之后结束}

btnbrowsreactionperformed方法是同一类的私有方法,类定义应该包括该方法。基本上,关闭匿名类的};应该在btnbrowsreactionperformed定义之后

jb1.addActionListener(new java.awt.event.ActionListener() {
                @Override
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnBrowseActionPerformed(null);
                }

            // do not close the anonymous inner class here
            //the below method belongs to the anonymous class.
            private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {
                if (fc == null) {
                    fc = new JFileChooser(".");
                }

                // Show it.
                int returnVal = fc.showOpenDialog(null);

                // Process the results.
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    textField.setText(fc.getSelectedFile().getPath());
                } else {
                    textField.setText("");
                }

                // Reset the file chooser for the next time it's shown.
                fc.setSelectedFile(null);

            }
            });//close it here instead 

在发布的代码中,匿名类定义在使用符号}的actionPerformed方法之后结束

btnbrowsreactionperformed方法是同一类的私有方法,类定义应该包括该方法。基本上,关闭匿名类的};应该在btnbrowsreactionperformed定义之后

jb1.addActionListener(new java.awt.event.ActionListener() {
                @Override
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnBrowseActionPerformed(null);
                }

            // do not close the anonymous inner class here
            //the below method belongs to the anonymous class.
            private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {
                if (fc == null) {
                    fc = new JFileChooser(".");
                }

                // Show it.
                int returnVal = fc.showOpenDialog(null);

                // Process the results.
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    textField.setText(fc.getSelectedFile().getPath());
                } else {
                    textField.setText("");
                }

                // Reset the file chooser for the next time it's shown.
                fc.setSelectedFile(null);

            }
            });//close it here instead 
您需要在构造函数外部编写BTNBrowsreactionPerformed方法的实现。 在类级别而不是构造函数中声明final JFileChooser fc=null;final JTextField textField。 它可以解决编译错误问题。 您需要在构造函数外部编写BTNBrowsreactionPerformed方法的实现。 在类级别而不是构造函数中声明final JFileChooser fc=null;final JTextField textField。 它可以解决编译错误问题。
您将在private void btnbrowsreactionperformedjava.awt.event.ActionEvent evt行中获得错误所在的行号{b1方法的actionperformed没有右括号,然后声明了btnbrowseactioinperformed。这就是冲突。您将在private void BTNBrowseActioPerformedJava.awt.event.ActionEvent evt行中获取错误所在的行号{为b1方法执行的操作没有结束括号,然后声明BTNBrowsreactioinperformed。这就是冲突。这个答案可能是正确的,也可能是不正确的,很难说您实际建议的内容需要更改。我在评论中提到了这一点。但是,是的,我会澄清。在发布的代码中,匿名者us类定义在使用符号}的actionPerformed方法之后结束;BTNBrowsreactionPerformed方法是同一类的私有方法,类定义应该包括该方法;关闭匿名类的步骤应在BTNBrowsreactionPerformed定义之后。请将此说明添加到您的答案中。此答案可能正确,也可能不正确,很难判断您实际建议的内容是否需要更改。我在评论中提到了这一点。但我会澄清。在发布的代码中匿名类定义在使用符号}的actionPerformed方法之后结束;BTNBrowsreactionPerformed方法是同一类的私有方法,类定义应该包括该方法。基本上,};关闭匿名类的步骤应在BTNBrowsreactionPerformed定义之后。请将此说明添加到您的答案中。如果有帮助,您可以回答。@NidhiVerma,请查看我答案中的注释。如果有帮助,您可以回答。@NidhiVerma,请查看我答案中的注释。