📄 鼠标自由作画.java
字号:
/* * 鼠标自由作画.java * * Created on 2004年9月24日, 上午11:40 *//** * * @author litertiger */import java.awt.*;import java.awt.event.*;public class 鼠标自由作画 extends java.applet.Applet implements MouseMotionListener { /** Initialization method that will be called after the applet is loaded * into the browser. */ int x=-1,y=-1; public void init() { setBackground(Color.green); addMouseMotionListener(this); // TODO start asynchronous download of heavy resources } public void paint(Graphics g) { if(x!=-1&&y!=-1) { g.setColor(Color.red); g.drawLine(x,y,x+1,y+1);//画一个点 } } public void mouseDragged(MouseEvent e) { x=(int)e.getX();//获得鼠标的坐标 y=(int)e.getY(); repaint();//调用repaint()函数重画 } public void mouseMoved(MouseEvent e) { } public void update(Graphics g) { paint(g);//我们重写了这个update这个方法 //主要是防止调用父类的 update的方法 //怕把以前的的画给删了 } // TODO overwrite start(), stop() and destroy() methods}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -