-3

I'm working on a lab for class and it's my first GUI environment. When I try to run the program it asks me "Select a way to run 'Lab 8'" and then two options - Java Applet or Java Application. It doesn't matter which I choose, I then get an error message "Selection does not contain a main type." Do I need to do anything for Eclipse to create GUI programs, like an add-on or something?

This is the only code I have so far. Not sure if that matters. Thanks

import javax.swing.*;
import java.awt.*;

public class TicTacToe extends JFrame{
    private ImageIcon cross = new ImageIcon ("FlowerX.jpg");
    ImageIcon not = new ImageIcon ("Owl.gif");

    public TicTacToe(){
        Container container = getContentPane();
        container.setLayout(new GridLayout(3, 3));


        }

    }
chuff
  • 5,846
  • 1
  • 21
  • 26
Ahviaa
  • 5
  • 3

1 Answers1

2

You need to have a main method in a standalone java program to run. The main method as specidifed below is the starting point for the jvm to execute your program:

public static void main (String args[])

Modify your code like this and try to execute:

import javax.swing.*;
import java.awt.*;

public class TicTacToe extends JFrame{
    private ImageIcon cross = new ImageIcon ("FlowerX.jpg");
    ImageIcon not = new ImageIcon ("Owl.gif");

    public TicTacToe(){
        Container container = getContentPane();
        container.setLayout(new GridLayout(3, 3));

      }

      public static void main(String args[])
      {
          new TicTacToe();
      }

    }

Learn more about main and basic structure of a java application: http://docs.oracle.com/javase/tutorial/getStarted/application/

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136