import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class huatu implements mousemotionlistener,actionlistener{
static final int r=3;
static int ox, oy;
static int flag=1;
public static void main(string arg[]){
jframe f=new jframe("paint");
container p=f.getcontentpane();
p.setlayout(new flowlayout());
jbutton jbutton1 = new jbutton("红");
jbutton jbutton2 = new jbutton("黑");
jbutton jbutton3 = new jbutton("退出");
//graphics g.setcolor(new color(255,0,0));
//buttonevent arg=new buttonevent(arg);
jbutton1.addactionlistener(new huatu());
jbutton2.addactionlistener(new huatu());
jbutton3.addactionlistener(new huatu());
p.addmousemotionlistener(new huatu());
p.add(jbutton1);
p.add(jbutton2);
p.add(jbutton3);
f.setsize(200,200);
f.show();
}
public void actionperformed(actionevent e){
if(e.getactioncommand().equals("红")){
flag=1;
}
else if (e.getactioncommand().equals("黑")){
flag=2;
}
else if (e.getactioncommand().equals("退出"))
system.exit(0);
}
public void mousedragged(mouseevent e){
container c=(container)e.getsource();
graphics g=c.getgraphics();
if (ox>=0) {
if(flag==1){
g.setcolor(new color(168,0,255));
g.drawline(ox,oy,e.getx(),e.gety());}
else
{ g.setcolor(new color(0,0,0));
g.drawline(ox,oy,e.getx(),e.gety());}
}
ox=e.getx();oy=e.gety();
}
public void mousemoved(mouseevent e){
ox=-1;oy=-1;
}
}
java applet 画图板-JSP教程,Java技巧及代码
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » java applet 画图板-JSP教程,Java技巧及代码
相关推荐
- 暂无文章
