| 发表于:2007-10-12 11:19:28 楼主 |
我写了一个panel,用于显示图片,代码如下: .. public picpanel(string picpath) { try { jbinit(picpath); } catch (exception e) { e.printstacktrace(); } } jlabel jl = null; imageicon img = null; private void jbinit(string picpath) throws exception { this.setlayout(null); setvisible(true); img = new imageicon(picpath); jl = new jlabel(img); this.setlayout(new borderlayout()); this.setsize(new dimension(400, 359)); this.add(jl, borderlayout.center); } .. 我在frame中调用panel并把图片地址以参数发给panel: picpanel pp=new picpanel("c:\\t.jpg"); panelcenter.add(pp,borderlayout.north); this.getcontentpane().add( panelcenter, borderlayout.center ); 可以正常显示图片, 但我希望在frame中加入一个按钮方法,点击该按钮来切换panel中的图片,我采用的是如下方法: private void button1_actionperformed(actionevent e) { pp=new picpanel("c:\\t2.jpg"); panelcenter.add(pp,borderlayout.west); this.getcontentpane().add( panelcenter, borderlayout.center ); } 不起作用。 请高手帮个忙,怎么样解决这个问题 |
|
|
|
|