文档详情

java实验报告5.doc

发布:2017-02-14约字共5页下载文档
文本预览下载声明
《java实验报告》 班级:10电信实验班 学号:姓名:王彬彬 1:题目 (1).编写Applet程序,其中包含一个滚动的字符串,字符串从左到右运动,当所有的字符都从屏幕的右边消失后,字符串重新从左边出现并继续向右移动。 (2).编写一个Applet内部显示一个蓝色反弹球的程序,通过一个事件使该球开始运动,在该球撞击Applet边框时,它应从边框弹回并以相反的方向运动。 2:实验目的 编写applet程序,利用runnable接口实现多进程操作 功能说明 .编写java applet,实现滚动的字母操作 .实现蓝色球的反弹 设计流程图 Applet start---run---获得进程--paint操作 代码实现 . import java.awt.*; import java.text.MessageFormat; import java.util.*; import javax.swing.*; import java.applet.*; import java.awt.event.*; public class hefu extends Applet implements Runnable { Thread hf; int count; String msg=WELCOME TO ZSTU; int x1,y1,wi; int s; public void start() { if(hf == null) { hf = new Thread(this); hf.start(); } } public void run() { // TODO Auto-generated method stub count = msg.length(); x1=count; y1=count-1; wi=20; s=0; while(true) { repaint(); try { Thread.sleep(500); } catch(InterruptedException e) { } } } public void paint(Graphics g) { String str = new String(); str = msg.substring(y1,x1); g.drawString(str, 20, 100); if(y10s==0) y1--; else { if(y1=0s!=count) { msg = +msg; s++; } else { msg = msg.substring(count, count*2); y1=count-1; s=0; } } } public void stop() { hf.stop(); hf = null; } } . import java.awt.*; import java.text.MessageFormat; import java.util.*; import javax.swing.*; import java.applet.*; import java.awt.event.*; public class tanqiu extends Applet implements Runnable { private static final long serialVersionUID = 1L; int mm = 20; int n = 8; int w = 25; int [][] b = new int [n][2]; int [] x = new int [n]; int [] y = new int [n]; int height; int width; Image OffScreen; Graphics drawOffScreen; public void run() { while(true) { repaint(); try{ Thread thread = Thread.currentThread(); String threadName = thread.getName(); int i = Integer.parseInt(threadName.substring(6,threadName.length())); System.out.println(Thread.currentThread().getName());
显示全部
相似文档