求助,这段java程序哪里错了<一个具有画图功能的小程序>

/***@(#)DrawTest.java***@author*@version1.002007/4/18*/importjava.awt.*;importjava.aw... /**
* @(#)DrawTest.java
*
*
* @author
* @version 1.00 2007/4/18
*/

import java.awt.*;
import java.awt.event.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class DrawTest extends AppletTest
{
public static int x0,y0;
public static void main (String[] args) {

Frame f=new Frame("画图");
f.setBackground(Color.blue);
f.setLocation(300,300);
f.setSize(400,400);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
x0=e.getX();
y0=e.getY();
}
public void mouseReleased(MouseEvent e)
{
try {
Graphics g=getGraphics();
g.setColor(Color.red);
g.drawLine(x0,y0,e.getX(),e.getY());
}
catch (Exception ex) {
System.out.println(ex.toString());
}

}
}
);
f.show();

}

}
展开
 我来答
SprainRain
2007-04-22
知道答主
回答量:3
采纳率:0%
帮助的人:0
展开全部
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class DrawTest {
public static int x0, y0;

public static void main(String[] args) {

final Frame f = new Frame("draw");
f.setBackground(Color.blue);
f.setLocation(300, 300);
f.setSize(400, 400);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.addMouseListener(new MouseAdapter() {

public void mousePressed(MouseEvent e) {
x0 = e.getX();
y0 = e.getY();
}

public void mouseReleased(MouseEvent e) {
try {
Graphics g = f.getGraphics();
g.setColor(Color.red);
g.drawLine(x0, y0, e.getX(), e.getY());
} catch (Exception ex) {
System.out.println(ex.toString());
}

}
});
f.show();

}

}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式