您的位置:首页 > 编程语言 > Java开发

《Java课程实习》日志(周三)

2015-07-02 11:08 495 查看
由于弄了好久,想把图片从上面获取路径,然后下面是随机显示的,在路径那里弄了好久的,所以到现在才发表。

获取路径和随机显示图片部分代码

File f = new File(strPath);
String[] names = f.list(new FilenameFilter(){
public boolean accept(File f , String name){
return name.endsWith(".jpg");

}
});

Random r = new Random();
String strTmp = strPath+"/"+names[r.nextInt(108)];
String strTmp1 =strPath+"/"+names[r.nextInt(108)];
String strTmp2 = strPath+"/"+ names [r.nextInt(108)];

lblImg1.setIcon(new ImageIcon(strTmp));
lblImg2.setIcon(new ImageIcon(strTmp1));
lblImg3.setIcon(new ImageIcon(strTmp2));


在做编程之中,在某些方面的知识学得不好,会对以后的影响很大,这次让自己认识到,还得从基础抓实学起,以后才能在这条路上走得更远更好。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: