你说的如果是java swing程序,有两种方法,1、JPanel上放背景;2、JLabel放背景
// 初始化窗口public void initFrame() {
// 利用JPanel添加背景
GImage = new JPanel() {
protected void paintComponent(Graphics g) {
ImageIcon icon = new ImageIcon("image\\benbenlajpg");
Image img = icongetImage();
gdrawImage(img, 0, 0, icongetIconWidth(),
icongetIconHeight(), icongetImageObserver());
jframesetSize(icongetIconWidth(), icongetIconHeight());
}
};
jframesetTitle("测试背景");
jframeadd(GImage);
jframepack();
jframesetVisible(true);
jframesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
}ImageIcon icon = new ImageIcon("image\\benbenlajpg");
iconsetImage(icongetImage()getScaledInstance(icongetIconWidth(),
icongetIconHeight(), ImageSCALE_DEFAULT));
Systemoutprintln(icongetIconHeight() + "" + icongetIconWidth());
jlpicsetBounds(0, 0, 1366, 768);
jlpicsetHorizontalAlignment(0);
jlpicsetIcon(icon);
jframesetSize(1366, 768);
jframeadd(jlpic);
jframepack();
jframesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
jframesetVisible(true);你说application还是web啊
---------------------------
可以在JFrame里加一个重载过的JPanel
class
ImagePanel
extends
JPanel
{
@Override
public
void
paint(Graphics
g)
{
superpaint(g);
//在这里把你那张画上去
}
}
jsp使用标签引入资源文件是可以作为背景音乐的,亲测可用,自己也试一试;在head标签内添加如下代码,注意scr引入的资源文件更换为你自己的
public void paintComponent(Graphics g) {
superpaintComponent(g);
if (image != null) {
gdrawImage(image, 0, 0, this);
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)