paintComponent tekent niet

Status
Niet open voor verdere reacties.

tuttefrut

Gebruiker
Lid geworden
7 nov 2011
Berichten
11
Hallo,


Ik ben een spelletje pong aan het maken en ik wil mijn twee peddels op mijn scherm tekenen maar dit wil me maar niet lukken
Zie ik iets over het hoofd in mijn code?

Code:
public class PongGame extends JFrame {

  // variablen hier
    
    private Gui gui;
    
    public static void main(String[] args) {
        // TODO code application logic here
        new PongGame();
        
    }
    public PongGame() {
        
         gui = new Gui();

        setSize(500, 500);

        setTitle("Pong Game -- Arne Van Cant");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setContentPane(gui);
        setVisible(true);
        setResizable(false);
        setLocationRelativeTo(null);
        
        
    }
}
class Gui extends JPanel {
    
    public Gui() {
        
        
    }
}
class gamePaneel extends JPanel {
    
    // hier komen variable van bal en peddel
    private Peddel peddelA,peddelB;
    
    public gamePaneel() {
        
        // nieuwe instanties van bal en peddel aanmaken
        
        peddelA = new Peddel(20, 120, Color.blue);
        peddelB = new Peddel(20, 120, Color.red);
               
    }
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        
        peddelA.draw(g);
        peddelB.draw(g);
    }
    
    
}
class Peddel {
      private int x, y;
    private Color kleur;
    private int hoogte = 70;

    public Peddel(int x, int y, Color kleur) {
        this.x = x;
        this.y = y;
        this.kleur = kleur;

    }

    public void draw(Graphics g) {
        g.setColor(kleur);
        g.fillRect(x, y, 10, hoogte);
    }

    public void moveUp() {
        if (y > 0) {
            y = y - 10;
        }
    }

    public void moveDown() {
        if (y < 341) {
            y = y + 10;
        }
    }

    public int getX() {
        return x;
    }

    public int getYBoven() {
        return y;
    }

    public void setHoogte(int hoogte) {
        this.hoogte = hoogte;
    }

    public int getYOnder() {
        return y + hoogte;
    }
}
 
see
Code:
    public void paint(Graphics2D g){
        System.out.print("paint=>"+toString());
        g.setColor(Color.black);
        g.fillRect(0, 0, d.width, d.height);
        DrawMaze(g);
    }
@https://code.google.com/p/javamygame/source/browse/trunk/Java_Gamer/src/be/djdb/game/essetials/MyLevel.java
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan