一、系统介绍
本系统实现了对电脑目录的读取,实现电脑目录的前进后退功能;实现电子相册的查看、重命名,复制,粘贴,删除功能;实现电子相册的上一张,下一张全屏播放,幻灯片播放,每2s一次,可以自己设置。界面良好。
二、系统展示
1.主界面
2.全屏主界面
3.放大图片
4.缩小图片
5.幻灯片放映
三、系统实现
AutoPlay.java
package com.sjsq; import java.util.Timer; import java.util.TimerTask; /** * * 自动播放 * * @author 浪客剑心 * * @author shuijianshiqing * * @date 2020-09-08 19:29 * */ public class AutoPlay { private int second; FullFrame frame; private final Timer timer = new Timer(); // 设置播放时间间隔为2s public AutoPlay(FullFrame fullFrame) { this.frame = fullFrame; second = 2; } public void start() { timer.schedule(new TimerTask() { public void run() { frame.Forward(); frame.getJButton1().setEnabled(false); } }, second * 1000, second * 1000); } public void stop() { timer.cancel(); } }
FileNode.java
package com.sjsq; import java.io.File; import java.io.IOException; import javax.swing.tree.DefaultMutableTreeNode; public class FileNode extends DefaultMutableTreeNode { private boolean explored_ = false; public FileNode(File file) { setUserObject(file); } public boolean getAllowChildren() { return isDirectory(); } public boolean isLeaf() { return !isDirectory(); } public File getFile() { return (File) getUserObject(); } public boolean isExplored() { return explored_; } public boolean isDirectory() { File file = getFile(); return file.isDirectory(); } public String toString() { File file = getFile(); String filename = file.toString(); int index = filename.lastIndexOf("\\"); return (index != -1 && index != filename.length() - 1) ? filename.substring(index + 1) : filename; } public String getString() { File file = getFile(); String filename = file.getAbsolutePath(); return filename; } public File getWorR() { File file = getFile(); File file1 = file.getAbsoluteFile(); return file1; } public String getWorR1() throws IOException { File file = getFile(); String file1 = file.getPath(); return file1; } public void explore() { if (!isDirectory()) { return; } if (!isExplored()) { File file = getFile(); File[] children = file.listFiles(); for (int i = 0; i < children.length; ++i) { if (children[i].isDirectory()) { add(new FileNode(children[i])); } } explored_ = true; } } }
FullFrame.java
package com.sjsq; import java.awt.Image; import java.io.File; import java.util.ArrayList; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JToolBar; import javax.swing.LayoutStyle; import javax.swing.SwingConstants; /** * * 全屏 * * @author shuijianshiqing * * @date 2020-09-08 19:32 * */ public class FullFrame extends JFrame { private JButton jButton1; private JButton jButton2; private JButton jButton3; private JButton jButton4; private JButton jButton5; private JButton jButton6; private JLabel jLabel1; private JScrollPane jScrollPane1; private JToolBar jToolBar1; ArrayList<File> ClickedFilePath = new ArrayList<File>(); ArrayList<JTextField> ImagesNameTF = new ArrayList<JTextField>(); ArrayList<JLabel> SmallLabels = new ArrayList<JLabel>(); int SelectImage = 0; double CurrentMultiple = 1; int ImagesQuantity = 0; int flag = 0; AutoPlay play; String OpenFilePath; public FullFrame(ArrayList<File> ClickedFilePath, ArrayList<JTextField> ImagesNameTF, int SelectImage, int ImagesQuantity, ArrayList<JLabel> SmallLabels, String OpenFilePath) { initComponents(); setTitle("电子相册全屏操作页面"); setExtendedState(JFrame.MAXIMIZED_BOTH); this.ClickedFilePath = ClickedFilePath; this.ImagesNameTF = ImagesNameTF; this.SelectImage = SelectImage; this.ImagesQuantity = ImagesQuantity - 1; this.SmallLabels = SmallLabels; this.OpenFilePath = OpenFilePath; if (SelectImage == -1) { jButton2.setEnabled(false); jButton1.setEnabled(false); jButton5.setEnabled(false); jButton6.setEnabled(false); } if (SelectImage == 0) { jButton1.setEnabled(false); jButton1.setEnabled(false); } if (SelectImage == ImagesQuantity - 1) { jButton1.setEnabled(true); jButton2.setEnabled(false); jButton3.setEnabled(true); jButton4.setEnabled(true); jButton5.setEnabled(false); jButton6.setEnabled(false); } if (SelectImage != ImagesQuantity - 1 && SelectImage != 0 && SelectImage != -1) { jButton1.setEnabled(true); jButton2.setEnabled(true); jButton3.setEnabled(true); jButton4.setEnabled(true); jButton5.setEnabled(true); jButton6.setEnabled(true); } } public void Back() { if (SelectImage - 1 >= 0) { for (int i = 0; i < ClickedFilePath.size(); i++) { if (ClickedFilePath.get(i).getName().equals(ImagesNameTF.get(SelectImage - 1).getText())) { ImageIcon ic1 = new ImageIcon(ClickedFilePath.get(i).getAbsolutePath()); Image im = ic1.getImage().getScaledInstance(ic1.getIconWidth(), ic1.getIconHeight(), Image.SCALE_DEFAULT); ImageIcon ic2 = new ImageIcon(im); getJLabel1().setIcon(ic2); } } SelectImage = SelectImage - 1; if (SelectImage == 0) { getJButton1().setEnabled(false); } else { getJButton1().setEnabled(true); jButton2.setEnabled(true); jButton3.setEnabled(true); jButton4.setEnabled(true); jButton5.setEnabled(true); jButton6.setEnabled(true); } } } public void Forward() { if (SelectImage + 1 <= ImagesQuantity) { for (int i = 0; i < ClickedFilePath.size(); i++) { if (ClickedFilePath.get(i).getName().equals(ImagesNameTF.get(SelectImage + 1).getText())) { ImageIcon ic1 = new ImageIcon(ClickedFilePath.get(i).getAbsolutePath()); Image im = ic1.getImage().getScaledInstance(ic1.getIconWidth(), ic1.getIconHeight(), Image.SCALE_DEFAULT); ImageIcon ic2 = new ImageIcon(im); getJLabel1().setIcon(ic2); } } SelectImage = SelectImage + 1; if (SelectImage == ImagesQuantity) { jButton2.setEnabled(false); jButton5.setEnabled(false); jButton6.setEnabled(false); getJButton1().setEnabled(true); jButton3.setEnabled(true); jButton4.setEnabled(true); } else { jButton1.setEnabled(true); } } } public void Enlarge() { if (SelectImage == -1) { ImageIcon ic1 = new ImageIcon(OpenFilePath); double w = ic1.getIconWidth(); double h = ic1.getIconHeight(); Image im = ic1.getImage().getScaledInstance((int) (w * (CurrentMultiple + 0.25)), (int) (h * (CurrentMultiple + 0.25)), Image.SCALE_DEFAULT); ImageIcon ic2 = new ImageIcon(im); getJLabel1().setIcon(ic2); } else { if (SelectImage != flag) { CurrentMultiple = 1; } for (int i = 0; i < ClickedFilePath.size(); i++) { if (ClickedFilePath.get(i).getName().equals(ImagesNameTF.get(SelectImage).getText())) { ImageIcon ic1 = new ImageIcon(ClickedFilePath.get(i).getAbsolutePath()); double w = ic1.getIconWidth(); double h = ic1.getIconHeight(); Image im = ic1.getImage().getScaledInstance((int) (w * (CurrentMultiple + 0.25)), (int) (h * (CurrentMultiple + 0.25)), Image.SCALE_DEFAULT); ImageIcon ic2 = new ImageIcon(im); getJLabel1().setIcon(ic2); } } } CurrentMultiple = CurrentMultiple + 0.25; flag = SelectImage; } public void Decrease() { if (SelectImage == -1) { ImageIcon ic1 = new ImageIcon(OpenFilePath); double w = ic1.getIconWidth(); double h = ic1.getIconHeight(); Image im = ic1.getImage().getScaledInstance((int) (w * (CurrentMultiple - 0.25)), (int) (h * (CurrentMultiple - 0.25)), Image.SCALE_DEFAULT); ImageIcon ic2 = new ImageIcon(im); getJLabel1().setIcon(ic2); } else { if (SelectImage != flag) { CurrentMultiple = 1; } for (int i = 0; i < ClickedFilePath.size(); i++) { if (ClickedFilePath.get(i).getName().equals(ImagesNameTF.get(SelectImage).getText())) { ImageIcon ic1 = new ImageIcon(ClickedFilePath.get(i).getAbsolutePath()); double w = ic1.getIconWidth(); double h = ic1.getIconHeight(); Image im = ic1.getImage().getScaledInstance((int) (w * (CurrentMultiple - 0.25)), (int) (h * (CurrentMultiple - 0.25)), Image.SCALE_DEFAULT); ImageIcon ic2 = new ImageIcon(im); getJLabel1().setIcon(ic2); } } } CurrentMultiple = CurrentMultiple - 0.25; flag = SelectImage; } @SuppressWarnings("unchecked") private void initComponents() { jToolBar1 = new JToolBar(); jButton1 = new JButton(); jButton2 = new JButton(); jButton3 = new JButton(); jButton4 = new JButton(); jButton5 = new JButton(); jButton6 = new JButton(); jScrollPane1 = new JScrollPane(); jLabel1 = new JLabel(); jToolBar1.setRollover(true); jButton1.setIcon(new ImageIcon(getClass().getResource("/images/2.JPG"))); // NOI18N jButton1.setFocusable(false); jButton1.setHorizontalTextPosition(SwingConstants.CENTER); jButton1.setVerticalTextPosition(SwingConstants.BOTTOM); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jToolBar1.add(jButton1); jButton2.setIcon(new ImageIcon(getClass().getResource("/images/1.jpg"))); jButton2.setFocusable(false); jButton2.setHorizontalTextPosition(SwingConstants.CENTER); jButton2.setVerticalTextPosition(SwingConstants.BOTTOM); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jToolBar1.add(jButton2); jButton3.setIcon(new ImageIcon(getClass().getResource("/images/3.jpg"))); // NOI18N jButton3.setFocusable(false); jButton3.setHorizontalTextPosition(SwingConstants.CENTER); jButton3.setVerticalTextPosition(SwingConstants.BOTTOM); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jToolBar1.add(jButton3); jButton4.setIcon(new ImageIcon(getClass().getResource("/images/4.jpg"))); // NOI18N jButton4.setFocusable(false); jButton4.setHorizontalTextPosition(SwingConstants.CENTER); jButton4.setVerticalTextPosition(SwingConstants.BOTTOM); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jToolBar1.add(jButton4); jButton5.setIcon(new ImageIcon(getClass().getResource("/images/5.jpg"))); // NOI18N jButton5.setFocusable(false); jButton5.setHorizontalTextPosition(SwingConstants.CENTER); jButton5.setVerticalTextPosition(SwingConstants.BOTTOM); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); jToolBar1.add(jButton5); jButton6.setIcon(new ImageIcon(getClass().getResource("/images/6.jpg"))); // NOI18N jButton6.setFocusable(false); jButton6.setHorizontalTextPosition(SwingConstants.CENTER); jButton6.setVerticalTextPosition(SwingConstants.BOTTOM); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } }); jToolBar1.add(jButton6); jScrollPane1.setViewportView(jLabel1); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jToolBar1, GroupLayout.PREFERRED_SIZE, 382, GroupLayout.PREFERRED_SIZE) .addContainerGap(278, Short.MAX_VALUE)) .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 660, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jToolBar1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE))); pack(); } @SuppressWarnings("empty-statement") private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { Decrease(); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { Back(); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { Forward(); } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { Enlarge(); } private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { jButton6.setEnabled(true); jButton2.setEnabled(false); getJButton1().setEnabled(false); jButton3.setEnabled(false); jButton4.setEnabled(false); jButton5.setEnabled(false); play = new AutoPlay(this); play.start(); } private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) { play.stop(); jButton2.setEnabled(true); getJButton1().setEnabled(true); jButton3.setEnabled(true); jButton4.setEnabled(true); jButton5.setEnabled(true); } public JLabel getJLabel1() { return jLabel1; } public void setJLabel1(JLabel jLabel1) { this.jLabel1 = jLabel1; } public JButton getJButton1() { return jButton1; } }
PFileSystemView.java
package com.sjsq; import java.io.File; import java.io.IOException; import javax.swing.filechooser.FileSystemView; /** * * 创建新文件 * * @author shuijianshiqing * * @date 2020-09-08 19:26 * */ class PFileSystemView extends FileSystemView { public File createNewFolder(File containingDir) throws IOException { return null; } }
ThreadImages.java
package com.sjsq; import java.awt.Image; import java.io.File; import java.util.ArrayList; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; public class ThreadImages implements Runnable { ArrayList<JLabel> SmallLabels = new ArrayList<JLabel>(); ArrayList<JTextField> SmallTextFields = new ArrayList<JTextField>(); ArrayList<JPanel> SmallPanels = new ArrayList<JPanel>(); JPanel ImagePanel; int i; ArrayList<File> ImageFiles; int k; ThreadImages(ArrayList<File> ImageFiles, int k, int i, ArrayList<JLabel> SmallLabels, ArrayList<JTextField> SmallTextFields, ArrayList<JPanel> SmallPanels, JPanel ImagePanel) { this.k = k; this.ImageFiles = ImageFiles; this.i = i; this.SmallLabels = SmallLabels; this.SmallTextFields = SmallTextFields; this.SmallPanels = SmallPanels; this.ImagePanel = ImagePanel; } public synchronized void run() { for (int j = k; j < i; j++) { ImageIcon ic1 = new ImageIcon(ImageFiles.get(j).getAbsolutePath()); double h1 = ic1.getIconHeight(); double w1 = ic1.getIconWidth(); if (h1 < 77 && w1 < 100) { Image im = ic1.getImage().getScaledInstance((int) w1, (int) h1, Image.SCALE_DEFAULT);// 改变大小 ImageIcon ic2 = new ImageIcon(im);// 从新得到一个固定图片 // SmallLabels.add(j, new JLabel()); // SmallTextFields.add(j, new JTextField()); SmallLabels.get(j).setIcon(ic2); ic2.setImageObserver(SmallLabels.get(j)); SmallTextFields.get(j).setText(ImageFiles.get(j).getName()); } else { if (h1 * 180 > w1 * 142) { Image im = ic1.getImage().getScaledInstance((int) (w1 / (h1 / 81)), 81, Image.SCALE_DEFAULT);// 改变大小 ImageIcon ic2 = new ImageIcon(im);// 从新得到一个固定图片 SmallLabels.get(j).setIcon(ic2); ic2.setImageObserver(SmallLabels.get(j)); SmallTextFields.get(j).setText(ImageFiles.get(j).getName()); } else { Image im = ic1.getImage().getScaledInstance(105, (int) (h1 / (w1 / 105)), Image.SCALE_DEFAULT);// 改变大小 final ImageIcon ic2 = new ImageIcon(im);// 从新得到一个固定图片 SmallLabels.get(j).setIcon(ic2); ic2.setImageObserver(SmallLabels.get(j)); SmallTextFields.get(j).setText(ImageFiles.get(j).getName()); } } ImagePanel.add(SmallPanels.get(j)); if (ImageFiles.size() > 20) { SmallPanels.get(j).setBounds(j % 5 * 131, 1 + (j / 5 * 125), 120, 110); } else { SmallPanels.get(j).setBounds(j % 5 * 135, 1 + (j / 5 * 125), 120, 110); } SmallPanels.get(j).setLayout(new java.awt.BorderLayout(0, 0)); SmallPanels.get(j).add(SmallLabels.get(j), java.awt.BorderLayout.CENTER); SmallPanels.get(j).add(SmallTextFields.get(j), java.awt.BorderLayout.PAGE_END); SmallTextFields.get(j).setBorder(null); SmallTextFields.get(j).setHorizontalAlignment(SwingConstants.CENTER); SmallTextFields.get(j).setEditable(false); if (j == 0) { SmallLabels.get(0).setDisplayedMnemonic(501); } else { SmallLabels.get(j).setDisplayedMnemonic(j); } SmallLabels.get(j).setHorizontalAlignment(SwingConstants.CENTER); SmallLabels.get(j).setOpaque(true); SmallLabels.get(j).setBackground(new java.awt.Color(244, 244, 244)); } } }
四、其他
1.其他系统实现
JavaWeb系统系列实现
Java+JSP实现学生图书管理系统
Java+JSP实现学生信息管理系统
Java+JSP实现用户信息管理系统
Java+Servlet+JSP实现航空订票系统
Java+Servlet+JSP实现房屋租赁管理系统
Java+Servlet+JSP实现学生选课管理系统
Java+Servlet+JSP实现学生成绩管理系统
Java+Servlet+JSP实现宠物诊所管理系统
Java+SSM+Easyui实现网上考试系统
Java+Springboot+H-ui实现营销管理系统
Java+Springboot+Mybatis+Bootstrap实现网上商城系统
JavaSwing系统系列实现
Java+Swing实现斗地主游戏
Java+Swing实现图书管理系统
Java+Swing实现医院管理系统
Java+Swing实现仓库管理系统
Java+Swing实现考试管理系统
Java+Swing实现通讯录管理系统
Java+Swing实现停车场管理系统
Java+Swing实现学生信息管理系统
Java+Swing实现学生宿舍管理系统
Java+Swing实现学生选课管理系统
Java+Swing实现学生成绩管理系统
Java+Swing实现学校教材管理系统
Java+Swing实现学校教务管理系统
Java+Swing实现企业人事管理系统
Java+Swing实现电子相册管理系统
Java+Swing实现自助取款机(ATM)系统
Java+Swing实现超市管理系统-TXT存储信息
Java+Swing实现宠物商店管理系统-TXT存储信息