首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Java编程,JFrame问题

Java编程,JFrame问题
EN

Stack Overflow用户
提问于 2015-01-17 05:02:26
回答 2查看 66关注 0票数 0

我正在尝试用各种不同的JPanels做一个接口,但是由于某些原因,我得到了这个错误。错误位于代码的底部。它将我的框架设置为可见。

代码语言:javascript
运行
复制
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
}
EN

回答 2

Stack Overflow用户

发布于 2015-01-17 05:12:25

你没有声明frame对象,你的类扩展了它,所以使用超类的方法。

代码语言:javascript
运行
复制
setVisible(true);
pack();
票数 3
EN

Stack Overflow用户

发布于 2015-01-17 05:08:12

有几件事。第一,变量frame是在哪里声明的?看看你的作用域,这些行在任何方法之外。这就是语法错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27992684

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档