Java Eclipse发现以前不存在的语法错误

Java Eclipse发现以前不存在的语法错误,java,eclipse,swing,syntax-error,Java,Eclipse,Swing,Syntax Error,我在这个项目上断断续续地工作了很长时间,离开一个月后才回来工作。上次我做这件事的时候,一切都很顺利,我正在清理东西准备完成。今天,当我打开eclipse时,出现了许多没有解决方案的错误,其中大多数与括号有关,但有一些与actionPerformed方法有关。我指出了错误所在的行(如果有帮助的话)。只是想知道是否有人能告诉我eclipse是否存在真正的错误或有什么问题 import java.awt.*; import java.awt.event.ActionEvent; import java

我在这个项目上断断续续地工作了很长时间,离开一个月后才回来工作。上次我做这件事的时候,一切都很顺利,我正在清理东西准备完成。今天,当我打开eclipse时,出现了许多没有解决方案的错误,其中大多数与括号有关,但有一些与actionPerformed方法有关。我指出了错误所在的行(如果有帮助的话)。只是想知道是否有人能告诉我eclipse是否存在真正的错误或有什么问题

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.Random;
import javax.swing.*;

public class main extends JFrame implements ActionListener{
JButton rock;
JButton scissors;
JButton paper;
JLabel left;
ImageIcon rock1;
ImageIcon scissors1;
ImageIcon scissors2;
ImageIcon paper2;
ImageIcon paper1;
ImageIcon rock2;
ImageIcon back;
ImageIcon scissorsb;
ImageIcon youWin;
ImageIcon youLose;
ImageIcon Loading;
JLabel background;
JLabel right;
String [] Rock3 = {};
String [] RPS = {"Rock","Paper","Scissors"};
Random rand = new Random ();
Random Prize = new Random ();
int num = rand.nextInt(RPS.length);
int yourChoice = -1;
JLabel winner;
Container contentPane = this.getContentPane();
SpringLayout layout = new SpringLayout();
String Tie = "Tie";
String compwins = "Computer wins!";
String youwin = "You win!";
Font winnerFont = new Font("Font", Font.PLAIN, 35);
int yourScore = 0;
int compScore = 0;
String yourNum = Integer.toString(yourScore);
String compNum = Integer.toString(compScore);
JLabel yourPoints = new JLabel();
JLabel compPoints;
private Timer t;
private Timer t2;
private Timer t3;

public  main (){
    super("Rock Paper Scissors");
    back = new ImageIcon("space-wallpaper-space-32897775-1920-1080.jpg");
    youWin = new ImageIcon("you win.png");
    youLose = new ImageIcon("you lose.png");
    paper1 = new ImageIcon("paper1.png");
    paper2 = new ImageIcon("paper2.png");
    scissors1 = new ImageIcon("scissors1.png");
    scissors2 = new ImageIcon("scissors2.png");
    rock1 = new ImageIcon("rock1.png");
    rock2 = new ImageIcon("rock2.png");
    Loading = new ImageIcon("loadingbig.png");

    background = new JLabel();
    left = new JLabel();
    right = new JLabel();
    winner = new JLabel();
    compPoints = new JLabel();
    yourPoints = new JLabel();
    right.setVisible(true);
    this.setVisible(true);
    this.setSize(1920,1080);
    winner.setFont(winnerFont);
    winner.setHorizontalAlignment( SwingConstants.CENTER );

    contentPane.add(compPoints);
    contentPane.add(yourPoints);


        contentPane.setLayout(layout);

        contentPane.add(winner);

        contentPane.add(left);
        contentPane.add(right);



 rock = new JButton("Rock");
 paper = new JButton ("Paper");
 scissors = new JButton ("Scissors");

layout.putConstraint(SpringLayout.WEST, rock,
        500,
        SpringLayout.WEST, contentPane);
this.add(rock, BorderLayout.NORTH);
layout.putConstraint(SpringLayout.SOUTH, rock,
        -30,
        SpringLayout.SOUTH, contentPane);
layout.putConstraint(SpringLayout.WEST, rock,
        40,
        SpringLayout.NORTH, contentPane);
this.add(paper, BorderLayout.NORTH);
layout.putConstraint(SpringLayout.SOUTH, paper,
        -30,
        SpringLayout.SOUTH, contentPane);
layout.putConstraint(SpringLayout.WEST, paper,
        200,
        SpringLayout.NORTH, contentPane);
this.add(scissors, BorderLayout.NORTH);
layout.putConstraint(SpringLayout.SOUTH, scissors,
        -30,
        SpringLayout.SOUTH, contentPane);
layout.putConstraint(SpringLayout.WEST, scissors,
        360,
        SpringLayout.NORTH, contentPane);
rock.setBackground(Color.GRAY);
rock.setPreferredSize(new Dimension(140,50));
paper.setBackground(Color.WHITE);
paper.setPreferredSize(new Dimension(140,50));
scissors.setBackground(Color.LIGHT_GRAY);
scissors.setPreferredSize(new Dimension(140,50));
rock.repaint();
scissors.repaint();
paper.repaint();
Background();


}


public static void main(String args[]){
main framer = new main();
}
@Override
/*Error Here*/public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub


    if(arg0.getSource() ==rock){
        left.setIcon(rock1);
        yourChoice = 0;
    }else if(arg0.getSource() ==paper){
        left.setIcon(paper1);
        yourChoice = 1;
    }else if(arg0.getSource() ==scissors){
        left.setIcon(scissors1);
        yourChoice = 2;
    }

    computerMove();


        Score();
        winner();
}
public void Background(){
rock.setVisible(false);
scissors.setVisible(false);
paper.setVisible(false);
contentPane.add(background);
background.setIcon(Loading);
t = new Timer(4000, new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
        background.setIcon(back);
        rock.setVisible(true);
        scissors.setVisible(true);
        paper.setVisible(true);
    }
});
t.setRepeats(false);
t.start();
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
rock.doClick();
paper.doClick();
scissors.doClick();
rock.addActionListener(this);
paper.addActionListener(this);
scissors.addActionListener(this);
}
public void Score(){

yourPoints.setFont(winnerFont);
compPoints.setFont(winnerFont);

layout.putConstraint(SpringLayout.WEST, yourPoints,
        100,
        SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, yourPoints,
        800,
        SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.WEST, compPoints,
        1790,
        SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, compPoints,
        800,
        SpringLayout.NORTH, contentPane);



if ((num==0 && yourChoice ==0)||(num==2 && yourChoice ==2)||(num==1 && yourChoice   ==1)){
    layout.putConstraint(SpringLayout.NORTH, winner,
            50,
            SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.WEST, winner,
            890,
            SpringLayout.WEST, contentPane);
    winner.setText(Tie);
    winner.repaint();
    t = new Timer(1400, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            winner.setText(null);
        }   
    });
    t.setRepeats(false);
    t.start();
}else if((num==0 && yourChoice ==2)||(num==2 && yourChoice ==1)||(num==1 && yourChoice   ==0)){
    compScore ++;
    compPoints.setText(compNum);
    layout.putConstraint(SpringLayout.NORTH, winner,
            50,
            SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.WEST, winner,
            810,
            SpringLayout.WEST, contentPane);
    winner.setText(compwins);
    winner.repaint();
    compPoints.repaint();
    /*Error Here*/t2 = new Timer(1400, new ActionListener() {

        @Override
        /*Error Here*/public void actionPerformed(ActionEvent e) {
            winner.setText(null);
            /*Error Here*/} 
        /*Error Here*/});
    t2.setRepeats(false);
    t2.start();
    /*Error Here*/}else if((num==2 && yourChoice ==0)||(num==0 && yourChoice ==1)||(num==1            && yourChoice ==2)){
    yourScore ++;
    yourPoints.setText(yourNum);
    layout.putConstraint(SpringLayout.NORTH, winner,
            50,
            SpringLayout.NORTH, contentPane);
    layout.putConstraint(SpringLayout.WEST, winner,
            850,
            SpringLayout.WEST, contentPane);
    winner.setText(youwin);
    winner.repaint();
    yourPoints.repaint();
    t3 = new Timer(1400, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            winner.setText(null);
        }
    });
    t3.setRepeats(false);
    /*Error Here*/t3.start();


    /*Error Here*/}
yourNum = Integer.toString(yourScore);
compNum = Integer.toString(compScore);
yourPoints.setText(yourNum);
compPoints.setText(compNum);
winner.repaint();
yourPoints.repaint();
compPoints.repaint();
winner.setForeground(Color.RED);
yourPoints.setForeground(Color.RED);
compPoints.setForeground(Color.RED);




/*Error Here*/}

public void winner(){
if(yourScore == 10){
    background.setIcon(youWin);
    contentPane.add(background);
    background.repaint();
    left.setVisible(false);
    right.setVisible(false);
    yourPoints.setVisible(false);
    compPoints.setVisible(false);
    winner.setVisible(false);
    rock.setVisible(false);
    paper.setVisible(false);
    scissors.setVisible(false);
    t = new Timer(3000, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            computerMove();
            Score();
            winner();
        }   
    });
    t.setRepeats(false);
    t.start();

}else if(compScore == 10){
background.setIcon(youLose);
contentPane.add(background);
background.repaint();
left.setVisible(false);
right.setVisible(false);
yourPoints.setVisible(false);
compPoints.setVisible(false);
winner.setVisible(false);
rock.setVisible(false);
paper.setVisible(false);
scissors.setVisible(false);
/*Error Here*/t = new Timer(3000, new ActionListener() {

    @Override
    /*Error Here*/public void actionPerformed(ActionEvent e) {

        computerMove();
        Score();
        winner();
    }   
    /*Error Here*/});
t.setRepeats(false);
t.start();
}
}
public void computerMove(){
 num = rand.nextInt(RPS.length);
if (num==0){
    right.setIcon(rock2);
}else if(num==1){
    right.setIcon(paper2);
}else if(num==2){
    right.setIcon(scissors2);
}


/*Error Here*/}

每当您在eclipse中遇到奇怪的问题时,请尝试执行以下操作:

  • 清理项目<代码>项目-->
    清洁…
  • 关闭项目,然后重新打开它<代码>项目-->
    打开项目
    /
    关闭项目
  • 复制源文件并删除原始文件,然后再次粘贴源文件

您缺少
computerMove
的右括号


在解决此类问题时,请尝试注释方法,直到得到可编译的内容,然后取消注释小代码块,直到找到有问题的代码块。

看起来您缺少文件末尾的右括号
}


非常糟糕的缩进和命名让人很难注意到。看看。

您是否再次尝试干净地构建项目?从重复的方法定义开始有很多错误。天哪!我以前也遇到过这种情况,我刚刚刷新了项目。如果不起作用,也尝试退出eclipse。上面建议的干净构建也会有所帮助。将类命名为“main”是一个非常糟糕的主意。至少用大写字母M来表示Main。你的public Main()一开始确实让我感到困惑。谢谢大家,我会试试这些东西,然后再打给你。我会试试,然后告诉你发生了什么。哇,我怎么会错过这个,我觉得自己像个白痴。至于格式,这是我的第一个项目,我现在懒得修复它。@TheFloatingLlama:Ctrl+Shift+F或右键单击:Source->Format。或者Ctrl+A,那么Ctrl+I(源->正确缩进)不应该花费那么多精力;-)