I need simplest way to draw a line in java in AWT panel
问题 I need the simplest way to draw a line between to coordinates. Since this drawing line in my code will be repeated more than 200 times in a loop i need the easiest way. I'm drawing the lines in a AWT panel component. 回答1: If you want to switch to Swing you would use the JPanel and overwrite the paintComponent() method. import java.awt.Graphics; import javax.swing.JPanel; public class PanelWithLine extends JPanel { @Override protected void paintComponent(Graphics g) { super.paintComponent(g);