|
-
how would i go about removing objects?
what im trying to do is after box1 and box 2 intersect i want to remove all boxes and remove Graphics2D so that i can add a contentpane to the program,calling certain buttons and labels,how would i go about doing or is there a simpler way then what im thinking about?
________
public class BoxIntersection extends JApplet implements Runnable, KeyListener
{
public void init()
{
getContentPane().setLayout(null);
setSize(DISPLAY_WIDTH,DISPLAY_HEIGHT);
setIgnoreRepaint(false);
addKeyListener(this);
//setBackground(Color.CYAN);
backBuffer = new BufferedImage(DISPLAY_WIDTH,DISPLAY_HEIGHT,BufferedImage.TYPE_INT_RGB);
bbGraphics = (Graphics2D) backBuffer.getGraphics();
//create six boxes...
box1 = new Box(DISPLAY_WIDTH/2 - 50,DISPLAY_HEIGHT/2 - 25,100,50);
box2 = new Box(100,100,50,50);
box3 = new Box(0,0,400,5);
box4 = new Box(395,0,5,400);
box5 = new Box(0,0,5,400);
box6 = new Box(0,395,400,5);
}
public void start()
{
loop = new Thread(this);
loop.start();
}
public void stop()
{
loop = null;
}
public void run()
{
long startTime,waitTime,elapsedTime;
//1000/25 FPS = 40ms delay
int delayTime = 1000/25;
Thread thisThread = Thread.currentThread();
while(loop == thisThread)
{
startTime = System.currentTimeMillis();
//render to back buffer now
render(bbGraphics);
//render back buffer image to screen
Graphics g = getGraphics();
g.drawImage(backBuffer, 0, 0,null);
g.dispose();
//handle frame rate
elapsedTime = System.currentTimeMillis() - startTime;
waitTime = Math.max(delayTime - elapsedTime, 5);
try
{
Thread.sleep(waitTime);
}
catch(InterruptedException e)
{
}
}
}
public void render(Graphics g)
{
g.clearRect(0, 0,DISPLAY_WIDTH,DISPLAY_HEIGHT);
if(box1.intersects(box2)) // change the color to white...
{
g.setColor(Color.white);
}
else
g.setColor(Color.green);
box1.render(g);
box2.render(g);
box3.render(g);
box4.render(g);
box5.render(g);
box6.render(g);
______
and below i have key movements that i didnt include in this post
Similar Threads
-
By asmita in forum VB Classic
Replies: 0
Last Post: 06-08-2005, 02:03 AM
-
By Michael Cole in forum Database
Replies: 2
Last Post: 04-02-2003, 03:06 PM
-
By Michael Cole in forum oracle.general
Replies: 0
Last Post: 02-20-2003, 10:25 PM
-
By Dave Fleischman in forum Enterprise
Replies: 3
Last Post: 08-18-2000, 01:10 PM
-
By Oliver Lennon in forum Enterprise
Replies: 3
Last Post: 04-18-2000, 12:30 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks