Cant repaint in a loop

45 views Asked by At

I have a paintComponent method in a different class that extends JPanel:

@Override
public void paintComponent(java.awt.Graphics g) {
    super.paintComponents(g);
    java.awt.Graphics2D g2 = (java.awt.Graphics2D) g;
    g2.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);
    
    try {
        Draw.invoke(Main.newInstance(), g2);
    } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException ex) {
        System.out.println("err");
    }
    
    System.out.println("Paint!");
    
    g2.dispose();
}

And I'm attempting to repaint in a different class :

        while (running) {            
            long now = System.nanoTime();
            delta += (now - lastTime) / ns;
            lastTime = now;
            
            if (delta >= 1) {
                
                try {
                    Update.invoke(Main.newInstance());
                } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                    Logger.getLogger(Delta.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                gp.validate();
                gp.repaint();
                
                updates++;
                delta--;
            }
            frames++;
            if (System.currentTimeMillis() - timer > 1000) {
                timer += 1000;
                System.out.println("FPS: " + frames + " Ticks: " + updates);
                avgUpdates = updates;
                updates = 0;
                avgFrames = frames;
                frames = 0;
            }
        }

The update method does execute properly but the repaint method doesn't seem to work properly

0

There are 0 answers