Java 错误:表达式1的开始非法错误

Java 错误:表达式1的开始非法错误,java,swing,user-interface,import,Java,Swing,User Interface,Import,这是我创建复合计算器的代码,但我有一个问题,它是表达式的非法开始。请帮助我完成我的项目。下面是代码中导致问题的部分修复。下次包含完整的错误代码,并尝试只显示代码的相关部分 import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionLis

这是我创建复合计算器的代码,但我有一个问题,它是表达式的非法开始。请帮助我完成我的项目。

下面是代码中导致问题的部分修复。下次包含完整的错误代码,并尝试只显示代码的相关部分

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;    
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.lang.*;
import java.util.*;
public class Life {
public static void main (String[] args){  
  JFrame frame = new JFrame("Interest Calculator");
  frame.setVisible(true);
  frame.setSize(300,100);
  frame.setBackground(Color.magenta);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  JPanel panel = new JPanel();
  frame.add(panel);


  JButton button = new JButton("Simple Interest");
  panel.add(button);
  button.addActionListener (new Action1());

  JButton button2 = new JButton("Compound Interest");
  panel.add(button2);
  button2.addActionListener (new Action2()); 
}
static class Action1 implements ActionListener {        
      public void actionPerformed (ActionEvent e) {     
    JFrame frame2 = new JFrame("Simple");
    frame2.setVisible(true);
    frame2.setSize(300,100);
    JPanel panel = new JPanel();
    frame2.add(panel);

    JButton button = new JButton("Ordinary"); 
        panel.add(button); 
    button.addActionListener (new Ordinary());


  JButton button2 = new JButton("Exact");
  panel.add(button2);     
  button2.addActionListener (new Exact());       
  }
}   
static class Action2 implements ActionListener {        
  public void actionPerformed (ActionEvent e) {     
    JFrame frame3 = new JFrame("Compound Interest");
    frame3.setVisible(true);
    frame3.setSize(300,100);

  JPanel panel = new JPanel();
  frame3.add(panel);

  JButton button = new JButton("Compounded");
  panel.add(button);

  JButton button2 = new JButton("Continously");
  panel.add(button2);
  }  
}
    static class Ordinary implements ActionListener {
    public void actionPerformed (ActionEvent e) { 
    JFrame frame4 = new JFrame("Simple");
    frame4.setVisible(true);
    frame4.setSize(300,100);

   JPanel panel = new JPanel();
   frame4.add(panel);

       JButton button = new JButton("Approximate");
  panel.add(button);
  button.addActionListener (new Approximate());

  JButton button2 = new JButton("Actual");
  panel.add(button2);
}   
}
static class Exact implements ActionListener {
public void actionPerformed (ActionEvent e) { 
JFrame frame5 = new JFrame("Exact");
frame5.setVisible(true);
frame5.setSize(300,100);

   JPanel panel = new JPanel();
  frame5.add(panel);

   JButton button = new JButton("Approximate");
  panel.add(button);



  JButton button2 = new JButton("Actual");
  panel.add(button2);
}   
}
static class Approximate implements ActionListener {
public void actionPerformed (ActionEvent e) {

JFrame frame6 = new JFrame("Simple");
frame6.setVisible(true);
frame6.setSize(300,100);
JPanel panel = new JPanel();
   frame6.add(panel);
   frame6.setVisible(true);
frame6.setSize(300,300);
frame6.setLayout(null);
frame6.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField P = new JTextField();
panel.add(P);
P.setText("Enter Principal");
JTextField r = new JTextField();
panel.add(r);
r.setText("Enter Rate");
JTextField t = new JTextField();
panel.add(t);
t.setText("Enter Year");
JButton button = new JButton("Calculate");
panel.add(button);
button.addActionListener (new button());
 static class button implements ActionListener {
    public void actionPerformed (ActionEvent e) {

float P,r,t,result ;
P = Float.parseFloat(P.getText());
r = Float.parseFloat(r.getText());
t = Float.parseFloat(t.getText());
result = P*r/100*t/360;
button.setText(String.valueof(result));
}
}
}
}
}

你为什么发“zzzzz”?他在键盘上睡着了;)如果我在校对这样一个写得不好的问题,我也会睡着的。在发布问题时,不要用垃圾来克服SO强加的限制。这样做的目的是发布高质量的问题,而不是转储垃圾数据。我以为这是在乞求,但在开始时,
pl
缺失,所以它将是plzzzzzz
ActionListener listener = new ActionListener() {
    public void actionPerformed (ActionEvent e) {
        float P,r,t,result ;
        //P = Float.parseFloat(P.getText()); // P makes no sens here - its float !!! and uninitialized
        //r = Float.parseFloat(r.getText()); // same for r
        //t = Float.parseFloat(t.getText()); // same for t
        result = P*r/100*t/360;
        button.setText(String.valueOf(result));
    }
};
button.addActionListener (listener);