标题:请教一个小问题
取消只看楼主
lw8484654
Rank: 1
等 级:新手上路
帖 子:223
专家分:0
注 册:2005-12-1
 问题点数:0 回复次数:0 
请教一个小问题

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TestMouseLine extends JFrame
{
int x,y;
int endX,endY;
public TestMouseLine()
{
Container c=getContentPane();

addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
x=e.getX();
y=e.getY();
}
});

addMouseMotionListener(new MouseMotionAdapter()
{
public void mouseDragged(MouseEvent e)
{
endX = e.getX();
endY = e.getY();
repaint();
}
});

addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});

setSize(400,300);
setLocation(400,300);
show();
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.red);
g.drawLine(x,y,endX,endY);
}

public static void main(String[] args)
{
new TestMouseLine();
}
}
super.paint(g);这句话是什么意思呢?为什么加了这句话就只能画一条线呢?如果要用鼠标控制画更多的线应该怎么弄呢?

搜索更多相关主题的帖子: public import 
2006-06-21 23:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-73984-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.080305 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved