The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


How to draw a line in Java?

Posted by Avin Sinanan on November 30, 2001 at 4:21 AM

Ok how does one draw a simple line in java..
here is the cod ei have so far... i can draw a line but i am looking for a different method to draw it.. take a look at my code... its very short

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;

class AvinLine
public static void main(String[] args)
JFrame frame = new JFrame();
JPanel pane = new JPanel();
Line2D myLine = new Line2D.Double(5,5,100,100);


Ok how do i draw the line without creating another class .. and the JPanel and JFrame must be in the same class.. I am trying to avoid making a new clas that extends JPanel. I do not want to add another class. The line must be added within this class. And i am also trying to avoid the "paint(Graphics g)" method. Is there anyway to add the line to the JPanel and then add the panel to the JFrame.

Because I find it dificult to believe that Java is such a powerful language that you have to call a "paint(Graphics g)" method and create another class just to draw a simple line.

Thanks for the help in advance..


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us