-1

I am trying to draw at my mouse a certain shape that I have set. I defined some shapes where they extend shape and draw circles and stuff. But when I click on panel it seems the paint doesnt put anything on the white jpanel. Debugger tells me shapes are saved though.

public void mouseClicked(MouseEvent e) {
    currentX = e.getX();

    currentY = e.getY();

    Shape newShape = owner.currentBrush.clone();
    picture.add(newShape); 
    repaint();
}
public void paint(Graphics g){

        super.paint(g);
        for( int i = 0; i < myShapes.size(); i++ ){
            picture.get(i).draw(g); 
        }

    }

public void draw(Graphics g){
        Graphics g2d = (Graphics2D) g;

        g2d.setColor(Color.BLUE);

        g2d.fillOval(getX(), getY(), radius, radius);

        g.drawOval(getX(), getY(), radius, radius);
    }

1 Answers1

2

Instead of overriding paint() method use paintComponent() method for JPanel.

@Overrie
public void paintComponent(Graphics g) {
     super.paintComponent(g);
     //your custom painting here
}

Read more

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
  • It seems to have the same problem@Override public void paintComponent(Graphics g){ super.paintComponent(g); for( int i = 0; i < owner.myDraw.picture.size(); i++ ){ owner.myDraw.picture.get(i).draw(g); //System.out.println("I BET THIS NEVER PRINTS"); } System.out.println("I AM TRYING TO PAINT"); – Peter Steuber Jun 13 '14 at 19:32
  • why are you using `g.drawOval()` and `g2d.fillOval()` where both Graphics are used that draws at same location. – Braj Jun 13 '14 at 19:37
  • I think you have to spend some time to study about Swing application and custom painting. Any online stuff will never help you at all. – Braj Jun 13 '14 at 19:49
  • http://pastebin.com/aav73i7x realized I was adding a new jpanel, but doesnt seem to be the problem – Peter Steuber Jun 13 '14 at 19:50
  • Just create a simple test program and try to replicate this issue. – Braj Jun 13 '14 at 19:51
  • http://www.filedropper.com/paintproject a better way to see it. It is so close to working. I put so much time into this thing. – Peter Steuber Jun 13 '14 at 20:03
  • Was working the whole time. Just didn't update the x and y setters. – Peter Steuber Jun 13 '14 at 20:34