[nbusers] Re: Graphics plain 2D objects are not rendered while an action occurred!!!

  • From: Alexander Schell < >
  • To:
  • Subject: [nbusers] Re: Graphics plain 2D objects are not rendered while an action occurred!!!
  • Date: Sat, 28 Jan 2012 08:56:53 +0100

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hello ravi

as far as i know you'll need a 'repaint()' to notify the container
holding your graphic to paint the changes...so i guess you'll need
something like a cyclic repaint...would be best to store your
generated maze in a structure which is able to paint itself...

best regards

alex

On 28.01.2012 08:57, ravi.joshi53 wrote:
> Hi, I am designing a game in Swing. Currently I am designing the
> maze for this game. The maze is generated by using Depth First
> Search algorithm. In my main JFrame, I have some JPanel. One
> JPanel, named mazePanel contains the maze. There are some other
> JPanel also, which contains the JButton for controlling. Following
> is the mazePanel code.
> 
> Code:
> 
> import java.awt.Graphics; import javax.swing.BorderFactory; import
> javax.swing.JPanel;
> 
> public class MazePanel extends JPanel {
> 
> private MazeGenerator mazeGenerator; private boolean startNewMaze =
> false;
> 
> public MazePanel() { 
> setBorder(BorderFactory.createTitledBorder("Maze")); 
> setToolTipText("This is the maze"); }
> 
> public void addNewMaze() { startNewMaze = true; mazeGenerator = new
> MazeGenerator(); }
> 
> @Override public void paintComponent(Graphics g) { 
> super.paintComponent(g); if (startNewMaze) { 
> mazeGenerator.generate(g); startNewMaze = false; } } }
> 
> 
> 
> 
> There is one JButton, which calls the method mazePanel.addNewMaze()
> and set the Boolean startNewMaze to true. After setting the
> startNewMaze, maze should be generated. i.e.
> mazeGenerator.generate(g) is inside if() condition. Method
> mazeGenerator.generate(g) recursively draw the random maze. That is
> why I donĂ¢??t want to run this method not more than once. Up to
> this everything is looking fine. But while I am running the main
> JFrame and clicks on the JButton, maze is not rendered in the
> mazePanel. Sometimes when I minimize and maximize the JFrame, maze
> rendered (might be because of repaint() occur). Even if I comment
> mazeGenerator.generate(g) inside if() condition and put some
> g.drawString(). The string is not rendered while action performed
> (i.e.Pressing JButton).
> 
> Where is the problem? Please help.
> 
> Thank you.
> 
> 
> 
> 
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8jqkUACgkQfkcoZSkNJQY1pwCdHLSRfZSkWsL/ETP4GCe2mcSV
1b8An0+re4cHPeigm/BBtI8wF0pY3Btb
=impG
-----END PGP SIGNATURE-----


[nbusers] Graphics plain 2D objects are not rendered while an action occurred!!!

ravi.joshi53 01/28/2012

[nbusers] Re: Graphics plain 2D objects are not rendered while an action occurred!!!

Alexander Schell 01/28/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close