944,161 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 42370
  • Java RSS
Feb 21st, 2005
0

How to draw a line

Expand Post »
HI,

All I want to do is put a straight line under my 3 labels which I have loaded into a JFrame.

After my JFrame has loaded I use the method repaint() which is supposed to call:

public void paintComponent(Graphics comp) {
Graphics2D comp2D = (Graphics2D)comp;
comp2D.drawLine(0,60,100,60);

}

Which does not draw my line. The method repaint() does not even allow me to go to the method paintComponent(Graphics comp). What am I doing wrong

Any help would be appreciated
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bsunkel is offline Offline
12 posts
since Nov 2004
Feb 21st, 2005
0

Re: How to draw a line

This is how I do my lines but I just started java a month ago and it is the only way I have been introduced to.
public void paint(Graphics g) {
g.drawLine(25, 0, 25, 50);
g.setColor(Color.black);
Reputation Points: 16
Solved Threads: 9
Master Poster
OurNation is offline Offline
780 posts
since Aug 2004
Jun 1st, 2011
0
Re: How to draw a line
public void draw (Graphics g)

function is not supported for the JFrame. Indeed JFrame does not have any painting capability.

You can either use the draw function for Applets or you can use a Swing component with draw capability like JPanel.

Below code should work :

Java Syntax (Toggle Plain Text)
  1. import javax.swing.*;
  2. import java.awt.*;
  3. public class cizim extends JPanel{
  4. //www.bilgisayarkavramlari.com
  5. public void paintComponent(Graphics g){
  6. g.drawLine(0,0,90,90);
  7. }
  8. public static void main(String args[]){
  9. JFrame jf = new JFrame();
  10. jf.add(new cizim());
  11.  
  12.  
  13. jf.setSize(500,500);
  14. jf.setVisible(true);
  15. }
  16. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shedai is offline Offline
2 posts
since Jun 2011
Jun 1st, 2011
0
Re: How to draw a line
Don't post in tool old dead threads if you have any new thing to share then create a new thread
Reputation Points: 219
Solved Threads: 122
Postaholic
abelLazm is offline Offline
2,085 posts
since Feb 2011
Jun 1st, 2011
2
Re: How to draw a line
>> Don't post in tool old dead threads if you have any new thing to share then create a new thread

There's nothing in the rules that forbids people to post in an old thread as long as the reply is on-topic and not just another question (thread-hijacking).
The post made by "shedai" is on-topic and might help people who have the same problem and find this thread on google.
Last edited by Nick Evan; Jun 1st, 2011 at 6:55 am.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in Java Forum Timeline: Update JTable and data on the go
Next Thread in Java Forum Timeline: problem installing JCE





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC