gpt4 book ai didi

Java 编程,JFrame 问题

转载 作者:行者123 更新时间:2023-12-01 22:30:05 25 4
gpt4 key购买 nike

我正在尝试使用各种不同的 JPanel 制作一个界面,但是由于某种原因,我收到了这个错误。错误位于代码底部。这是将我的框架设置为可见。

public class GUIExampleApp extends JFrame  implements ActionListener {
JLabel Title, Description;
JButton Start, Help, Quit;
TextField Limiting;
JPanel panelContainer = new JPanel (true);
JPanel StartApplication = new JPanel (true);
JPanel StartingApplication = new JPanel (true);

CardLayout card = new CardLayout();

public GUIExampleApp() { // constructing the window
super("GUIExampleApp");
panelContainer.setLayout(card);
panelContainer.add(StartApplication, "1");
panelContainer.add(StartingApplication, "2");
card.show(panelContainer, "now");

// Set the frame's name
// get the container frame

// Create labels, text boxes and buttons
Title = new JLabel("INTERFACE");
Description = new JLabel("Knowledge grows everyday");

MainMenuApplicationDesc= new JLabel("Pick Which Unit you want to study");
Title.setBackground(Color.red);
Title.setForeground(Color.blue);
StartingApplication.setBackground(Color.red);
Description.setBackground(Color.red);
Description.setForeground(Color.blue);
Start = new JButton("Start");
Help = new JButton("Help");
Quit = new JButton("Quit");

// make the buttons listen to clicks on this application
Start.addActionListener(this);
Help.addActionListener(this);
Quit.addActionListener(this);

setSize(600, 600); // Set the frame's size
Start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
card.show(panelContainer, "2");
}
});

Back.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
card.show(panelContainer, "1");
}
});

Quit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0){
System.exit (1);
}
});
}

// ERRORS ARE HERE, "Syntax Error"
frame.setVisible(true);
frame.pack();

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new GUIExampleApp();
} // Create a GUIExampleApp frame
});
} // main method
}

最佳答案

您没有声明框架对象,您的类扩展了它,因此使用父类(super class)的方法。

setVisible(true);
pack();

关于Java 编程,JFrame 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27992684/

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