package ballWorlds.framework; import java.awt.Dimension; import java.awt.Color; import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; import ballWorlds.World; /** * A BallWorlds application is a Swing application that simulates "worlds" that * contain instances of various kinds of "balls" (and possibly other objects). * *

* The Main class contains the main method for the BallWorlds application * and hence is the starting point for that application. It constructs the * Worlds and the JFrame in which they will be displayed. * *

* This exercise is based on an exercise from Lynn Andrea Stein's Rethinking * CS101 project. See www.cs101.org. * * @author David Mutchler, Salman Azhar, Curt Clifton and others, January 2005. * Modified September 2008, September 2009. */ public class Main { /* Default number, sizes and colors for the Worlds. */ private final static int NUMBER_OF_WORLDS = 3; private final static Dimension WORLD_1_SIZE = new Dimension(600, 250); private final static Dimension WORLD_2_SIZE = new Dimension(800, 300); private final static Dimension WORLD_3_SIZE = new Dimension(500, 250); private final static Color WORLD_1_COLOR = new Color(0, 255, 126); private final static Color WORLD_2_COLOR = new Color(0, 255, 0); private final static Color WORLD_3_COLOR = new Color(0, 225, 0); /** * The BallWorlds application starts here in main. It constructs the * Worlds and the JFrame in which they will be displayed. * * @param args * Array of command-line arguments, ignored here */ public static void main(String[] args) { JFrame frame = new BallWorldsFrame(); Main.makeWorlds(Main.NUMBER_OF_WORLDS, frame); frame.setVisible(true); } /* * Makes the given number of Worlds, giving each the given frame. Rotates * between 3 preassigned sizes and colors for the Worlds. */ private static void makeWorlds(int numberOfWorlds, JFrame frame) { ArrayList dimensions = new ArrayList(); dimensions.add(Main.WORLD_1_SIZE); dimensions.add(Main.WORLD_2_SIZE); dimensions.add(Main.WORLD_3_SIZE); ArrayList colors = new ArrayList(); colors.add(Main.WORLD_1_COLOR); colors.add(Main.WORLD_2_COLOR); colors.add(Main.WORLD_3_COLOR); List universe = new ArrayList(); for (int k = 0; k < numberOfWorlds; k++) { new WorldWithTwoOrThreeThreads(universe, dimensions.get(k % 3), colors .get(k % 3), frame, true); } } }