我是 Java 新手。我想显示一个带有两个按钮的 Jframe。单击每个按钮后,应显示不同的 JOptionPane 消息。但是,我Illegal start of expression在两个static class声明中都遇到了错误。
谁能解释为什么?我试过移动静态类,但仍然是同样的错误。
这是我的代码...
import javax.swing.JOptionPane;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
public class main { 
    public main() { 
    }
    public static void main(String[] args) { 
                    String name = JOptionPane.showInputDialog(null, "What's your name?", "Enter your name", JOptionPane.PLAIN_MESSAGE);
                    System.out.println("\nWelcome, "+ name + ".");  
                    System.out.print(terms);
                    JOptionPane.showMessageDialog(null, "Welcome to SkyWhale, " + name + ".\n" + deets + "\n" + terms , "Welcome, " + name + ".", JOptionPane.PLAIN_MESSAGE);
                    JFrame control = new JFrame("SkyWhale");
                      control.setVisible(true);
                      control.setSize(500,200);
                      control.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      JPanel panel = new JPanel();
                      JButton chatbtn = new JButton("Live Chat");
                      JButton editorbtn = new JButton("Editor");
                      control.add(panel);
                      panel.add(chatbtn);
                      panel.add(editorbtn);
                      chatbtn.addActionListener(goToChat());
                      editorbtn.addActionListener(goToEdit());
                     static class goToEdit implements ActionListener { 
                        public void actionPerformed(ActionEvent e) 
                        {
                            JOptionPane.showMessageDialog(null, "Code goes here...", "Editor", JOptionPane.PLAIN_MESSAGE);
                        }
                      }
                     static class goToChat implements ActionListener { 
                        public void actionPerformed (ActionEvent e) 
                        {
                            JOptionPane.showMessageDialog(null, "Conversation...", "Live Chat", JOptionPane.PLAIN_MESSAGE);
                        }
                      }
                    }
                }   
        }