java 编程,panel
panel中能插入图片吗?用哪些方法或则类呀,求指导??
程序代码:
import java.awt.*; import javax.swing.*; public class TestFrame extends JFrame { private Image image = null ; private ImageIcon icon = new ImageIcon("E:\\壁纸\\动漫超赞CG壁纸1920x1200(38P)\\001.jpg"); public TestFrame(){ super("测试窗口"); Toolkit toolkit = this.getToolkit(); Dimension dimension= toolkit.getDefaultToolkit.getScreenSize(); this.setSize(dimension.width,dimension.height); this.setVisible(true); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } public static void main(){ new TestFrame(); } //绘制背景这个方法jvm会自动调用 public void paint(Graphics g){ super.paint(); image = icon.getImage(); g.drawImage(image,0,0,null); } }
[ 本帖最后由 Java258 于 2014-10-24 14:26 编辑 ]