Note that there are some explanatory texts on larger screens.

plurals
  1. POThreaded repaint opening new window
    primarykey
    data
    text
    <p>I am using java to make a simple game. I have code that forty times a second, runs the screen thread. However, whenever i call the screen thread a new window opens up and the old one also stays open. Is there a way I can fix this? Thanks</p> <pre><code>package sylvyrfysh; import java.awt.*; import javax.swing.*; import sylvyrfysh.handlers.OreHandler; import sylvyrfysh.troops.manager.TroopManager; public class Screen extends JFrame implements Runnable{ private static final long serialVersionUID = -377919050238217712L; public Screen(){ super("Commander"); setContentPane(new DrawPane()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setFont(new Font("Arial",Font.PLAIN,12)); setSize(607,669); setVisible(true); setResizable(false); KeyboardFocusManager manager=KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventDispatcher(new EventHandler()); addMouseListener(new MouseHandler()); } class DrawPane extends JPanel{ private static final long serialVersionUID = 2729138328693556841L; public void paintComponent(Graphics g){ g.setColor(Color.BLACK); g.fillRect(0,0,600,40); g.setColor(Color.CYAN); g.drawString("Ore: "+Main.ore,0,10); g.drawString("Base Health: "+Main.baseHealth,0,30); g.setColor(Color.BLUE); g.fillRect(0,40,600,600); g.setColor(Color.GREEN); g.fillRect(0,40,100,100); for(int[] i:TroopManager.troops){ g.fillRect(i[1],i[2]+40,1,1); } g.setColor(Color.RED); g.fillRect(500, 540, 100, 100); for(int[] i:TroopManager.enemyTroops){ g.fillRect(i[1],i[2]+40,1,1); } g.setColor(Color.YELLOW); for(int[] i:OreHandler.ore){ g.fillRect(i[1],i[2]+40,1,1); } } } public void run(){repaint();} } </code></pre> <p>EDIT: What appears to be happening is whenever i call the screen thread, it also calls the constructor.</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.
    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