?? scroller.java
字號:
/*
Basic horizontal scrolling text applet, with optional URL link
Parameters (see also WebBase):
SCROLLTEXT Message to display
def: "No message supplied!"
SHADOW "Shadow" text
def: false (no shadow)
URL the URL to jump to when the applet is clicked
by a mouse
def: none - if none supplied or invalid, it's just a scrolling
text applet
Copyright 1998 by E. A. Graham, Jr.
Free to use or modify.
*/
import java.awt.*;
import java.applet.*;
import java.net.URL;
import java.net.MalformedURLException;
public class Scroller extends WebBase {
String message;
int messageX = 0,messageY = 0; // Coordinates of the scrolling text
int messageW = 0; // Width of the message in pixels
public Font messageF; // Font for the message (TimesRoman only)
boolean font3D; // draw a drop-shadow on the message
String urlName; // string for URL to link to
URL nextURL = null; // the actual URL
// initialization time!
public void init() {
super.init();
// get the HTML parameters or set to defaults
String tparam;
tparam = readMessage();
message = (tparam == null) ? new String("No message supplied!") : new String(tparam);
tparam = ReadText("SHADOW");
font3D = (tparam == null) ? false : tparam.equalsIgnoreCase("true");
urlName = ReadText("URL");
if (urlName != null) {
try {
if (urlName.indexOf("http://") < 0) {
nextURL = new URL(getDocumentBase(),urlName);
}
else {
nextURL = new URL(urlName);
}
}
catch (MalformedURLException e) {};
}
borderWidth = Math.abs(borderWidth);
// set up the font and initial positions
setFontValues();
}
public void stop() {
super.stop();
messageX = maxWidth;
}
// draw the stuff
public synchronized void update(Graphics g) {
if(loaded) {
super.update(g);
//...then draw shadow copy of text...
if (font3D) {
Color foreColorD1,foreColorD2;
foreColorD1 = foreColor.darker();
foreColorD2 = foreColorD1.darker();
appGC.setColor(foreColorD2);
appGC.drawString(message, messageX+2, messageY+2);
appGC.setColor(foreColorD1);
appGC.drawString(message, messageX+1, messageY+1);
}
//...then draw the text...
appGC.setColor(foreColor);
appGC.setFont(messageF);
appGC.drawString(message, messageX, messageY); // clipping is wonderful!
//...next comes the border...
drawBorder(maxWidth,maxHeight,borderWidth);
//...fade the edges
g.drawImage(appImage, 0, 0, this);
}
}
public boolean handleEvent(Event event) {
return super.handleEvent(event);
}
// method that can be over-ridden to supply the message text
protected String readMessage() {
String tmsg;
tmsg = ReadText("ScrollText");
return tmsg;
}
void setFontValues() {
messageF = appFont((maxHeight - (2 * borderWidth)),Font.BOLD);
FontMetrics fm = getFontMetrics(messageF);
messageX = maxWidth;
messageY = ((maxHeight-fm.getHeight()) >> 1) + fm.getAscent() - 1;
messageW = fm.stringWidth(message);
}
synchronized void doAppThing() {
messageX -= scrollUnit; //scrollUnit is the incremental distance of scrolling
if((messageX + messageW) < 0) messageX = maxWidth;
}
public boolean mouseDown(Event e,int x, int y) {
borderWidth = -borderWidth;
return true;
}
public boolean mouseUp(Event e,int x, int y) {
borderWidth = -borderWidth;
if (nextURL !=null) {
getAppletContext().showDocument(nextURL,frameTarget);
}
return true;
}
public boolean mouseEnter(Event e,int x,int y) {
if (nextURL != null) showStatus("Link to " + urlName);
return true;
}
public boolean mouseExit(Event e,int x,int y){
showStatus("");
return true;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -