A whole bunch of JButtons Please review this code.

  import java.awt.*;

 import javax.swing.*;
 public class Snake_Ladder  {
public static void main(String[] args) {
new Snake_Ladder();
}

public Snake_Ladder(){
int i;
JFrame frame = new JFrame();
JPanel pane = new JPanel();
GridLayout experimentLayout = new GridLayout(11,0);
        pane.setLayout(experimentLayout);
        for(i=100;i&gt;=91;i--){
        pane.add(new JButton(" " +i));
        }
        for(i=81;i&lt;=90;i++){
        pane.add(new JButton(" " +i));
       }
        for(i=80;i&gt;=71;i--){
        pane.add(new JButton(" " +i));
        }
        for(i=61;i&lt;=70;i++){
        pane.add(new JButton(" " +i));
        }
        for(i=60;i&gt;=51;i--){
        pane.add(new JButton(" " +i));
        }
        for(i=41;i&lt;=50;i++){
        pane.add(new JButton(" " +i));
        }
        for(i=40;i&gt;=31;i--){
        pane.add(new JButton(" " +i));
        }
        for(i=21;i&lt;=30;i++){
        pane.add(new JButton(" " +i));
        }
        for(i=20;i&gt;=11;i--){
        pane.add(new JButton(" " +i));
        }
        for(i=1;i&lt;=10;i++){
        pane.add(new JButton(" " +i));
        }
frame.add(pane);
frame.setSize(1200,1400);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

}

 }
Unfortunately your question about "How to..." is off-topic for this site but I feel that your code really needs to be reviewed as there are some things that can be improved.


Don't import .* Only use the imports that you need. If you need to import JButton, import JButton, don't import all other classes within the same package.
Fix your indentation and spacing for (i = 100; i &gt;= 91; i--) { is a lot more readable than what you currently have.


Also, use an extra indentation step (one tab / four spaces) after each { and go back one indentation step after each }. Applying this, your code will look like:

for (i = 61; i &lt;= 70; i++) {
    pane.add(new JButton(" " + i));
}


To make your IDE do the indentation for you:


If you are using Eclipse, select all your code and press either Ctrl + I or Ctrl + Alt + F.
If you are using Netbeans, select all your code and press Alt + Shift + F


Update, your for-loop can be written as only one loop (even though it's quite many variables and this code possibly needs it's own review...)

int COUNT = 100;
int last10s = 0;
for (int i = 0; i &lt; COUNT; i++) {
    int decreasing = COUNT - i;
    int even10 = i / 10;
    if (decreasing % 10 == 0)
        last10s = decreasing;
    boolean shouldDecrease = even10 % 2 == 0;
    int increasing = last10s - 9 + i % 10;
    int chosen = shouldDecrease ? decreasing : increasing;
    pane.add(new JButton(" " + chosen));
}