首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >即使main()存在,也没有main()

即使main()存在,也没有main()
EN

Stack Overflow用户
提问于 2014-02-23 22:31:09
回答 4查看 77关注 0票数 0

我将这段代码添加到Netbeans中,我得到的文件test1不包含main()函数。

我添加了main()函数,但仍然得到了以下错误:

代码语言:javascript
运行
复制
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;

import net.miginfocom.swing.MigLayout;

public class test1 extends JFrame {

    // Window Vars //
    String title;
    int width;
    int height;

    // Mid Level componets //
    JMenuBar menuBar;
    JMenu file;
    JToolBar toolBar;
    JPanel map;
    JPanel sideBar;

    // Low Level componets //
    JMenuItem exit;

    JButton select;

    public test1(String title, int width, int height) {
        this.title = title;
        this.width = width;
        this.height = height;
        this.makeInterface();
    }

    public void makeInterface() {
        // Setup JFrame
        this.setTitle(title);
        this.setSize(width, height);
        this.setLocationRelativeTo(null);
        this.setMinimumSize(new Dimension(700, 500));
        this.setVisible(true);

        this.setLayout(new MigLayout(
                "debug, fillx, gap unrel rel",  // Layout
                "[grow, fill][fill]",         // Column
                "[fill][fill]"));       // Row
        this.makeMenu();
        this.addToolBars();
        this.makePanels();
        this.setupActionListeners();
    }

    public void makeMenu() {
        this.menuBar = new JMenuBar();
        this.file = new JMenu("File");
        this.file.setMnemonic(KeyEvent.VK_F);
        this.menuBar.add(file);

        this.exit = new JMenuItem("Exit", KeyEvent.VK_E);
        this.exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.ALT_MASK));
        this.file.add(exit);

        this.setJMenuBar(this.menuBar);
    }

    public void addToolBars() {
        this.toolBar = new JToolBar("Draggable");
        this.addToolBarButtons();
        this.add(toolBar, "span, height 20:35:50, wrap");
    }

    public void addToolBarButtons() {
        this.select = new JButton("Select");
        this.toolBar.add(select);
    }

    public void makePanels() {
        this.map = new JPanel();
        this.sideBar = new JPanel();

        this.add(map, "width 400:600:, flowy, growy");
        this.add(sideBar, "width 250:300:350, flowy, growy");
    }

    public void setupActionListeners() {
        this.exit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
    }
    public static void main(){
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new test1("r",400,400).setVisible(true);
            }
        });
    }
}

,有人能找出问题出在哪里吗?

EN

回答 4

Stack Overflow用户

发布于 2014-02-23 22:32:28

main的正确签名是

代码语言:javascript
运行
复制
public static void main(String[] args)
票数 12
EN

Stack Overflow用户

发布于 2014-02-23 22:32:57

您主要需要作为参数(String[] args)

票数 2
EN

Stack Overflow用户

发布于 2014-02-23 22:45:05

在主function.The的声明中缺少必需的参数,main的正确语法是:

代码语言:javascript
运行
复制
public static void main(String args[])
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21975560

复制
相关文章

相似问题

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