Jump to content

What would I need to code in Main to run this Grid Layout example?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
pathtotake

pathtotake

    Newbie

  • Members
  • PipPip
  • 13 posts
here the code that was given as example but might have been given in the hope that we would be able to figure out how to run it by coding our own main, but I have been trying for hours:

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

public class GridLayoutExample extends JApplet
{
    private JButton[] myButton;
@Override
    public void init()
    {
        getContentPane().setLayout(new GridLayout(4, 3));
        getContentPane().setBackground(new Color(171, 205, 239));
        myButton = new JButton[10];
        for (int i = 0; i < myButton.length; i++)
        {
            myButton[i] = new JButton("Button " + (i + 1));
            getContentPane().add(myButton[i]);
        }

    }
EDIT: just need to know how to run the above code with a main method is all.
Also, @override isnt meant to be there (or wasnt there in the example), i just added it to see what happened.

EDIT2: Ive got this to run without Main. For some reason when I press the run button in netbeans it doesnt run but when i right click the file and click run file then it runs. Wont run in cmd either.

Edited by pathtotake, 29 March 2010 - 03:38 PM.


#2
Deadlock

Deadlock

    Learning Programmer

  • Members
  • PipPipPip
  • 81 posts
It's an applet, so you can run it with appletviewer command. But why don't you use your netbeans to run it? or even eclipse? why would you ever need cmd to run it if It will never run on desktops (It's an applet)