Need help with this simple problem

Playing with Java shapes, no colour or fill shown

Page 1 of 1

4 Replies - 380 Views - Last Post: 29 November 2009 - 10:34 AM Rate Topic: -----

#1 robert_tonnessen@hotmail.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 21-November 08

Need help with this simple problem

Post icon  Posted 29 November 2009 - 10:04 AM

Hi all, this place always delivers the goods so dont let me down.

I am just starting to learn a little java graphics and have a small problem. When i set the stroke colour or fill colour nothing happens, the shape is drawn with a standard colour and is never filled. I have two classes, draw() and shapes() the code for both is shown. what am i missing people?

draw,
package drawingShapes;

import java.awt.*;
import javax.swing.JPanel;


public class draw extends JPanel {

	public void drawing() {
		repaint();
	}

	public void paintComponent (Graphics g){
	this.paintComponent(g);

	g.setColor(Color.green);
g.fillRect(10, 15, 100, 20);
  

	}
}



shapes,
package drawingShapes;

import javax.swing.JFrame;

/**
 *
 * @author robert
 */
public class shapes {
public static void main (String[] args){

JFrame frame = new JFrame("test frame");
frame.setVisible(true);
frame.setSize(400, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
draw yourObject = new draw();
frame.add(yourObject);

yourObject.drawing();
}
}



First to solve wins a thumbs up!

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with this simple problem

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: Need help with this simple problem

Posted 29 November 2009 - 10:11 AM

this.paintComponent(g);



Shouldn't that be:
super.paintComponent(g);


Was This Post Helpful? 1
  • +
  • -

#3 robert_tonnessen@hotmail.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 21-November 08

Re: Need help with this simple problem

Posted 29 November 2009 - 10:26 AM

That Made no difference :(

tried both ways, same result.

who's next?
Was This Post Helpful? 0
  • +
  • -

#4 robert_tonnessen@hotmail.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 21-November 08

Re: Need help with this simple problem

Posted 29 November 2009 - 10:31 AM

Correction, after a 'clean and build' your this to super worked a treat!

thanks.
Was This Post Helpful? 0
  • +
  • -

#5 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: Need help with this simple problem

Posted 29 November 2009 - 10:34 AM

You're very welcome. Good luck on future endeavours!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1