?? dda.java
字號:
import java.awt.*;
import java.applet.Applet;
public class dda extends Applet
{int x0,x1,y0,y1;
public void init(){
x0=Integer.parseInt(getParameter("x0"));
y0=Integer.parseInt(getParameter("y0"));
x1=Integer.parseInt(getParameter("x1"));
y1=Integer.parseInt(getParameter("y1"));
}
public void paint(Graphics g)
{
float dx=x1-x0;
float dy=y1-y0;
float m=dy/dx;
float y;
int x,n; //n為x值的最大值
if(x1>x0) //當終點橫坐標大于起點橫坐標
{
x=x0; //畫線從橫坐標小的點出發
n=x1; //到橫坐標大的點結束
y=y0;
}
else
{
x=x1;
n=x0;
y=y1;
}
g.setColor(Color.blue); //設置畫筆顏色
for(;x<=n;x++)
{g.drawString(".",x,(int)(y+0.5)); //y值取整,并畫點(x,y)
y+=m;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -