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.


Sign In
Create Account


Back to top









