class testframe extends JFrame {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setContentPane(new graphics());
}
}
class graphics extends JPanel {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawLine(0, 0, 120, 120);
g.setColor(Color.GREEN);
}
}
g.drawLine(20,20,100,150);你再试试!