求助,这段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();
}
} 展开
* @(#)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();
}
} 展开
1个回答
展开全部
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();
}
}
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();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询