public class GUIStuff
1: import java.util.Scanner;
2: import javax.swing.*;
3: import java.awt.*;
5: public class GUIStuff {
6: public static void main(String[] args) {
8: System.out.print("\n\n"
9: + "GUI Stuff\n"
10: + "---------\n\n"
11: + "This program creates and manipulates windows.\n\n"
12: + "After each time you press enter, "
13: + "you need to click back in THIS window "
14: + "to\ncontinue with the demonstration.\n\n\n");
16: JFrame win = new JFrame("My Win");
17: System.out.println("A new window has been created!");
18: System.out.println("\nWhaddaya mean you can't see it?\n");
19: pause();
21: win.setVisible(true);
22: System.out.println("\nOh, sorry! Now it's not invisible.\n");
23: pause();
25: win.setSize(300, 200);
26: System.out.println("\nAnd now it's not so tiny.\n");
27: pause();
29: JLabel lbl1 = new JLabel("Hello, World!");
30: // win.getContentPane().add(lbl1);
31: win.add(lbl1);
32: win.setVisible(true);
33: System.out.println("\nNow it has a label in it.\n");
34: pause();
36: JTextField tf = new JTextField("Initial Text");
37: win.getContentPane().add(tf, BorderLayout.PAGE_END);
38: win.setVisible(true);
39: System.out.println("\nNow it has a text field "
40: + "(type in the text field).\n");
41: pause();
43: JButton b1 = new JButton("OK");
44: win.add(b1);
45: win.setVisible(true);
46: System.out.println("\nNow it's got a button (click the button).\n");
47: pause();
49: JFrame win2 = new JFrame("Flow Layout Window");
50: win2.setSize(300, 200);
51: win2.setLayout(new FlowLayout());
52: win2.add(new JLabel(">>>First Label<<<"));
53: win2.add(new JLabel(">>>Second Label<<<"));
54: win2.add(new JLabel(">>>Third Label<<<"));
55: win2.add(new JLabel(">>>Fourth Label<<<"));
56: win2.add(new JLabel(">>>Fifth Label<<<"));
57: win2.setVisible(true);
58: System.out.println("\nAnother window -- "
59: + "resize it and watch how the labels move.\n");
60: pause();
62: JFrame win3 = new JFrame("Border Layout Window");
63: win3.setSize(300, 200);
64: win3.setLayout(new BorderLayout());
65: win3.add(new JLabel(">>>North Label<<<"), BorderLayout.NORTH);
66: win3.add(new JLabel(">>>South Label<<<"), BorderLayout.SOUTH);
67: win3.add(new JLabel(">>>East Label<<<"), BorderLayout.EAST);
68: win3.add(new JLabel(">>>West Label<<<"), BorderLayout.WEST);
69: win3.add(new JLabel(">>>Center Label<<<"), BorderLayout.CENTER);
70: win3.setVisible(true);
71: System.out.println("\nAnother window -- "
72: + "resize it and watch how the labels move.\n");
73: pause();
75: JFrame win4 = new JFrame("Grid Layout Window");
76: win4.setSize(300, 200);
77: win4.setLayout(new GridLayout(2, 3));
78: win4.add(new JLabel(">>>First Label<<<"));
79: win4.add(new JLabel(">>>Second Label<<<"));
80: win4.add(new JLabel(">>>Third Label<<<"));
81: win4.add(new JLabel(">>>Fourth Label<<<"));
82: win4.add(new JLabel(">>>Fifth Label<<<"));
83: win4.setVisible(true);
84: System.out.println("\nAnother window -- "
85: + "resize it and watch how the labels move.\n");
86: pause();
88: System.out.println("\n\n\n"
89: + "Hit ^C or close this window to end the program\n\n\n");
90: }
92: public static void pause() {
93: System.out.print("Press enter key to continue...");
94: Scanner kbd = new Scanner(System.in);
95: kbd.nextLine();
96: }
97: }