Applet小应用

来源:互联网 发布:volt模板引擎 php 编辑:程序博客网 时间:2024/05/21 21:47

设计和编写一个可以用鼠标操作的Applet小应用程序和相应的HTML页面,观察Applet的执行过程,测试程序鼠标用户交互操作的效果。

在小应用中鼠标点击的地方画一个圆。

import java.applet.Applet;import java.awt.Color;import java.awt.Event;import java.awt.Graphics;import java.awt.Graphics2D;public class test extends Applet{int cx=10;int cy=10;public boolean mouseDown(Event e,int x,int y){cx=x;cy=y;repaint();return true;}public void paint(Graphics g){Graphics2D g2=(Graphics2D)g;g2.setColor(Color.orange);g2.fillOval(cx, cy, 10, 10);}}
嵌入网页

<html><head><title>applet应用</title></head><body><applet code="test.class" width="200" height="200"></applet></body></html>



0 0
原创粉丝点击