gpt4 book ai didi

java - 无法完成类(class)主体

转载 作者:行者123 更新时间:2023-12-01 23:30:59 28 4
gpt4 key购买 nike

我已经计算了花括号的数量,但无法弄清楚为什么类主体不完整。每次我试图修复类(class)时,都会把整个类(class)弄乱。问题出在代码中的最后一个类。最后一个花括号给我带来了类里面的麻烦。我正在使用 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);
}

最佳答案

由于令人困惑的缩进,您将嵌套类嵌套在彼此内部并不明显。 Action5 嵌套在 Action4 中,而 Action4 又嵌套在 Action3 中,而 Action3 又嵌套在 Action2 中,而 Action2 又嵌套在Action,嵌套在Stocks中。

要么在文件的最后放置 5 个大括号,以关闭所有类,或者更好的是,将它们全部直接嵌套在 Stocks 中,而不是相互嵌套。

关于java - 无法完成类(class)主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19300538/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com