import java.awt.*; /** * This class visualizes the selection of the towns with the mouse. * * coding: h.sarg * modified: 01/98 */ public class TownCanvas extends java.awt.Canvas implements java.awt.event.MouseListener { /** * holds the towns */ private int[][] townarray; /** * distance from one town to its nearest impossible town width */ private int stepwidth; /** * distance from one town to its nearest impossible town height */ private int stepheight; /** * canvas width */ private int canvaswidth=340; /** * canvas height */ private int canvasheight=340; /** * grid of towns */ private int grid=0; /** * TownCanvas constructor comment. */ public TownCanvas() { super(); this.addMouseListener(this); } /** * gets towns from the DialogData object and makes a copy of them * @param a array of towns * @param b grid */ public void setTownData(int[][] a, int b) { Dimension canvassize; this.grid = b; if(a == null) { this.townarray=new int[grid][grid]; for(int i=0;i= 0) { gbuff.setColor(java.awt.Color.blue); gbuff.drawOval(i*stepwidth+2,j*stepheight+2,stepwidth-4,stepheight-4); gbuff.fillOval(i*stepwidth+2,j*stepheight+2,stepwidth-4,stepheight-4); gbuff.setColor(java.awt.Color.gray); } } } } g.drawImage(buffered_image,0,0,this); g.dispose(); return; } /** * Clicking to a position in the canvas sets the corresponding town. * Is this town already set then the click removes it. * @param e java.awt.event.MouseEvent */ public void mouseClicked(java.awt.event.MouseEvent e) { int a,b; int x,y; x=e.getX(); y=e.getY(); if (x