java

位置:IT落伍者 >> java >> 浏览文章

实现鼠标画图的Java程序


发布日期:2018年06月03日
 
实现鼠标画图的Java程序

import javaawtColor;

import javaawtFrame;

import javaawtGraphics;

import javaawtPoint;

import javaawteventMouseAdapter;

import javaawteventMouseEvent;

import javaawteventMouseListener;

import javautilArrayList;

import javautilIterator;

public class MyMouseAdapter {

public static void main(String[] args) {

new MyFrame(drawing);

}

}

class MyFrame extends Frame{

ArrayList points=null;

MyFrame(String s){

super(s);

points=new ArrayList();

setLayout(null);

setBounds();

thissetBackground(new Color());

setVisible(true);

thisaddMouseListener(new Monitor());

}

public void paint(Graphics g){

Iterator i=erator();

while(ihasNext()){

Point p=(Point)inext();

gsetColor(Colorblue);

gfillOval(pxpy );

}

}

public void addPoint(Point p){

pointsadd(p);

}

}

class Monitor extends MouseAdapter{ //MouseAdapter实现了MouseListener接口

public void mousePressed(MouseEvent e){

MyFrame f=(MyFrame)egetSource();

faddPoint(new Point(egetX()egetY()));

frepaint(); //让Frame强制经行重画

}

}

               

上一篇:深入Java核心 Java内存分配原理精讲

下一篇:java中使用MD5加密算法进行加密