大学职业搜题刷题APP
下载APP
首页
课程
题库模板
Word题库模板
Excel题库模板
PDF题库模板
医考护考模板
答案在末尾模板
答案分章节末尾模板
题库创建教程
创建题库
登录
logo - 刷刷题
创建自己的小题库
搜索
【简答题】

本题是一个Applet,功能是用鼠标画不同颜色的图形。页面中有5个按钮“画红色图形”、“画绿色图形”、“画蓝色图形”、“橡皮”和“清除”,单击前三个按钮中的一个,按住鼠标左键或右键在而板中拖动,就能画出对应颜色的线条,单击“橡皮”按钮,按住鼠标左键或右键在面板中拖动就能将面板中的图形擦除掉,单击“清除”按钮,就能将面板中所有的图形清除掉。
import java.applet.*;
import java.awt.*;
import java.awt..*;
public class java3 extends Applet implements ActionListener
int x=-1,y=-1,rubberNote=0,clearNote=0;
Color c=new Color(255,0,0);
int con=3;
Button b_red,b_blue,b_green,b_clear,b_quit;
public void init()
addMouseMotionListener(this);
b_red=new Button("画红色图形");
b_blue=new Button("画蓝色图形");
b_green=new Button("画绿色图形");
b_quit=new Button("橡皮");
b_clear=new Button("清除");
add(b_red);
add(b_green);
add(b_blue);
add(b_quit);
add(b_clear);
b_red.addActionListener(this);
b_green.addActionListener(this);
b_blue.addActionListener(this);
b_quit.addActionListener(this);
b_clear.addActionListener(this);
public void paint()
if(x!=-1&&y!=-1&&rubberNote==0&&clearNote==0)
g.setColor(c);
g.fillOval(x,y,con,con);
else if(rubberNote==1&&clearNote==0)
g.clearRect(x,y,10,10);
else if(clearNote==1&&rubberNote==0)
(g.clearRect(0,0,getSize().width,getSize().height);

public void mouseDragged(Mouse e)
x=(int)e.getX();y=(int)e.getY();repaint();
public void mouseMoved(Mouse e)
public void update(Graphics g)
paint(g);
public void actionPerformed( e)
if(e.getSource()==b_red)
rubberNote=0;clearNote=0;c=new Color(255,0,0);
else if(e.getSource()==b_green)
rubberNote=0;clearNote=0;c=new Color(0,255,0);
else if(e.getSource()==b blue)
rubberNote=0;clearNote=0;c=new Color(0,0,255);
if(e.getSource()==b_quit)
rubberNote=1;clearNote=0;
if(e.getSource()==b_clear)
clearNote=1;rubberNote=0;repaint();

手机使用
分享
复制链接
新浪微博
分享QQ
微信扫一扫
微信内点击右上角“…”即可分享
反馈
收藏 - 刷刷题收藏
举报
参考答案:
举一反三
相关题目:
刷刷题-刷题-导入试题 - 刷刷题
参考解析:
AI解析
重新生成
题目纠错 0
发布
刷刷题-刷题-导入试题 - 刷刷题刷刷题-刷题-导入试题 - 刷刷题刷刷题-刷题-导入试题 - 刷刷题
刷刷题-刷题-导入试题 - 刷刷题
刷刷题-刷题-导入试题 - 刷刷题
刷刷题-单词鸭