Thursday 15 April 2010

oop - Java simple drawing program using bookClasses SimpleTurtle -


For my online Java class I am trying to get a simple drawing program to work in this program. To create a world object with a turtle (I'm using to run this program). To attract, I'm using a MiceListener. My problem is that I have two windows: the ones on which I draw, the lines on the other side are visible. I would like to draw on the same window on which the lines are formed. I am using turtle I (I am just using turtle here which comes from the signal turtle) Anyway, here is my code:

  import java.awt.event .MouseAdapter; Import java.awt.event.MouseEvent; Class MyMouseAdapter provides MouseAdapter {World worldObj = New World (); Turtle turtle = new turtle (1000, 1000, world oz); Public zero mousePressed (MouseEvent e) {int xpressed = e.getX (); Int ypressed = e.getY (); System.out.printf ("mouse clicked:% d,% d% n", xpressed, yPressed); Turtle.hide (); Turtle.penUp (); TurtleMovato (xpressed, yPressed); } Public Zero Mouse was released (MouseEvent e) {int xReleased = e.getX (); Int yReleased = e.getY (); System.out.printf ("Mouse Released:% d,% d% n", Xrrated, Wireless); Turtle.show (); Turtle.penDown (); tortoise. Maw (x related, Y release); Turtle.hide (); }} Public square WorldTest2 {public WorldTest2 (world world obj = new world); WorldObj.addMouseListener (New MyMouseAdapter ()); } Public Stable Zero Main (string [] Args) {World Test 2 Test = New World Test 2 (); }}  

I know why this does not work (I'm making turtle on one world but mouse listener on the other), but I do not know how I can fix it this. Any help?

Add a getter () method to your World Test 2 class

Public Class World Test 2 {World World Oj; Public World () {worldObj = New World (); } Public World Friendly () {// Now call it Mimass adapter class returns world obj. Instead of creating new objects in the world}}

In the MyMouseAdapter class

  class MyMouseAdapter offers MouseAdapter {World WorldObj = new worldast 2 (). GetWorld (); }  

No comments:

Post a Comment