import java.awt.*; import java.awt.event.*; import javax.swing.*; class GUIFlow extends JFrame{ JTextField jtf1, jtf2, jtf3, jtf4; JLabel jl1, jl2, jl3, jl4; public GUIFlow(){ setTitle("GUIFlow"); addComponents(getContentPane()); setSize(new Dimension(200,150)); setDefaultLookAndFeelDecorated(true); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void addComponents(Container c){ c.setLayout(new FlowLayout()); jtf1 = new JTextField(10); jtf2 = new JTextField(10); jtf3 = new JTextField(10); jtf4 = new JTextField(10); jl1 = new JLabel("Label1"); jl2 = new JLabel("Label2"); jl3 = new JLabel("Label3"); jl4 = new JLabel("Label4"); c.add(jl1); c.add(jtf1); c.add(jl2); c.add(jtf2); c.add(jl3); c.add(jtf3); c.add(jl4); c.add(jtf4); } public static void main(String[] args) { GUIFlow gf = new GUIFlow(); } } class GUIGrid extends JFrame{ JTextField jtf1, jtf2; JButton jb1, jb2, jb3, jb4; public GUIGrid(){ setTitle("GUIGrid"); addComponents(getContentPane()); pack(); setDefaultLookAndFeelDecorated(true); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void addComponents(Container c){ c.setLayout(new GridLayout(0,3)); jtf1 = new JTextField(10); jtf2 = new JTextField(10); jb1 = new JButton("Button1"); jb2 = new JButton("Button2"); jb3 = new JButton("Button3"); jb4 = new JButton("Button4"); c.add(jb1); c.add(jb2); c.add(jb3); c.add(jtf1); c.add(jb4); c.add(jtf2); } public static void main(String[] args) { GUIGrid gg = new GUIGrid(); } } class GUIBorder extends JFrame{ JTextField jtf1, jtf2, jtf3, jtf4; JButton jb1; public GUIBorder(){ setTitle("GUIBorder"); addComponents(getContentPane()); pack(); setDefaultLookAndFeelDecorated(true); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void addComponents(Container c){ c.setLayout(new BorderLayout(0,3)); jtf1 = new JTextField(10); jtf2 = new JTextField(10); jtf3 = new JTextField(10); jtf4 = new JTextField(10); jb1 = new JButton("Button1"); c.add(jb1, BorderLayout.CENTER); c.add(jtf1, BorderLayout.NORTH); c.add(jtf2, BorderLayout.SOUTH); c.add(jtf3, BorderLayout.EAST); c.add(jtf4, BorderLayout.WEST); } public static void main(String[] args) { GUIBorder gb = new GUIBorder(); } } class Calculator extends JFrame{ JTextArea screen; JTextField input; JMenuBar jmb; JMenu jm1; JMenuItem jmi1, jmi2, jmi3; JButton add, subtract, divide, multiply, mod, clear, enter; double currentValue; int currentOperation; public Calculator() { setTitle("Calculator"); Container c = getContentPane(); addComponents(c); pack(); setDefaultLookAndFeelDecorated(true); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void addComponents(Container c){ c.setLayout(new BoxLayout(c,BoxLayout.Y_AXIS)); add = new JButton("+"); subtract = new JButton("-"); divide = new JButton("/"); multiply = new JButton("*"); mod = new JButton("%"); clear = new JButton("Clear"); enter = new JButton("="); JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(0,5)); p1.add(add); p1.add(subtract); p1.add(multiply); p1.add(divide); p1.add(mod); JPanel p2 = new JPanel(new GridLayout(0,1)); p2.add(clear); JPanel p3 = new JPanel(new GridLayout(0,1)); p3.add(enter); input = new JTextField(10); screen = new JTextArea(5,20); screen.setEditable(false); c.add(screen); c.add(p2); c.add(p1); c.add(p3); c.add(input); } public static void main(String[] args) { Calculator calculator1 = new Calculator(); } }