/** * A Simple stand-alone GUI program based on Swing. * The program displays all the command line args in a JFrame, * each arg becomes a JButton. * * There are a number of methods defined in this program that * use various layout managers, one one should get called. * Try using different layout managers to see how they change * the appearance of things... * (by default you will only see one button!) * * @author Dave Hollinger * @version 1.0 */ import javax.swing.*; import java.awt.*; // needed for Container class ListArgs { static private final String label = "Hello World"; static private final String title = "Simple Java GUI"; public static void main(String [] args) { // create a top-level container with a title JFrame frame = new JFrame(title); // set the size frame.setSize(400,200); // establish what happens when the window is closed // (without this the program would keep running!) frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // grab the content container associated with the frame. Container c = frame.getContentPane(); /* uncomment one of the lines below to establish which layout manager is used (these methods are defined below). */ defaultLayout(c,args); //flowLayout(c,args); //gridLayout(c,args); //gridLayout2(c,args); // make the frame visible frame.setVisible(true); } /** * defaultLayout doesn't specify a layout manager. * (the default is BorderLayout). * * The result is that all the buttons are placed on top of each other * and you can only see the last one added * @param c is the container to which we add the buttons * @param args list of strings used to create buttons. */ static void defaultLayout(Container c, String [] args) { // add each command line arg as a button for (int i=0;i