Results 1 to 5 of 5
Thread: Canvas not being drawn
- 03-28-2009, 08:14 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 3
- Rep Power
- 0
Canvas not being drawn
Hello there,
I'm creating an applet where a player can play a game against an AI player. I'd like to create the option of having 2 AI's play against eachother. This works, but for some reason a graph which works fine in Human vs AI doesn't work in AI vs AI.
I've created a subclass of Canvas that should draw a graph somewhere in the applet. I've added this Canvas to my Applet (this.add(canvas, BorderLayout.WEST)).
This works fine when I play with the player vs the AI. When two AI's play against eachother, the canvas is not drawn. I suspect that this is because when two AIs play against eachother, the program never returns to the java runtime. When a human player plays against the AI, there is time in which non of my code is being executed, because the applet is awaiting new input from the player. When the AI plays against another AI this never happens. I thought at first that this problem was because paint() was never called in the latter case, but that's not true. paint() is being called, but for some reason the components add()ed to the applet are not being redrawn, or are not visible for some other reason.
Is there any chance someone can point me into the direction of the problem with just this description of the problem?
Thanks
- 03-28-2009, 08:41 PM #2
You're almost certainly executing your program logic on the EDT, thus blocking it and effectively preventing it from doing anything else -- like repainting the components.
This tutorial is for Swing, but even if your applet is a awt Applet and not a JApplet, much of it is applicable.
Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI with JFC/Swing)
dbLast edited by DarrylBurke; 03-28-2009 at 08:44 PM.
- 03-28-2009, 09:52 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 3
- Rep Power
- 0
Thanks a lot, I'm pretty sure that is indeed the problem!
- 03-29-2009, 12:19 AM #4
Member
- Join Date
- Mar 2009
- Posts
- 3
- Rep Power
- 0
Ok, I've partly rewritten my applet to be a JApplet and have organised the threads as explained in the tutorial you posted.
My question is this: how do I "send a message" from the EDT to the worker thread? I want to do this when a button is pressed (code running in the EDT) and do it in a threadsafe manner.
Is it safe to set a boolean without a lock? How do I send larger messages between threads?
ThanksLast edited by tacosc; 03-29-2009 at 12:45 AM.
- 03-29-2009, 10:11 AM #5
Similar Threads
-
Help with canvas
By tankhardrive in forum New To JavaReplies: 13Last Post: 10-29-2008, 08:08 PM -
Canvas Example
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:22 PM -
Using SWT Canvas
By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 09:06 AM -
How do erase image drawn
By fernando in forum New To JavaReplies: 1Last Post: 08-06-2007, 05:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks