62,614
社区成员
发帖
与我相关
我的任务
分享
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class DrawLine extends JFrame {
private Thread t;
public DrawLine(){
setBounds(600,300,600,400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Graphics graphics = getGraphics();
graphics.setColor(Color.RED);
for(int y=50;y<100;y++){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
graphics.drawLine(30, y, 100, y);
y++;
}
}
public static void main(String[] args) {
new DrawLine();
}
}