Results 1 to 4 of 4
Thread: Looped repaint of display area
- 07-28-2009, 02:38 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 7
- Rep Power
- 0
Looped repaint of display area
Hi everyone,
I am a new member of this forum and I need your help for a little problem I have.
I have this piece of code in my main function:
The purpose of the code is to update the display area, and a few graph areas while my simulation is running. This worked perfectly for a while, but recently I think I've updated to a newer version of JDK and now the program doesn't seem to run the repaints if my simRunning boolean is true.Java Code:while (true) { if (simRunning) { da.repaint(); fpsGA.repaint(); vehiclesNumberGA.repaint(); } }
What is even more interesting, when I go to debug mode it does run the repaints when my simRunning is true. So only when I normally run my application I have the problem with the repaints.
Any suggestion will be appreciated.
Thanks,
Gix
- 07-28-2009, 05:00 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Just updating the JDK couldn't cause for this, hard to believe that. Can you show up your code here, which we can have an idea what's you've done.
- 07-28-2009, 12:45 PM #3
Member
- Join Date
- Jul 2009
- Posts
- 7
- Rep Power
- 0
My code is pretty huge, so i will just post the part I guess you need to determine what the problem is. The trick is that the code hasn't changed from what it was before I upgraded and after I upgraded, and while before it worked now it doesn't.
This is the display area (da) class paint function, the bolded code part functions will be given below:
Here's the trafficMap draw function:Java Code:public void paintComponent(Graphics g) { statBar.setMessage(lastStatusMessage + " x = " + mouseXMove + ", y = " + mouseYMove); Graphics2D g2 = (Graphics2D) g; g2.translate(xOffset, yOffset); g2.scale(ZOOM, ZOOM); g2.setBackground(new Color(162, 205, 90)); g2.clearRect((int) ((xOffset * -1) / ZOOM), (int) ((yOffset * -1) / ZOOM), (int) (getWidth() / ZOOM), (int) (getHeight() / ZOOM)); g2.setClip((int) ((xOffset * -1) / ZOOM), (int) ((yOffset * -1) / ZOOM), (int) (getWidth() / ZOOM), (int) (getHeight() / ZOOM)); g2.addRenderingHints(new RenderingHints( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); [B]trafficMap.moveVehicles(frameRate); trafficMap.drawMap(g2);[/B] // Start and End Positions g2.setFont(new Font("Trebuchet MS", 0, 6)); g2.setColor(new Color(238, 154, 0)); if (routeStart != null) { g2.fillOval(routeStart.getXLoc() - 10, routeStart.getYLoc() - 10, 20, 20); g2.setColor(Color.black); g2.drawString("Start", routeStart.getXLoc() - 7, routeStart .getYLoc() + 2); } g2.setColor(new Color(238, 154, 0)); if (routeEnd != null) { g2.fillOval(routeEnd.getXLoc() - 10, routeEnd.getYLoc() - 10, 20, 20); g2.setColor(Color.black); g2.drawString("End", routeEnd.getXLoc() - 5, routeEnd.getYLoc() + 2); } if (showMouseDrag) { g2.setColor(Color.black); g2.drawLine(mouseX1, mouseY1, mouseX2, mouseY2); } }
The draw road function and the draw vehicle functions only draws polygons of those classes at the appropriate spots.Java Code:public void drawMap(Graphics g) { TrafficSim.startRefreshTime = System.currentTimeMillis(); Graphics2D g2 = (Graphics2D) g; g2.setFont(new Font("Trebuchet MS", 0, 6)); // if we have put background Map image if (bckgImage != null) g2.drawImage(bckgImage, 0, 0, null); // Roads for (Road r : roads) { [B]r.drawRoad(g2, new Color(139, 139, 131));[/B] } for (Road r : roads) { [B]r.drawVehicles(g2);[/B] } TrafficSim.endRefreshTime = System.currentTimeMillis(); TrafficSim.simulationTime = (int) (TrafficSim.endRefreshTime - TrafficSim.simulationStart) / 100; TrafficSim.waitRefresh = TrafficSim.endRefreshTime - TrafficSim.startRefreshTime; if (TrafficSim.waitRefresh < 1) TrafficSim.waitRefresh = 1; TrafficSim.frameRate = (double) 1000; TrafficSim.frameRate /= (double) TrafficSim.waitRefresh; }
But the code i am posting is not a problem at all... the problem is in the while loop I posted in my first post. Here's my main function:
So basically, the program is stuck in the while loop during execution and should repaint my components when I set simRunning to true. But now, even if I put something of the sort:Java Code:public static void main(String args[]) { new TrafficSim(); while (true) { if (simRunning) { da.repaint(); fpsGA.repaint(); vehiclesNumberGA.repaint(); } } }
which will print "true", it will still refuse to go inside and execute the repaints in the if statement...Java Code:System.out.println(simRunning);
- 07-28-2009, 12:53 PM #4
Member
- Join Date
- Jul 2009
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
repaint() problems
By Emily1100125 in forum AWT / SwingReplies: 5Last Post: 02-03-2009, 04:11 PM -
Help with repaint() command
By GeoffTK in forum New To JavaReplies: 2Last Post: 11-26-2008, 04:33 AM -
Problem in repaint
By Preethi in forum AWT / SwingReplies: 16Last Post: 03-18-2008, 08:10 PM -
Repaint problem
By swimberl in forum Java 2DReplies: 0Last Post: 01-06-2008, 03:28 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks