📄 buttonbar.java
字号:
import java.awt.*;
import java.net.*;
import java.awt.image.*;
public class ButtonBar extends java.applet.Applet implements Runnable {
//Parsed vars
static int[] msgnum, x1, x2, y1, y2;
static int[] mapx1, mapx2, mapy1, mapy2;
static String[][] msgtext;
static String fontname;
static int fontsize, buttnum;
static boolean[] left;
static String[][] textURL;
String click;
Color textColor = Color.blue;
int globalX, globalY;
int curButt = 0, cnt = 100;
int[] maxtextWidth;
int fheight;
int[][] msgtextWidth;
Image image, ring, offscreen;
Graphics gc, g;
MediaTracker mt;
Thread juicer = null;
boolean[] buttOn;
boolean buttPushed = false;
FontMetrics fm;
Font font;
public void init() {
ButtonBarParseArgs bbpa = new ButtonBarParseArgs(this);
offscreen = createImage(473, 260);
gc = offscreen.getGraphics();
mt = new MediaTracker(this);
image = getImage(getCodeBase(), "images/sis_frontnav2.jpg");
ring = getImage(getCodeBase(), "images/ring.gif");
mt.addImage(image, 0);
mt.addImage(ring, 0);
try {
mt.waitForAll();
}
catch(InterruptedException e) {
System.out.println("interrupted load of images");
}
font = new Font(fontname, Font.BOLD, fontsize);
fm = gc.getFontMetrics(font);
fheight = fm.getMaxAscent() - fm.getMaxDescent() +5;
msgtextWidth = new int[buttnum][10];
maxtextWidth = new int[buttnum];
x2 = new int[buttnum];
y2 = new int[buttnum];
buttOn = new boolean[buttnum];
for (int j = 0; j <buttnum; j++) {
for( int i = 0; i < msgnum[j]; i++) {
msgtextWidth[j][i] = fm.stringWidth(msgtext[j][i]);
if (maxtextWidth[j] < msgtextWidth[j][i]) maxtextWidth[j]
= msgtextWidth[j][i];
}
y2[j] = fheight * msgnum[j];
x2[j] = x1[j] + maxtextWidth[j];
}
}
public void start() {
if(juicer == null) {
juicer = new Thread(this);
juicer.start();
}
}
public void stop() {
if ( (juicer != null) && (juicer.isAlive()) ) {
juicer.stop();
juicer = null;
}
}
public void run() {
int i;
boolean noButtOn;
gc.drawImage(image, 0, 0, this);
gc.setFont(font);
while (true) {
noButtOn = true;
if (cnt < 50){ i = cnt;
if( left[i] ) x1[i] = mapx1[i] - maxtextWidth[i];
else x1[i] = mapx2[i];
y1[i] = (mapy1[i] + mapy2[i])/2 - fheight * msgnum[i];
gc.drawImage(image, 0, 0, this);
gc.setColor(Color.red);
gc.setColor(Color.white);
gc.drawImage(ring, mapx1[i], mapy1[i], 59, 59, this);
gc.fillRect(x1[i] - 10, y1[i], x2[i] + 15, y2[i] + 5);
gc.setColor(Color.black);
gc.drawRect(x1[i] - 10, y1[i], x2[i] + 14, y2[i] + 4 );
for( int j = 0; j < msgnum[i]; j++) {
if(globalY < y1[i] + fheight + fheight * j &&
globalY > y1[i] + fheight * j)
{
click = textURL[i][j];
gc.setColor(Color.red);
gc.fillOval(x1[i] - 8, y1[i] + fheight/2 + fheight * j, 4, 5);
gc.setColor(textColor);
showStatus(textURL[i][j]);
}
gc.drawString(msgtext[i][j], x1[i] + 2,
y1[i] + fheight + fheight * j);
gc.setColor(Color.black);
gc.drawOval(x1[i] - 8, y1[i] + fheight/2 + fheight * j, 4, 5);
}
noButtOn = false;
}
repaint();
try { juicer.sleep(60); }
catch(InterruptedException e) { }
if (cnt==100) {
showStatus("Copyright 1997 Southern Internet");
gc.drawImage(image, 0, 0, this);
}
}
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
g.drawImage(offscreen, 0, 0, this);
}
public boolean mouseMove(Event evt, int x, int y) {
globalX = x;
globalY = y;
// System.out.println("x: " + x + " y: " +y);
// System.out.println(cnt);
buttPushed = false;
boolean someButtOn = false;
for ( int i=0; i < buttnum; i++ ) {
if (buttPushed) buttOn[i] = false;
else {
if ( x > mapx1[i] && x < mapx2[i] && y > mapy1[i] && y < mapy2[i] ) {
buttOn[i] = true;
someButtOn = true;
cnt = i;
}
else if ( !left[i] && buttOn[i] && x > mapx2[i] - 15 &&
x < mapx2[i] + maxtextWidth[i] + 5 &&
y > (mapy2[i] + mapy1[i])/2 - fheight * msgnum[i] &&
y < (mapy2[i] + mapy1[i])/2 + 10) {
for(int s=0; s < buttnum; s++) {
buttOn[s] = false;
}
buttOn[i] = true; cnt = i;
someButtOn = true;
buttPushed = true;
}
else if ( left[i] && buttOn[i] && x > mapx1[i] - maxtextWidth[i] -10&&
x < mapx1[i] + 20 &&
y > (mapy2[i] + mapy1[i])/2 - fheight * msgnum[i] &&
y < mapy2[i] ) {
for(int k=0; k < buttnum; k++) {
buttOn[k] = false;
}
buttOn[i] = true; cnt = i;
someButtOn = true;
buttPushed = true;
}
else buttOn[i] = false;
}
}
if (!someButtOn) cnt = 100;
return(true);
}
public boolean mouseUp( Event evt, int x , int y )
{
try
{ URL thingee = new URL(click);
getAppletContext().showDocument(thingee);
}
catch (MalformedURLException e)
{ System.out.println("hey I caught it!!!");
System.out.println(click + " exception");
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -