📄 scroll_1.java
字号:
import java.applet.Applet;
import java.awt.* ;
import java.awt.event.*;
public class Scroll_1 extends Applet implements Runnable
{
String text ;
int xpos, realLength, realHeight, width, height, velocity ;
boolean threadSuspended = false ;
Font font ;
Color fgcolor, bgcolor ;
Thread mover ;
Image offScreen ;
Graphics osGraphics ;
public Scroll_1()
{
xpos = 400;
width = 400;
height = 40;
velocity = 5;
threadSuspended = false;
}
public void init()
{
String str = getParameter("text") ;
text = (str != null) ? str : "No text" ;
str = getParameter("fontsize") ;
int fontSize = str == null ? 24 : Integer.parseInt(str) ;
str = getParameter("fontstyle") ;
int fontStyle = Font.PLAIN ;
if (str != null)
{
str.toUpperCase() ;
if (str.compareTo("ITALIC") == 0)
fontStyle = Font.ITALIC ;
else if (str.compareTo("BOLD") == 0)
fontStyle = Font.BOLD ;
}
font = new Font("Serif", fontStyle, fontSize) ;
str = getParameter("velocity") ;
velocity = str == null ? 5 : Integer.parseInt(str) ;
str = getParameter("fgcolor") ;
int c = str == null ? 0 : Integer.parseInt(str, 16) ;
fgcolor = new Color(c) ;
str = getParameter("bgcolor") ;
c = str == null ? 0xffffff : Integer.parseInt(str, 16) ;
bgcolor = new Color(c) ;
width = getSize().width ;
height = getSize().height ;
offScreen = createImage(width, height) ;
}
private void paintText(Graphics g)
{
g.setColor(bgcolor) ;
g.fillRect(0, 0, width, height) ;
g.clipRect(0, 0, width, height) ;
g.setFont(font) ;
g.setColor(fgcolor) ;
FontMetrics fontmetrics = g.getFontMetrics() ;
realLength = fontmetrics.stringWidth(text) ;
realHeight = fontmetrics.getHeight() ;
g.drawString(text, xpos, (height + realHeight) / 2) ;
}
public void paint(Graphics g)
{
paintText(offScreen.getGraphics());
g.drawImage(offScreen, 0, 0, null) ;
}
public void start()
{
if(mover == null)
{
mover = new Thread(this) ;
mover.start() ;
}
}
public void stop()
{
mover = null;
}
private void setcoord()
{
xpos = xpos - velocity;
if(xpos < -realLength) xpos = width;
}
public void run()
{
while(mover != null)
{
try
{
Thread.currentThread().sleep(10L);
}
catch(InterruptedException _ex) { }
setcoord() ;
repaint() ;
}
}
public void update(Graphics g)
{
paint(g) ;
}
public boolean handleEvent(Event event)
{
if(event.id == Event.MOUSE_DOWN)
{
if(threadSuspended)
mover.resume() ;
else
mover.suspend() ;
threadSuspended = !threadSuspended;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -