📄 simtoolbar.java
字号:
import java.awt.*;
import java.net.*;
import java.applet.*;
import java.awt.event.*;
import java.util.StringTokenizer;
public class SimToolBar extends Applet implements MouseListener{
private MediaTracker myTracker;
private Image enterImage, exitImage;
private boolean onButton = false;
private boolean clickButton = false;
private int onImages = 0;
private URL myURL;
private String target, myString, where;
public void init(){
if ((myString = getParameter("where")) != null)
where = myString;
else
where = null;
myTracker = new MediaTracker(this);
enterImage = getImage(getDocumentBase(), getParameter("enterImage"));
myTracker.addImage(enterImage, 0);
exitImage = getImage(getDocumentBase(), getParameter("exitImage"));
myTracker.addImage(exitImage, 0);
try {
myTracker.waitForAll();
} catch (InterruptedException e) {}
target = getParameter("target");
try{
myURL = new URL(getDocumentBase(), target);
System.out.println(target);
}catch(MalformedURLException mal){}
addMouseListener(this);
}
public void start(){
repaint();
}
public void mouseClicked(MouseEvent e){
}
public void mousePressed(MouseEvent e){
clickButton = true;
repaint();
}
public void mouseReleased(MouseEvent e){
if(clickButton && onButton){
clickButton = false;
repaint();
if (where != null)
getAppletContext().showDocument(myURL, where);
else
getAppletContext().showDocument(myURL);
}else{
clickButton = false;
repaint();
}
}
public void mouseEntered(MouseEvent e){
onButton = true;
repaint();
}
public void mouseExited(MouseEvent e){
onButton = false;
repaint();
}
public void drawImg(Graphics g, Image theImage){
int a;
if (onImages == 3)
a = 1;
else
a =0;
int imageWidth = theImage.getWidth(this);
int imageHeight = theImage.getHeight(this);
int imageX = (getSize().width / 2) - (imageWidth / 2);
int imageY = (getSize().height / 2) - (imageHeight / 2);
imageY = (getSize().height / 2) - ( imageHeight / 2 ) + 2;
g.drawImage(theImage, imageX+a, imageY+a, this);
}
public void drawButton(Graphics g){
Color topAndLeft;
Color bottomAndRight;
if (onImages == 2){
topAndLeft = Color.lightGray;
bottomAndRight = Color.darkGray;
}
else{
topAndLeft = Color.darkGray;
bottomAndRight = Color.lightGray;
}
g.setColor(topAndLeft);
g.drawLine(0, 0, getSize().width, 0);
g.drawLine(0, 1, 0, getSize().height);
g.setColor(bottomAndRight);
g.drawLine(getSize().width - 1, 1, getSize().width - 1, getSize().height);
g.drawLine(1, getSize().height - 1, getSize().width, getSize().height - 1);
}
public void paint(Graphics g){
if(!onButton){
onImages = 1;
drawImg(g, exitImage);
}
else if (onButton && !clickButton) {
onImages = 2;
drawButton(g);
drawImg(g, enterImage);
}
else {
onImages = 3;
drawButton(g);
drawImg(g, enterImage);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -