全部展开
因为你的jl1没有放入jp1,而是放入了JFrame,所以不能放入JP1.remove(JL1 ); 应该改为this.remove(JL1 );
此外,更改后,重新定位62616964757 a 686964616 Fe 4b 893 e 5b 19e 3133361303130下的JFrame组件,使其与this.validate (;
你的步骤我会帮你修改的,你看。 (更改请参见注释) importjava.awt.*;
importjavax.swing.*;
公共类hello _2extends jframe {
JLabeljl1;
JLabeljl2;
JPaneljp1;
publicstaticvoidmain (string [ ] args ) {
Hello_2hello=newHello_2(;
}
公共健康_2() )。
{
jp1=newJPanel (;
jl1=new jlabel (new image icon (images/001.png ) );
this.add(JL1;
this.setsize (420,430;
this.setlocationrelativeto () null;
//窗口居中
this.setdefaultcloseoperation (jframe.exit _ on _ close );
//关闭程序
this.setvisible(true;
this.remove(JL1; //此处JP1.remove(JL1 ); 更改为this.remove(JL1 )
jl2=new jlabel (new image icon (images/002.png ) );
this.add(JL2;
this.validate (; //现在让JFrame容器重新定位子组件
//repaint (;
//明明想在界面上显示001.png后再显示002.png,为什么只显示001.png呢?
}
}