File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Drawing a triangle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Drawing a triangle" Watch "Drawing a triangle" New topic
Author

Drawing a triangle

Cecille Yang
Greenhorn

Joined: Sep 17, 2011
Posts: 2
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
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
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".


Ping & DNS - updated with new look and Ping home screen widget
Cecille Yang
Greenhorn

Joined: Sep 17, 2011
Posts: 2
Oh, that would do it. Thanks!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

Your paintComponent method is missing the call to super.paintComponent(g).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Drawing a triangle
 
Similar Threads
Small event handling problem, need to implement a stop
Someone Please Help! Graphics 2D
Checkerboard w/ 64 squares
Some help needed to find an event stopping condition
The method add(Component) in the type Container is not applicable for the arguments (Class)Why?