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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013907419/article/details/46716733

由于弄了好久,想把图片从上面获取路径,然后下面是随机显示的,在路径那里弄了好久的,所以到现在才发表。

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

	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));

在做编程之中,在某些方面的知识学得不好,会对以后的影响很大,这次让自己认识到,还得从基础抓实学起,以后才能在这条路上走得更远更好。

猜你喜欢

转载自blog.csdn.net/u013907419/article/details/46716733