以下是我的代码,请各位帮忙调试!谢谢啦!我的想用CANVAS画一条直线!接受输入数据,然后画线!
import java.awt.*;
import java.awt.event.*;public class PaintLine  { public static void main(String [] args)
{
int x1=0,y1=0,x2=0,y2=0;
CanvasD cd=new CanvasD(x1,y1, x2, y2);
new FrameInOut(cd  );
}
}class  FrameInOut extends Frame implements MouseListener
{
Label prompt1,prompt2;
TextField t1,t2;
Button btn1;
public FrameInOut(CanvasD cd)
{
super("画直线");
prompt1=new Label("请输入x2:");
prompt2=new Label("y2:");
t1=new TextField(10);
t2=new TextField(10);
btn1=new Button("画线");
int x1=0,y1=0,x2=100,y2=100;
CanvasD cd1=new CanvasD(x1,y1, x2, y2);

setLayout(new FlowLayout());
add(prompt1);
add(t1);
add(prompt2);
add(t2);
add(btn1);
add(cd);
btn1.addMouseListener(this);
addWindowListener(new HandleWin());
setSize(500,500);
setVisible(true);
}
public void mouseClicked(MouseEvent e)
{
if(e.getSource()==btn1)
{


x2=Integer.parseInt(t1.getText());
y2=Integer.parseInt(t2.getText());
}
}

public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}


}
class CanvasD extends Canvas
{
static int a1,b1,a2,b2;
static
{
a1=0;
a2=0;
b1=0;
b2=0;
}
 static int x1,y1,x2,y2;
CanvasD(int a1,int b1,int  a2,int b2)
{
x1=a1;
y1=b1;
x2=a2;
y2=b2;
setBackground(Color.gray);
  setSize(300,300);

}

public void paint(Graphics g)
{
g.drawLine(x1,y1,x2,y2);
repaint();
} setSize(300,300);
} }

}
class HandleWin extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
(e.getWindow()).dispose();
System.exit(0);
}
}