0

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

Edited by happygeek: fixed formatting

5
Contributors
4
Replies
13
Views
11 Years
Discussion Span
Last Post by Nick Evan
Featured Replies
  • 2

    >> 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 … Read More

0

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);

Edited by happygeek: fixed formatting

0

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 :

import javax.swing.*;
import java.awt.*;
public class cizim extends JPanel{
  //www.bilgisayarkavramlari.com
  public void paintComponent(Graphics g){
    g.drawLine(0,0,90,90);
  }
  public static void main(String args[]){
    JFrame jf = new JFrame();
    jf.add(new cizim());


    jf.setSize(500,500);
    jf.setVisible(true);
  }
}
2

>> 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.

Edited by Nick Evan: n/a

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.