Note that there are some explanatory texts on larger screens.

plurals
  1. POGraphics plain 2D objects are not rendered while an action occurred
    primarykey
    data
    text
    <p>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. </p> <pre><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; } } } </code></pre> <p>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.</p> <p>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).</p> <p>Where is the problem? Please help.</p> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload