import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class DrawLineFrame extends JFrame {
DrawLinePanel linePanel = new DrawLinePanel();
public static void main(String args[]) {
DrawLineFrame frame = new DrawLineFrame();
frame.setVisible(true);
}
public DrawLineFrame() {
super();
setTitle("绘制直线");
setBounds(100, 100, 273, 167);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(linePanel);
}
class DrawLinePanel extends JPanel {
public void paint(Graphics g) {
g.drawLine(70, 50, 180, 50);
g.drawLine(70, 80, 180, 80);
g.drawLine(110, 10, 140, 120);
}
}
}