?? bigger.java
字號:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Bigger extends Applet implements MouseMotionListener {
Graphics g;
Image offi;
Image back;
String picture_name;
MediaTracker imageTracker;
int boxX = 0, boxY = 0;
int boxW = 100, boxH = 100;
int width, height;
public void init(){
g = getGraphics();
picture_name = new String();
picture_name = getParameter("picture_name");
if(picture_name == null)
picture_name = "beautiful.jpg";
imageTracker = new MediaTracker(this);
back = getImage(getCodeBase(),picture_name);
offi = createImage(300,200);
Graphics offg = offi.getGraphics();
offg.drawImage(back, 0, 0, this);
addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent e){
}
public void mouseMoved(MouseEvent e){
redrawGlass(boxX, boxY, e.getX(), e.getY());
boxX = e.getX();
boxY = e.getY();
if(boxX > (width - boxW / 2))
boxX = width - boxW / 2;
if(boxY > (height - boxH / 2))
boxY = height - boxH / 2;
drawGlass();
}
void drawGlass(){
Graphics temp;
temp = g.create();
temp.clipRect(boxX,boxY,boxW,boxH);
temp.drawImage(back, -boxX, -boxY, width * 2, height * 2, null);
g.setColor(Color.white);
g.drawRect(boxX, boxY, boxW - 1, boxH - 1);
}
void redrawGlass(int oldX, int oldY, int newX, int newY){
Graphics temp;
temp = g.create();
if(newX <= oldX && newY <= oldY){
temp.clipRect(newX, newY + boxH, boxW + oldX - newX, oldY - newY);
temp.drawImage(offi,0,0,null);
temp = g.create();
temp.clipRect(newX + boxW, newY, oldX - newX, boxH + oldY - newY);
temp.drawImage(offi,0,0,null);
}else if(newX > oldX && newY <= oldY){
temp.clipRect(oldX, newY + boxH, boxW + newX - oldX, oldY - newY);
temp.drawImage(offi,0,0,null);
temp = g.create();
temp.clipRect(oldX, newY,newX - oldX, boxH + oldY - newY);
temp.drawImage(offi,0,0,null);
}else if(newX > oldX && newY > oldY){
temp.clipRect(oldX, oldY,boxW + newX - oldX, newY - oldY);
temp.drawImage(offi,0,0,null);
temp = g.create();
temp.clipRect(oldX,oldY, newX - oldX, boxH + newY - oldY);
temp.drawImage(offi,0,0,null);
}else{
temp.clipRect(newX, oldY,boxW + oldX - newX, newY - oldY);
temp.drawImage(offi,0,0,null);
temp = g.create();
temp.clipRect(newX + boxW, oldY, oldX - newX, boxH + newY - oldY);
temp.drawImage(offi,0,0,null);
}
}
public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h){
if(flags == ALLBITS){
width = back.getWidth(this);
height = back.getHeight(this);
offi = createImage(width + boxW / 2, height + boxH / 2);
Graphics offg = offi.getGraphics();
offg.setColor(Color.lightGray);
offg.fillRect(0,0,width + boxW / 2, height + boxH / 2);
offg.drawImage(back, 0, 0,this);
repaint();
return false;
}else
return true;
}
public void paint(Graphics g){
g.drawImage(back, 0, 0, this);
drawGlass();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -