我已经数过了花括号,无法弄清楚为什么类体不完整。每次我试图修复班级时,都会把整个班级搞得一团糟。问题是代码中的最后一个类。最后一个花括号是给我上课带来麻烦的花括号。我正在使用 Eclipse 来编写它。
这是整个程序的代码:
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Stocks {
public static void main(String [] args) {
JFrame frame = new JFrame ("Java Stocks");
frame.setSize(700,700);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel (new GridBagLayout());
frame.add(panel);
frame.getContentPane().add(panel, BorderLayout.WEST);
GridBagConstraints c = new GridBagConstraints ();
JButton button1 = new JButton("Profile");
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(40, 40, 40, 40);
panel.add(button1, c);
button1.addActionListener(new Action());
}
static class Action implements ActionListener {
public void actionPerformed (ActionEvent e) {
JFrame frame2 = new JFrame("Your Stocks");
frame2.setVisible(true);
frame2.setSize(600,600);
JLabel label = new JLabel("Your Personal Stocks");
JPanel panel = new JPanel();
frame2.add(panel);
panel.add(label);
}
public static void main(String [] args) {
GridBagConstraints c = new GridBagConstraints ();
JButton button2 = new JButton("Market");
c.gridx = 0;
c.gridy = 1;
c.insets = new Insets(40, 40, 40, 40);
button2.addActionListener(new Action());
}
static class Action2 implements ActionListener {
public void actionPerformed (ActionEvent e) {
JFrame frame2 = new JFrame("Your Stocks");
frame2.setVisible(true);
frame2.setSize(600,600);
JLabel label = new JLabel("Your Personal Stocks");
JPanel panel = new JPanel();
frame2.add(panel);
panel.add(label);
}
public static void main(String [] args) {
GridBagConstraints c = new GridBagConstraints ();
JButton button3 = new JButton("Users");
c.gridx = 0;
c.gridy = 2;
c.insets = new Insets(40, 40, 40, 40);
button3.addActionListener(new Action());
}
static class Action3 implements ActionListener {
public void actionPerformed (ActionEvent e) {
JFrame frame2 = new JFrame("Your Stocks");
frame2.setVisible(true);
frame2.setSize(600,600);
JLabel label = new JLabel("Your Personal Stocks");
JPanel panel = new JPanel();
frame2.add(panel);
panel.add(label);
}
public static void main(String [] args) {
GridBagConstraints c = new GridBagConstraints ();
JButton button4 = new JButton("Notes");
c.gridx = 0;
c.gridy = 3;
c.insets = new Insets(40, 40, 40, 40);
button4.addActionListener(new Action());
}
static class Action4 implements ActionListener {
public void actionPerformed (ActionEvent e) {
JFrame frame2 = new JFrame("Your Stocks");
frame2.setVisible(true);
frame2.setSize(600,600);
JLabel label = new JLabel("Your Personal Stocks");
JPanel panel = new JPanel();
frame2.add(panel);
panel.add(label);
}
public static void main(String [] args) {
GridBagConstraints c = new GridBagConstraints ();
JButton button5 = new JButton("Information");
c.gridx = 0;
c.gridy = 4;
c.insets = new Insets(40, 40, 40, 40);
button5.addActionListener(new Action());
}
static class Action5 implements ActionListener {
public void actionPerformed (ActionEvent e) {
JFrame frame2 = new JFrame("Your Stocks");
frame2.setVisible(true);
frame2.setSize(600,600);
JLabel label = new JLabel("Your Personal Stocks");
JPanel panel = new JPanel();
frame2.add(panel);
panel.add(label);
}