資源簡介
java實現(xiàn)電子相冊,可以播放文件夾里的照片,文件夾可以自己選擇。

代碼片段和文件信息
import?java.awt.EventQueue;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.io.File;
import?javax.swing.Jframe;
import?javax.swing.JPanel;
import?javax.swing.border.EmptyBorder;
import?javax.swing.JLabel;
import?javax.swing.JButton;
import?javax.swing.JTextField;
import?javax.swing.JFileChooser;
import?javax.swing.ImageIcon;
import?javax.swing.Timer;
public?class?album?extends?Jframe{
JButton?btnStart;
JButton?btnStop??;
JButton?btnNewButton;
JLabel?picLabel;
JTextField?time;
Timer?timer;
File?fileDirectory;
JFileChooser?fileChooser;
String[]?lists;
String?parentPath;
?int?i=0;
public?album()?{
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
setBounds(0?0?1000?700);
settitle(“圖片播放器“);
JPanel?contentPane?=?new?JPanel();
contentPane.setBorder(new?EmptyBorder(10?10?10?10));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton?btnStart?=?new?JButton();
btnStart.setText(“開始播放圖片“);
btnStart.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
playpic();
}
});?
btnStart.setBounds(786?327?154?65);
contentPane.add(btnStart);
JButton?btnStop?=?new?JButton();
btnStop.setText(“停止播放圖片“);?
btnStop.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
stop();
}
});
btnStop.setBounds(786?450?154?65);
contentPane.add(btnStop);
picLabel?=?new?JLabel();
picLabel.setText(“圖片顯示區(qū)域“);
picLabel.setBounds(10?15602?609);
contentPane.add(picLabel);
JButton?btnNewButton?=?new?JButton(“瀏覽圖片文件目錄“);
btnNewButton.setBounds(786?208?154?65);
contentPane.add(btnNewButton);
btnNewButton.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
openpic();
}
});
time=?new?JTextField(10);
time.setBounds(840?58?66?32);
contentPane.add(time);
time.setColumns(10);
JLabel?lblNewLabel?=?new?JLabel(“播放間隔????????????????????????毫秒“);
lblNewLabel.setBounds(786?58?154?39);
contentPane.add(lblNewLabel);
}
private?void?playpic(){
int?t;
if(time.getText().equals(““))
t=0;
else
t=Integer.valueOf(time.getText());????????
timer=new?Timer(tnew?ActionListener(){
public?void?actionPerformed(ActionEvent?e){
ImageIcon?image=new?ImageIcon(parentPath+“\\“+lists[i]);
picLabel.setIcon(image);
i++;
if(i+1>lists.length)i=0;
}
});
timer.start();
}
public?void?openpic(){
??????fileChooser=new?JFileChooser(new?File(“G:“));
??????fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
??????fileChooser.showOpenDialog(this);
??????fileDirectory=fileChooser.getSelectedFile();
??????parentPath=fileDirectory.getAbsolutePath();
??????lists=fileDirectory.list();
??????if(hasPicture()){
????????this.NextPicture();
??????}else{
???
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-04-12?11:48??album\
?????文件?????????301??2018-04-12?10:17??album\.classpath
?????文件?????????381??2018-04-12?10:17??album\.project
?????目錄???????????0??2018-04-12?11:48??album\.settings\
?????文件?????????598??2018-04-12?10:17??album\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2018-05-14?20:31??album\bin\
?????文件?????????596??2018-05-15?19:04??album\bin\album$1.class
?????文件?????????596??2018-05-15?19:04??album\bin\album$2.class
?????文件?????????595??2018-05-15?19:04??album\bin\album$3.class
?????文件????????1282??2018-05-15?19:04??album\bin\album$4.class
?????文件?????????672??2018-05-15?19:04??album\bin\album$5.class
?????文件????????4484??2018-05-15?19:04??album\bin\album.class
?????文件?????????608??2018-05-14?20:31??album\bin\Display$1.class
?????文件?????????608??2018-05-14?20:31??album\bin\Display$2.class
?????文件?????????670??2018-05-14?20:31??album\bin\Display$3.class
?????文件?????????932??2018-05-14?20:31??album\bin\Display$4.class
?????文件?????????777??2018-05-14?20:31??album\bin\Display$5.class
?????文件????????1283??2018-05-14?20:31??album\bin\Display$6.class
?????文件????????4112??2018-05-14?20:31??album\bin\Display.class
?????文件?????????676??2018-05-14?20:31??album\bin\PlayPicture$1.class
?????文件????????5037??2018-05-14?20:31??album\bin\PlayPicture.class
?????文件?????????626??2018-05-14?20:31??album\bin\WebBrowser$1.class
?????文件?????????643??2018-05-14?20:31??album\bin\WebBrowser$10.class
?????文件?????????803??2018-05-14?20:31??album\bin\WebBrowser$11.class
?????文件?????????907??2018-05-14?20:31??album\bin\WebBrowser$12.class
?????文件?????????596??2018-05-14?20:31??album\bin\WebBrowser$2.class
?????文件?????????644??2018-05-14?20:31??album\bin\WebBrowser$3.class
?????文件?????????647??2018-05-14?20:31??album\bin\WebBrowser$4.class
?????文件?????????639??2018-05-14?20:31??album\bin\WebBrowser$5.class
?????文件?????????638??2018-05-14?20:31??album\bin\WebBrowser$6.class
?????文件?????????641??2018-05-14?20:31??album\bin\WebBrowser$7.class
............此處省略8個文件信息
- 上一篇:java實驗七
- 下一篇:分?jǐn)?shù)計算器界面設(shè)計
評論
共有 條評論