Drawing a Line 1 import java.awt.Graphics; 2 import javax.swing.JFrame; 3 import javax.swing.JPanel; 4 5 public class Test extends JFrame { 6 public Test() { 7 super( Graphics Example ); 8 add(new NewPanel()); 9 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 10 setSize(250, 225); 11 setLocationRelativeTo(null); 12 setVisible(true); 13 } 14 15 public static void main(String args[]) { 16 Test t = new Test(); 17 } 18 } 19 20 class NewPanel extends JPanel { 21 protected void paintComponent(Graphics g) { 22 super.paintComponent(g); 23 g.drawLine(0, 0, 100, 50); 24 } 25 } USC CSCI 201L10/23 Graphics
{}