• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drawing a triangle

 
Cecille Yang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm really new to programming in general, and for my comp sci class we have to create a rectangle. The teacher wants two classes- one that creates the lines (using Line2D.Double) and extends JComponent, and the JComponent, which is the viewer class. I only drew one line in the Triangle class because I wanted to get the program up and running before fiddling around with the more specific details.

My problem is that the frame.add in the viewer class isn't working... there's an error "The method add(Component) in the type Container is not applicable for the arguments (Triangle)".

Code for Triangle:


Code for my viewer:
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JComponent is the name of an existing class (javax.swing.JComponent) - you shouldn't use that as the name of one of your classes. Or -if you need to do that for the purposes of your assignment- you need to declare Triangle as "... extends javax.swing.JComponent".
 
Cecille Yang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, that would do it. Thanks!
 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your paintComponent method is missing the call to super.paintComponent(g).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic