有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

netbeans为什么这个java代码显示错误?

package mygridLayout;
import java.awt.*;
import javax.swing.*;
public class MyGridLayout
{
    JFrame f;
    MyGridLayout()
            {
                f = new JFrame();

                JButton b1 = new JButton("1");
                JButton b2 = new JButton("2");
                JButton b3 = new JButton("3");
                JButton b4 = new JButton("4");
                JButton b5 = new JButton("5");
                JButton b6 = new JButton("6");
                JButton b7 = new JButton("7");
                JButton b8 = new JButton("8");
                JButton b9 = new JButton("9");

                f.add(b1);
                f.add(b2);
                f.add(b3);
                f.add(b4);
                f.add(b5);
                f.add(b6);
                f.add(b7);
                f.add(b8);
                f.add(b9);

                f.setLayout(new GridLayout(3,3));

                f.setSize(300,300);
                f.setVisible(true);
            }
    public static void main(String[] args)
    {
        new MyGridLayout();
    }
}

Error: Could not find or load main class mygridlayout.MyGridLayout C:\Users\Home\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds)


共 (1) 个答案

  1. # 1 楼答案

    1. 在项目浏览器中右键单击项目
    2. 点击属性
    3. 点击Run
    4. 确保你的主课是你想要的入门课。(确保使用完全限定的名称,即mypackage.MyClass)
    5. 点击OK
    6. 清理并构建你的项目
    7. 运行项目:)

    如果您只想运行该文件,请在包资源管理器中右键单击该类,然后单击运行文件,或(Alt+RF),或(Shift+F6