谁能让图片随 Frame 的大小变化自动适应窗口,帮帮我

telenths 2002-07-23 08:07:56
同上
...全文
166 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
henssen 2002-11-18
  • 打赏
  • 举报
回复
up
telenths 2002-07-24
  • 打赏
  • 举报
回复
明白了
gdsean 2002-07-23
  • 打赏
  • 举报
回复
系统调用了paintComponent方法才可以画出JPanel出来
telenths 2002-07-23
  • 打赏
  • 举报
回复
呵呵
我正是要用一个 JPanel 不然其他组件可就没处放了

效果非常好
谢谢
还有一小问 我没有看见你调用 paintComponent(Graphics g)
是系统自己调用的吗?
gdsean 2002-07-23
  • 打赏
  • 举报
回复
呵呵我原来是扩展JPanel的
public class ImageBgPanel extends JPanel {
private ImageIcon bg;
public ImageBgPanel(LayoutManager layout,ImageIcon icon) {
super(layout);
bg = icon;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Image img = bg.getImage();
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
}
}
你不如在JFrame上面放一个JPanel
telenths 2002-07-23
  • 打赏
  • 举报
回复
应该是
paintComponents

可是我看不见图像
telenths 2002-07-23
  • 打赏
  • 举报
回复
返回
"ImageBgFrame.java": Error #: 300 : method paintComponent(java.awt.Graphics) not found in class javax.swing.JFrame at line 23, column 11
gdsean 2002-07-23
  • 打赏
  • 举报
回复
你试试用这个Frame代替原来的Frame

import java.awt.*;
import javax.swing.*;

public class ImageBgFrame extends JFrame{
private ImageIcon bg;
public ImageBgFrame(String title,ImageIcon icon) {
super(title);
bg = icon;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Image img = bg.getImage();
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
}
}
telenths 2002-07-23
  • 打赏
  • 举报
回复
对不起 图片是一个 jpg 文件 不是画上去的呀
wangyu4882 2002-07-23
  • 打赏
  • 举报
回复
用画布呀,和APPLET差不多
telenths 2002-07-23
  • 打赏
  • 举报
回复
拼错了 是 Application :-P
telenths 2002-07-23
  • 打赏
  • 举报
回复
摇滚java 老兄 非常谢你的帮助
不过我是在 Appleation 里做,不是 applet ,还有办法吗?
gdsean 2002-07-23
  • 打赏
  • 举报
回复
扩展paintComponent方法
private ImageIcon bg;//给定一个图
...
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Image img = bg.getImage();
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧