3
A
回答
4
我不認爲有這樣做的功能。但是你可以擴展一個Panel(它可以作爲一個簡單的組件容器)並且覆蓋paint方法在後臺繪製圖像。
以下是一個示例程序。希望這可以幫助。
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.io.IOException.*;
public class BackgroundApplet extends Applet {
Image backGround;
public void init() {
// set the size of the applet to the size of the background image.
// Resizing the applet may cause distortion of the image.
setSize(300, 300);
// Set the image name to the background you want. Assumes the image
// is in the same directory as the class file is
backGround = getImage(getCodeBase(), "save.GIF");
BackGroundPanel bgp = new BackGroundPanel();
bgp.setLayout(new FlowLayout());
bgp.setBackGroundImage(backGround);
// Add the components you want in the Applet to the Panel
bgp.add(new Button("Button 1"));
bgp.add(new TextField("isn't this cool?"));
bgp.add(new Button("Useless Button 2"));
// set the layout of the applet to Border Layout
setLayout(new BorderLayout());
// now adding the panel, adds to the center
// (by default in Border Layout) of the applet
add(bgp);
}
}
class BackGroundPanel extends Panel {
Image backGround;
BackGroundPanel() {
super();
}
public void paint(Graphics g) {
// get the size of this panel (which is the size of the applet),
// and draw the image
g.drawImage(getBackGroundImage(), 0, 0,
(int)getBounds().getWidth(), (int)getBounds().getHeight(), this);
}
public void setBackGroundImage(Image backGround) {
this.backGround = backGround;
}
private Image getBackGroundImage() {
return backGround;
}
}
+2
AWT? (支票表 - 實現不佩帶表)這是什麼千禧年? –
+1
'setSize(300,300);'這在瀏覽器中無法可靠運行。 applet的大小應該由HTML設置。 –
相關問題
- 1. Android應用程序中的背景圖像的最小尺寸
- 2. 用javascript更改java小程序背景
- 3. Java小程序透明背景
- 4. Java小程序,使背景透明
- 5. body.class背景圖像大小
- 6. 背景圖像在android應用程序中似乎很小?
- 7. Android應用程序的背景圖像
- 8. 背景大小與css sprite圖像中的背景位置
- 9. 在Java Swing應用程序中顯示背景圖像
- 10. 在java中的背景圖像
- 11. 在背景圖像背景圖像
- 12. Windows Phone應用程序背景圖像
- 13. 使用引導程序調整背景圖像大小
- 14. 背景圖片上的背景圖像
- 15. 在Java中添加背景圖像
- 16. 在Java中設置背景圖像
- 17. 大小的DIV背景圖像
- 18. ActionBarSherlock背景的圖像大小
- 19. 背景圖像的高度很小
- 20. 背景大小:封面不設置背景圖像的高度
- 21. 從PyGame中的較小圖像構建背景圖像
- 22. 圖像背景
- 23. 背景圖像
- 24. 背景圖像
- 25. Linearlayout中的背景圖像
- 26. Flex中的背景圖像
- 27. 中心的背景圖像
- 28. css中的圖像背景
- 29. 帶背景圖像的Java卡布局
- 30. CSS中的無圖像背景圖像
*「你如何在Java小程序中設置背景圖像?」*一旦擁有了圖像,就像在「JPanel」中做的那樣。 –
順便說一句 - GIF動畫? –