All pastes #229506 Raw Edit

Unnamed

public text v1 · immutable
#229506 ·published 2006-10-30 19:06 UTC
rendered paste body
package life;

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

public class view {
	
	private static void lifeView(int size) {
		int x,y;
		JFrame life = new JFrame();
		
		JLabel stages = new JLabel("0", SwingConstants.CENTER);
		JSlider slide = new JSlider(JSlider.VERTICAL, 1, 10,1);
		JButton clear = new JButton("Clear");
		JButton step = new JButton("Step");
		JButton run = new JButton("Run");
		JButton stop = new JButton("Stop");
		Box buttons = new Box(BoxLayout.X_AXIS);
		JPanel cells = new JPanel(new GridLayout(size,size));
		
		cell [][] grid = new cell[size][size];
		for(x = 0; x < size;x++){
			for(y = 0; y < size; y++){
				cells.add(grid[x][y]);
			}
		}
		
		
		buttons.add(clear,0);
		buttons.add(step,1);
		buttons.add(run,2);
		buttons.add(stop,3);
		
		
		slide.setMajorTickSpacing(2);
		slide.setMinorTickSpacing(1);
		slide.setPaintTicks(true);
		slide.setPaintLabels(true);
		slide.setBorder(
				BorderFactory.createEmptyBorder(0,0,10,0));
		
		
		life.setSize(400,400);
		Container contentPane = life.getContentPane();
		
		contentPane.add(stages, BorderLayout.NORTH);
		contentPane.add(slide,BorderLayout.EAST);
		contentPane.add(buttons,BorderLayout.SOUTH);
		contentPane.add(cells, BorderLayout.WEST);
	
		
		life.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		life.setVisible(true);
		
			
	}
	
	public static void main(final String [] args){
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				if (args.length > 0){
					try {
						
					lifeView(Integer.parseInt(args[0]));
					} catch (NumberFormatException exceptNum) {
						System.err.println("The first parameter should be a number");
						System.exit(0);
					}
				}
				else{
					lifeView(40);}
				
				}
			
		});
	}
	
}