首页 > 编程知识 正文

java添加图片路径,怎么在java中添加图片

时间:2023-05-03 23:35:46 阅读:171955 作者:477

全部展开

有两个问题。 图像路径写得不正确。 图像必须在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;

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。