📄 simplelightweightcontainer.java
字号:
import java.applet.Applet;
import java.awt.*;
public class SimpleLightweightContainer extends Applet {
private Image dining, paper;
public void init() {
dining = getImage(getCodeBase(),"../gifs/Dining.gif");
paper = getImage(getCodeBase(),"../gifs/paper.gif");
Container container = new LightweightContainer(paper);
container.add(new Lightweight(dining));
setLayout(new BorderLayout());
add(container, "Center");
}
}
class LightweightContainer extends Container {
private Image wallpaperImage;
public LightweightContainer(Image wallpaperImage) {
this.wallpaperImage = wallpaperImage;
setLayout(new FlowLayout());
}
public void paint(Graphics g) {
Util.wallPaper(this, g, wallpaperImage);
super.paint(g);
}
}
class Lightweight extends Component {
private Image image;
public Lightweight(Image image) {
this.image = image;
Util.waitForImage(this, image);
}
public void paint(Graphics g) {
g.drawImage(image, 0, 0, this);
}
public Dimension getPreferredSize() {
return new Dimension(image.getWidth(this),
image.getHeight(this));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -