模拟PPT 实现播放图片
来源:互联网 发布:老男孩python 编辑:程序博客网 时间:2024/04/30 20:00
代码如下
package com.xiaoqiang;import java.awt.Component;import java.awt.Container;import java.awt.Graphics;import java.awt.Image;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.io.File;import javax.swing.Icon;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.event.AncestorListener;/** * 本案例模拟PPT * @author xiaoqiang * @time 2017年5月6日 */public class SimulationPPT extends JFrame implements ActionListener,MouseListener{ private Container con; private final String filePath = "./src/pic/"; private File[] files = null; private ImageIcon[] imageIcons = null; private ImageIcon[] smallImageIcons = null; private JLabel centerLabel = new JLabel(); private JButton nextPic = new JButton("下一页"); private JButton previousPic = new JButton("上一页"); private JLabel[] labels = new JLabel[6]; private int nowPage = 0; private final int MAX_PAGE = 1;//最大页数 private final int MIN_PAGE = 0;//最小页数 public SimulationPPT() { this.draw(); } private void draw() { con = this.getContentPane(); con.setLayout(null); this.getImageIcon(); this.getSmallImageIcon(); this.setCenterLabel(0); con.add(centerLabel); con.add(nextPic); con.add(previousPic); centerLabel.setBounds(700, 100, 512, 512); previousPic.setBounds(100, 720, 100, 100); nextPic.setBounds(1680, 720, 100, 100); centerLabel.addMouseListener(this); previousPic.addActionListener(this); nextPic.addActionListener(this); for (int i = 0; i < labels.length; i++) { labels[i] = new JLabel(smallImageIcons[i]); con.add(labels[i]); labels[i].setBounds(300+230*i, 700, 128, 128); labels[i].addMouseListener(this); } this.setSize(Toolkit.getDefaultToolkit().getScreenSize()); this.setVisible(true); } private void loadPage() { for (int i = 0; i < labels.length; i++) { labels[i].setIcon(smallImageIcons[i+nowPage*6]); } } /** * 设置最中间 大图片的位置 * @param i */ private void setCenterLabel(int i) { centerLabel.setIcon(imageIcons[i]); } private ImageIcon[] getImageIcon(){ files = new File(filePath).listFiles(); imageIcons = new ImageIcon[files.length]; for (int i = 0; i < imageIcons.length; i++) { imageIcons[i] = new ImageIcon(files[i].getAbsolutePath()); } return imageIcons; } /** * 把图片转化为小图片 * @return */ private ImageIcon[] getSmallImageIcon(){ Image[] images = new Image[imageIcons.length]; Image[] changedImages = new Image[imageIcons.length]; smallImageIcons = new ImageIcon[imageIcons.length]; for (int i = 0; i < images.length; i++) { images[i] = imageIcons[i].getImage(); changedImages[i] = images[i].getScaledInstance(128, 128, Image.SCALE_REPLICATE); smallImageIcons[i] = new ImageIcon(changedImages[i]); } return smallImageIcons; } public static void main(String[] args) { new SimulationPPT(); } @Override public void actionPerformed(ActionEvent e) { if("上一页".equals(e.getActionCommand())){ if(nowPage == MIN_PAGE){ JOptionPane.showMessageDialog(this, "已经是第一页"); }else{ nowPage--; this.loadPage(); } } else if("下一页".equals(e.getActionCommand())){ if(nowPage == MAX_PAGE){ JOptionPane.showMessageDialog(this, "已经最后一页"); }else{ nowPage++; this.loadPage(); } } } @Override public void mouseClicked(MouseEvent e) { int i=-1; while(!e.getSource().equals(labels[++i])); System.out.println(i); this.setCenterLabel(i+nowPage*6); } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { }}
0 0
- 模拟PPT 实现播放图片
- 让PPT文档自动实现列表播放
- PPT也能实现列表播放
- ppt如何设置实现循环播放
- PPT播放
- Handler实现图片播放
- Jquery实现图片播放
- C#实现 word、pdf、ppt 转为图片
- C#实现 word、pdf、ppt 转为图片
- PPT2010中轻松实现PPT自动循环播放
- 使用手机控制PPT播放实现方法(含源码)
- reveal.js实现html播放ppt的炫酷效果
- 实现PPT演示的"非全屏播放"效果
- 打造自动播放动画,实现PPt模式的效果
- 【特种兵PPT教程】如何实现PPT播放时内部页间的跳转?
- javascript实现图片播放功能
- Android实现图片循环播放
- js实现幻灯片播放图片
- 初学者对堆和栈的认识
- react native基于redux架构实现登陆和购物车
- 一些输入函数总结
- DHTML技术---新闻栏目
- 热修复小议
- 模拟PPT 实现播放图片
- Hibernate一对多及多对一
- 【Linux】利用信号实现sleep函数
- 关于开源图表hellocharts-android的一些使用心得
- 数据库引擎的区别
- Spring Boot参考文档(7)建造你的代码
- 梯度下降法
- 生成树计数
- Chrome、Firefox下margin-top问题