Hi following is my code, now I want to remove the object from the world which has a text message in it.Similarly I want to even add some more text in the world after some work is performed.Can you help me in this.
----------------------------------------------------------------------------------------------------------
Now I am finding it difficult to add and remove a text message at runtime....
Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public void act() { int mouseX, mouseY ; String text = "Have Coin!" ; String text1= "Have penny" ; if (Greenfoot.mouseDragged( this )) { MouseInfo mouse = Greenfoot.getMouseInfo(); mouseX=mouse.getX(); mouseY=mouse.getY(); setLocation(mouseX, mouseY); if ((mouseX> 300 && mouseX < 400 ) && (mouseY> 200 && mouseY< 250 )) { World w = getWorld(); w.removeObject( this ); //getMessage(); //Message message= new Message(text); w.addObject( new Message(text), 380 , 450 ); //getWorld().addObject(message(text),380,450); update(); Greenfoot.playSound( "coin-drop.wav" ); Greenfoot.delay( 10 ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; public class Message extends Actor { public Message(String text) { GreenfootImage gi= new greenfoot.GreenfootImage( 100 , 30 ); gi.drawString(text, 2 , 20 ); setImage(gi); } } |