Graphics 问题 急!!!
我写了个画线法的程序,想从键盘接受起始坐标。但是,程序在
E:\作业练习\Graphic Class\Line\DDALine.java:51: ') ' expected
DDA_Line add=new DDA_Line(coordinate[0],coordinate[1],coordinate[2],coordinate[3],Graphics g);
地方提示出错。请各位帮小弟看看谢谢!!!!
下面是我的程序:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import java.io.*;
public class DDALine extends Applet
{
//int bx,by,ex,ey;
//Color c;
public void init ()
{
//接受起始坐标
}
public void paint(Graphics g)
{
int coordinate [];
coordinate=new int [4]; //存放 起始坐标
String [] inx=new String[4];
System.out.print( "Please enter the coordinate (bx,by)and(ex,ey): ");//键盘接受 起始坐标
try
{
InputStreamReader std=new InputStreamReader(System.in);
BufferedReader stdin=new BufferedReader(std);
for(int i=0;i <4;i++)
{
inx[i]=stdin.readLine();
coordinate[i]=Integer.parseInt(inx[i]);
}
for(int j=0;j <coordinate.length;j++)//打印出输入的坐标
{
System.out.print(coordinate[j]+ " ");
}
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
DDA_Line add=new DDA_Line(coordinate[0],coordinate[1],coordinate[2],coordinate[3],Graphics g);
}
catch(Exception e)
{
}
//调用DDA_Line类的构造方法 方法
//DDA_Line(100,200,300,450,g);
}
}
class DDA_Line
{
void DDA_Line(int bx,int by,int ex,int ey,Graphics g) //DDA_Line() 方法
{
float x,y,dx,dy,k;
int temp;
dx=ex-bx;
dy=ey-by;
g.setColor(Color.red);
if(dx==0) //当分母 dx=0时
{
if(by> ey)
{
temp=bx; bx=ex; ex=temp; temp=by; by=ey; ey=temp; //起始坐标互换
}
x=bx;
for(y=by;y <ey;y++)
{
g.drawString( ". ",(int)x,(int)y);
}
}
else
// dx不等于零时
{
k=dy/dx;
if(Math.abs(k) <=1) //当斜率 0 <k <=1 或 -1 <k <0 时
{
if(bx> ex)
{
temp=bx; bx=ex; ex=temp; temp=by; by=ey; ey=temp; //起始坐标互换
}
y=by;
for(x=bx;x <ex;x++)
{
g.drawString( ". ",(int)x,(int)Math.rint(y+0.5));
y=y+k;
}
}
if(Math.abs(k)> 1) //当斜率 k> 1 或 k <-1时
{
if(by> ey)