Note that there are some explanatory texts on larger screens.

plurals
  1. POGlitch drawing on JComponent
    primarykey
    data
    text
    <p>I'm having this weird kind of glitch with drawing on an JComponent. What happens is that whenever i drag the JFrame window outside the bounds of my monitor, the drawing accelerates and draws faster than it should. I'm guessing it has to do something with swing management, seems like drawing stops once the Jframe is offscreen and resumes in a burst kind of way after being set inside the bounds of the monitor screen.</p> <p>Here's my code:</p> <pre><code>package javagame; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import javax.swing.JComponent; /** * * */ public class Screen extends JComponent implements Runnable{ // paintbrush for drawing. //private Graphics internalg; private boolean keepDrawing = true; public Screen() { super(); startDrawing(); } /// Draw methods @Override protected void paintComponent(Graphics g) { super.paintComponent(g); //internalg = g; //Draw //System.out.println("painted"); drawSomething(g); } @Override public void run() { //Draw until manually stopped while(keepDrawing){ repaint(); try { Thread.sleep(100); } catch (InterruptedException ex) { } } } /** * Fire off thread. */ private void startDrawing() { Thread t = new Thread(this); //thread ends when JFrame is closed. t.setDaemon(true); t.start(); } /// Draw Logic /// /// Images int d = 2; public void drawSomething( Graphics internalg ) { if (isValid()){ internalg.setColor(Color.BLACK); internalg.fillRect(0, 0, getWidth(), getHeight());//clear bg internalg.setFont( new Font(Font.DIALOG, Font.BOLD, 15) ); internalg.setColor( Color.GREEN ); internalg.drawOval( (getWidth()/2)-(d/2) , (getHeight()/2)-(d/25), d, d); d++; } } /// Images } </code></pre>
    singulars
    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