0
votes
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 Answers

1
votes
  1. Right click on your Project in the project explorer
  2. Click on properties
  3. Click on Run
  4. Make sure your Main Class is the one you want to be the entry point. (Make sure to use the fully qualified name i.e. mypackage.MyClass)
  5. Click OK.
  6. Clean an build your project
  7. Run Project :)

If you just want to run the file, right click on the class from the package explorer, and click Run File, or (Alt + R, F), or (Shift + F6)