I have been staring at this program for a while and can't get it to work. I would appreciate any assistance that you can provide.
Problem: System.exit(0); is not working. IDE gives me an error that I don't understand. System should exit when mouse is pressed inside of rectangle.
Program description: Program is supposed to open drawing window and then draws rectangle. Program loops until mouse is pressed inside of rectangle (Mouse press marked by red hash). System is supposed to close when condition is true.
import element.*; // opens element library import java.awt.Color; // opens color library public class DrawHashMarks { // opens class /** * This class draws a set of hash marks. * @Walton */ public static void main(String[] args) { //opens main method DrawingWindow d = new DrawingWindow(); //opens drawing window Rect stop = new Rect (50,50,30,30); // draws rectangle Pt pressPoint; // sets variable for presspoint d.draw(stop); //a button for stopping d.setForeground(Color.red); // set color for hash mark while (true) { // potentially infinite pressPoint = d.awaitMousePress(); // mouse is now down if (stop.contains(pressPoint)); // leave loop drawHashAt(d,pressPoint); // calls drawHashAt method d.awaitMouseRelease(); // mouse is now up } // close loop System.exit(0); } // close main method public static void drawHashAt (DrawingWindow d, Pt center) { // opens method // pre: d is a valid drawing window, center is a valid point // post: draw a hash mark centered at center in drawing window d d.moveTo(center); //move to center of hash mark d.move(-10, 0); //move left d.line(20, 0); //draw horizontal axis d.move(-10, -10); //move up d.line(0, 20); //draw vertical axis } // opens drawHashAt method } // close class
Thanks for your help.