📄 showinfo.java
字号:
package showinfo;import java.awt.*;import java.awt.event.*;import java.applet.*;import java.util.*;/** * Title: Applet显示滚动信息 * Description: 在浏览器页面左上角滚动信息,鼠标移动上去即停止滚动,移开则继续滚动。 * Copyright: Copyright (c) 2002 * Company: 北京师范大学计算机系 * @author 孙一林 * @version 1.0 */public class ShowInfo extends Applet implements Runnable, MouseListener{ Thread thread; private int y; private Image offImg; // 定义缓冲图象变量 private Graphics offG; boolean pause = false; // 暂停标志 private int info_num; // 定义输入参数个数 public void init() { setBackground(Color.orange); // 设置Applet的背景 addMouseListener(this); // 增加鼠标监听 offImg = createImage(getSize().width, getSize().height); // 创建缓冲图象大小 offG = offImg.getGraphics(); y=getSize().height+14; // 设置初始值为Applet的高度 try { // 取HTML网页中的参数 info_num = Integer.parseInt(getParameter("info_num")); } catch(Exception e) { showStatus("参数错误!"); // 在IE的状态栏目中显示错误信息 System.exit(-1); } } public void paint(Graphics g) { offG.clearRect(0,0, getSize().width, getSize().height); // 显示到缓冲区中 for(int i=1; i<=info_num; i++) // 显示信息 offG.drawString(getParameter("info_"+String.valueOf(i)),10,y+(i*14)); if(offG!=null) g.drawImage(offImg,0,0,this); } public void update(Graphics g) { // 防止画面闪烁 paint(g); } public void run() { Thread current = Thread.currentThread(); while (thread == current) { try { Thread.currentThread().sleep(100); // 暂时1秒 } catch (InterruptedException e) {} repaint(); if(!pause) y--; if(y<0-info_num*14) y=getSize().height+14; } } public void start() { thread = new Thread(this); // 启动线程 thread.start(); } public void stop() { thread = null; // 停止线程序 removeMouseListener(this); // 删除鼠标监听 } public void mouseEntered(MouseEvent e) { // 鼠标监听 pause = true; // 设置暂停 } public void mouseExited(MouseEvent e) { pause = false; // 恢复滚动 } public void mouseReleased(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseClicked(MouseEvent e) {y=0;} public String getAppletInfo() { return "滚动显示信息"; } public String[][] getParameterInfo() { String[][] pinfo = { {"info_num","int","信息数量"}, {"info_X","String","信息,X代表1-->info_num"} }; return pinfo; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -