import awb.*; import java.awt.*; import java.awt.event.*; public class Shapes extends java.applet.Applet implements ActionListener { IntField gSize; TextArea ta; String stars = "*******************"; String spaces = " "; Button bDiamond, bHGlass, bTree, bChain; public void init() { gSize = new IntField(10); bDiamond = new Button("Diamond"); bHGlass = new Button("Hour Glass"); bTree = new Button("Tree"); bChain = new Button("Chain"); ta = new TextArea(20, 20); ta.setFont(new Font("Courier", Font.BOLD, 10)); bDiamond.addActionListener(this); bHGlass.addActionListener(this); bTree.addActionListener(this); bChain.addActionListener(this); add(gSize); add(bDiamond); add(bHGlass); add(bTree); add(bChain); add(ta); } void BlankLine() { ta.append(" \n"); } void Dia(int sz) { int k = 0; while (k < sz) { ta.append(spaces.substring(0,10-k) + stars.substring(0,2*k+1)+"\n"); k = k + 1; } } void Mond(int sz) { int k = sz; while (k > 0) { k = k - 1; ta.append(spaces.substring(0,10-k) + stars.substring(0,2*k+1)+"\n"); } } void Diamond(int sz) { BlankLine(); Dia(sz); Mond(sz-1); } void Tree(int sz) { BlankLine(); Dia(sz - 4); Dia(sz - 2); Dia(sz); Dia(1); Dia(1); } void Chain(int sz) { int k = 0; BlankLine(); while (k < sz) { Dia(2); Mond(1); k = k + 1; } } public void actionPerformed(ActionEvent event) { Object cause = event.getSource(); int sz; if (cause == bDiamond) { sz = gSize.getInt(); Diamond(sz); } if (cause == bHGlass) { sz = gSize.getInt(); BlankLine(); Mond(sz); Dia(sz); } if (cause == bTree) { sz = gSize.getInt(); Tree(sz); } if (cause == bChain) { sz = gSize.getInt(); Chain(sz); } } }