import awb.*; import java.awt.*; import java.awt.event.*; public class GDemo3 extends java.applet.Applet implements ActionListener // A demonstration program for the Graphics methods combined with arrays { Graphics g; Canvas c; Button b1, b2; int x[] = {45, 95, 130, 130, 95, 45, 10, 10}; int y[] = {10, 10, 45, 95, 130, 130, 95, 45}; int n; public void init() { c = new Canvas(); c.setSize(200, 200); add(c); g = c.getGraphics(); b1 = new Button("Start"); b2 = new Button("StringFig"); b1.addActionListener(this); b2.addActionListener(this); add(b1); add(b2); n = 8; } public void actionPerformed(ActionEvent event) { Object cause = event.getSource(); if (cause == b1) { g.setColor(Color.white); // Color the whole canvas white g.fillRect(0, 0, 200, 200); } if (cause == b2) { int k, j; k = 0; g.setColor(Color.blue); while (k < n) { j = 0; while (j < n) { g.drawLine(x[k], y[k], x[j], y[j]); j = j + 1; } k = k + 1; } } } }