java中graphics类划线的问题

2025-02-26 19:43:58
推荐回答(2个)
回答1:

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

回答2:

g.drawLine(20,20,100,150);你再试试!