title: How do you draw a line with Java?
body: <p>I'm trying to draw a line and just can't figure it out. I actually need to draw a triangle for my computer science lab. I'm very new to programming, going off of Big Java book by Horstmann. It's unclear on how to exactly draw something and I'm just not getting it. First it introduces a "EmptyFrameViewer" and says its the "essential plumping" to show a frame, which I can get to work. I have a frame pop up but have never get anything to draw on the frame. The following is my code and all I get is a 500x500 frame. Can anyone help me? I just want a line! once I have a line I'm sure I can figure out how to draw more things.</p>
  
  <pre><code>import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.geom.Line2D;
  import javax.swing.JComponent; 
  import javax.swing.JFrame;
  
  public class DrawFrame extends JComponent 
  {
  public void lineComponent (Graphics g)
  {
      Graphics2D g2 = (Graphics g);
      Line2D.Double line1 = new Line2D.Double(30, 110, 80, 110);
      g2.draw(line1);
  }
  
  public static void main(String[] args) 
  {
      JFrame frame = new JFrame();
      frame.setSize(500, 500);
      frame.setTitle("BE A LINE");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      DrawFrame component = new DrawFrame();
      frame.add(component);
      frame.setVisible(true);
  
  }
  
  }
  </code></pre>