全部展开
有两个问题。 图像路径写得不正确。 图像必须在src下,图像路径必须为src/海洋. png。 正e 68 a 84 E8 a 2ad 62616964757 a 686964616 f 3133365656632正确格式为image=newimageicon(src
image=newimageicon(src/海洋. png ) )必须位于label=newjlabel ) image )中。 以前。
示例: importjavax.swing.*;
classJPanelDemoextendsJPanel{
标签;
JTextFieldtext;
JButtonbutton;
ImageIconimage;
publicJPanelDemo (
image=new image icon (src/test.png );
label=newjlabel(image;
text=newjtextfield(20;
button=newjbutton('ok ' );
add (标签);
添加(文本);
add(Button;
}
}
publicclassAppextendsJFrame{
publicApp () }
this.setsize (500,400 );
this.setdefaultcloseoperation (jframe.exit _ on _ close );
this.add(newjpaneldemo ) );
}
publicstaticvoidmain (string [ ] args ) {
newApp ().setvisible ) true;
}
}