百度网盘链接:https://pan.baidu.com/s/1KfpjSDVHVv_oxTBP6d-c9Q 
提取码:nen4

想法:弄一个登录界面,登录进去后可以选择查看图片

实现步骤:

1、主函数Main类

package 图片展示;public class Main {public static void main(String[] args) {// TODO Auto-generated method stubLogin login = new Login();}}

2、login类

package 图片展示;import java.awt.Color;
import java.awt.Image;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;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.JPasswordField;
import javax.swing.JTextField;public class Login extends JFrame implements ActionListener{JTextField fieldAccount = new JTextField(10);JPasswordField fieldPassword = new JPasswordField(10);public Login() {this.setTitle("Login");this.setBounds(200, 200, 440, 340);this.setDefaultCloseOperation(HIDE_ON_CLOSE);this.setVisible(true);      this.setIconImage(new ImageIcon("./photo/background.jpg").getImage());this.setLayout(null);JLabel label = new JLabel("   帐  号   ");label.setAlignmentX(JLabel.CENTER_ALIGNMENT);label.setBounds(220, 100, 100, 50);this.add(label );fieldAccount.setBounds(270, 110, 120, 25);this.add(fieldAccount);label = new JLabel("   密 码   ");label.setAlignmentX(JLabel.CENTER_ALIGNMENT);label.setBounds(220, 150, 100, 50);this.add(label);fieldPassword.setBounds(270, 160, 120, 25);this.add(fieldPassword);JButton jbutton = new JButton("登录");jbutton.setBounds(270, 200, 60, 30);Color color1 = new Color(80,120,40);jbutton.setForeground(color1);this.add(jbutton);jbutton.addActionListener(this);fieldPassword.addActionListener(this);/*改变窗口背景*/ImageIcon backbround = new ImageIcon("./photo/background.jpg");Image image = backbround.getImage(); Image smallImage = image.getScaledInstance(500, 500, Image.SCALE_FAST);ImageIcon backbrounds = new ImageIcon(smallImage);//将图片添加到JLable标签 JLabel jlabel = new JLabel(backbrounds);//设置标签的大小jlabel.setBounds(0,0, getWidth(),getHeight() );//将图片添加到窗口add(jlabel);}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubString account1 = fieldAccount.getText();String pwd1 = new String(fieldPassword.getPassword());if (account1.compareTo("123") == 0 && pwd1.compareTo("123") == 0){JOptionPane.showMessageDialog(null, "登录成功,Welcome","Login",1);dispose();Home home = new Home();}else JOptionPane.showMessageDialog(null, "登录失败,请重试","Login",1);}}

3、Home类

package 图片展示;import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;public class Home extends JFrame implements ActionListener{public Home() {this.setTitle("浏览界面");this.setBounds(100, 100, 450, 300);this.setDefaultCloseOperation(HIDE_ON_CLOSE);this.setVisible(true);this.setIconImage(new ImageIcon("./photo/background.jpg").getImage());FlowLayout layout = new FlowLayout();this.setLayout(layout);JButton button1 = new JButton("第一张");ImageIcon imageIcon1 = new ImageIcon("./photo/photo1.jpg"); Image image1 = imageIcon1.getImage(); Image smallImage1 = image1.getScaledInstance(60, 50, Image.SCALE_FAST);ImageIcon smallIcon1 = new ImageIcon(smallImage1);button1.setIcon(smallIcon1);this.add(button1);button1.addActionListener(this);button1.addActionListener(new ActionListener()        {public void actionPerformed(ActionEvent e){Photo1 photo1 = new Photo1();}});JButton button2 = new JButton("第二张");ImageIcon imageIcon2 = new ImageIcon("./photo/photo2.jpg"); Image image2 = imageIcon2.getImage(); Image smallImage2 = image2.getScaledInstance(60, 50, Image.SCALE_FAST);ImageIcon smallIcon2 = new ImageIcon(smallImage2);button2.setIcon(smallIcon2);this.add(button2);button2.addActionListener(this);button2.addActionListener(new ActionListener()     {public void actionPerformed(ActionEvent e){Photo2 photo2 = new Photo2();}});JButton button3 = new JButton("第三张");ImageIcon imageIcon3 = new ImageIcon("./photo/photo3.jpg"); Image image3 = imageIcon3.getImage(); Image smallImage3 = image3.getScaledInstance(60, 50, Image.SCALE_FAST);ImageIcon smallIcon3 = new ImageIcon(smallImage3);button3.setIcon(smallIcon3);this.add(button3);button3.addActionListener(this);button3.addActionListener(new ActionListener()     {public void actionPerformed(ActionEvent e){Photo3 photo3 = new Photo3();}});JButton jb4 = new JButton("首张");this.add(jb4);jb4.addActionListener(this);jb4.addActionListener(new ActionListener()       {public void actionPerformed(ActionEvent e){Photo1 photo1 = new Photo1();}});JButton jb5 = new JButton("末张");this.add(jb5);jb5.addActionListener(this);jb5.addActionListener(new ActionListener()       {public void actionPerformed(ActionEvent e){Photo3 photo3 = new Photo3();}});}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub}}

4、photo1类

package 图片展示;import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;public class Photo1 extends JFrame implements ActionListener{public Photo1() {this.setTitle("Photo1");this.setBounds(100, 100, 800, 600);this.setDefaultCloseOperation(HIDE_ON_CLOSE);this.setIconImage(new ImageIcon("./photo/background.jpg").getImage());this.setVisible(true);FlowLayout layout = new FlowLayout();this.setLayout(layout);ImageIcon image1 = new ImageIcon("./photo/photo1.jpg");JLabel label = new JLabel(image1);     this.add(label);JButton button1 = new JButton("信息");this.add(button1);button1.addActionListener(this);button1.addActionListener(new ActionListener()     {public void actionPerformed(ActionEvent e){JOptionPane.showMessageDialog(null, "  鸣人","photo1信息",-1);}});JButton button2 = new JButton("下一张");this.add(button2);button2.addActionListener(this);button2.addActionListener(new ActionListener()      {public void actionPerformed(ActionEvent e){dispose();Photo2 photo2 = new Photo2();                }});}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub}}

5、photo2类

package 图片展示;import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;public class Photo2 extends JFrame implements ActionListener{public Photo2() {this.setTitle("Photo2");this.setBounds(100, 50, 1000, 750);this.setDefaultCloseOperation(HIDE_ON_CLOSE);this.setIconImage(new ImageIcon("./photo/photo2.jpg").getImage());this.setVisible(true);FlowLayout layout = new FlowLayout();this.setLayout(layout);ImageIcon image1 = new ImageIcon("./photo/photo2.jpg");JLabel label = new JLabel(image1);this.add(label);JButton button1 = new JButton("信息");this.add(button1);button1.addActionListener(this);button1.addActionListener(new ActionListener()       {public void actionPerformed(ActionEvent e){Massage1 massage1 = new Massage1();}});JButton button2 = new JButton("上一张");this.add(button2);button2.addActionListener(this);button2.addActionListener(new ActionListener()        {public void actionPerformed(ActionEvent e){dispose();Photo1 photo1 = new Photo1();}});JButton button3 = new JButton("下一张");this.add(button3);button3.addActionListener(this);button3.addActionListener(new ActionListener()        {public void actionPerformed(ActionEvent e){dispose();Photo3 photo3 = new Photo3();                }});}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub}}

6、photo3类

package 图片展示;import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;public class Photo3 extends JFrame implements ActionListener{public Photo3() {this.setTitle("Photo3");this.setBounds(100, 100, 800, 600);this.setDefaultCloseOperation(HIDE_ON_CLOSE);this.setIconImage(new ImageIcon("./photo/photo3.jpg").getImage());this.setVisible(true);FlowLayout layout = new FlowLayout();this.setLayout(layout);ImageIcon image1 = new ImageIcon("./photo/photo3.jpg");JLabel label = new JLabel(image1);this.add(label);JButton button1 = new JButton("信息");this.add(button1);button1.addActionListener(this);button1.addActionListener(new ActionListener()      {public void actionPerformed(ActionEvent e){JOptionPane.showMessageDialog(null, "  佐助","photo3信息",-1);}});JButton jbutton2 = new JButton("上一张");this.add(jbutton2);jbutton2.addActionListener(this);jbutton2.addActionListener(new ActionListener()      {public void actionPerformed(ActionEvent e){dispose();Photo2 photo2 = new Photo2();                }});}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub}}

7、Massage类

package 图片展示;import java.awt.Color;
import java.awt.Font;import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;public class Massage1 extends JFrame{public Massage1() {this.setTitle("Massage");this.setBounds(200, 50, 600, 400);this.setDefaultCloseOperation(HIDE_ON_CLOSE);this.setIconImage(new ImageIcon("./photo/photo2.jpg").getImage());this.setVisible(true);JTextArea  Myarea=new  JTextArea(3,10);Myarea.setText( " \n " +"信息:\n"+ "hello\n"+"你好\n"+"哈哈哈\n"+ "哈哈哈哈哈哈\n" );       this.setLayout(null);              Myarea.setBounds( 10,10,600,350);                         Myarea.setFont(new Font("华文正楷",Font.BOLD,25));Color color = new Color(0,110,0);Myarea.setForeground(color);Myarea.setEditable(false);this.add(Myarea);}}

这些操作用到的知识,例如界面跳转、弹框、图片显示等前面都有发过单一的。

Java实现简单图片浏览相关推荐

  1. ssm java上传图片预览_基于JAVA的SSM图片浏览系统

    今天和一个朋友共同完成了一个图片浏览系统的设计与实现项目,我们在开发时选用的框架是SSM(MYECLIPSE)框架.我这个朋友知识有限,只会这个框架,哈哈,都是为了方便他.和往常一样选用简单又便捷的M ...

  2. java canvas 画图片_[Java教程][HTML5] Canvas绘制简单图片

    [Java教程][HTML5] Canvas绘制简单图片 0 2016-05-13 13:00:04 获取Image对象,new出来 定义Image对象的src属性,参数:图片路径 定义Image对象 ...

  3. java 实现ps功能_java 简单图片,可以实现ps的几个小滤镜

    java 简单图片,可以实现ps的几个小滤镜 以下教你实现图片马赛克,黑白画,珠纹化,油画效果等处理技术原理及实现.看完自己也可以简单的玩一玩. 1. 需要用到的包 java.awt // 用于创建用 ...

  4. 制作动态相册的python知识点_动感网页相册 python编写简单文件夹内图片浏览工具...

    不知道大家有没有这样的体验,windows电脑上查看一张gif图,默认就把IE给打开了,还弹出个什么询问项,好麻烦的感觉.所以为了解决自己的这个问题,写了个简单的文件夹内图片浏览工具. 效果图 以E盘 ...

  5. Android之——史上最简单最酷炫的3D图片浏览效果的实现

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/48052709 如今,Android开发已经成为移动互联开发领域中一支不可或缺的力量 ...

  6. 在开发中图片浏览遇到的一些简单问题

    在开发中图片浏览遇到的一些简单问题 由于在项目中已经用到了一个第三方框架(MJPhotoBrowser)做图片浏览了,所以就使用了这个框架来做图片的浏览功能. 项目需求 单击图片放大(只可以浏览单张图 ...

  7. 简单粗暴的移动端图片浏览插件demo

    使用方法: 首先引入 jQuery <script src="./fly-zomm-img.min.js"></script> 再引入 图片浏览插件 < ...

  8. PhotoSwipe 图片浏览插件使用方法 - 简单

    [转载] [JS插件] PhotoSwipe 图片浏览插件使用方法 一.介绍 PhotoSwipe 是专为移动触摸设备设计的相册/画廊.兼容所有iPhone.iPad.黑莓6+,以及桌面浏览器.底层实 ...

  9. Vue图片浏览组件v-viewer简单应用

    v-viewer 用于图片浏览的Vue组件,支持旋转.缩放.翻转等操作,基于viewer.js. 安装 npm install v-viewer 使用 引用插件 main.js import View ...

最新文章

  1. 全领域涨点 | Evolving Attention在CV与NLP领域全面涨点
  2. 使用GeocodeService进行地理位置检索
  3. ADO.NET Entity Framework Beta2(五)/快速入门(实体框架)
  4. 最新综述:从多个角度介绍多模态对话信息搜索(MMCIS)任务
  5. Web前端工程师的一些常见误区介绍!
  6. Function Query(树状数组)
  7. 公路多孔箱涵设计_【公路常识中篇】公路路基边坡滑坡防护设计和预防
  8. 【2016年第6期】21世纪天文学面临的大数据和研究范式转型
  9. 文字排版不可不看的优秀案例合集
  10. 安装fio命令linux,如何在Linux中使用Fio来测评硬盘性能
  11. okHttp3 源码分析
  12. 计算机管理主要是作业管理和什么管理,计算机四级之作业管理试题
  13. 关于 Java 泛型的一些有趣的例子
  14. Undefined exploded archive location(在myeclipse中TOMCAT不能发布程序。)
  15. 【blog】用emoji-java解决Emoji存储MySQL乱码问题
  16. 三因子两水平doe_minitab doe 操作说明 范例 全因子实验设计法3 因子2 水平实验设计.pdf...
  17. 火爆全网,搜狐CEO张朝阳手推E=mc²,CEO当太久都忘了他是MIT物理博士
  18. activiti工作流数据库表详细说明
  19. P站-画师通图片如何保存为原图
  20. 问题解决:Ubuntu18.04版本始终无法动态获取IP地址

热门文章

  1. 正向设计模式下防火规范自动检查工具AtCheck
  2. 双目立体视觉建立深度图_双目立体视觉技术的实现及其发展
  3. CPAL脚本自动化测试 ———— RC232 系列函数及使用
  4. (五)通俗易懂理解——双向LSTM
  5. 前端局部自动刷新_javascript如何实现局部刷新?
  6. 三星大中华区总裁称Galaxy S III提前至4月份发布
  7. jetson nano 开发:与主机共用一套键鼠设置
  8. 这几个免费资源网站太强了!老司机们都收藏了!
  9. linux nginx日志分割,Linux下自动分割Nginx日志文件(二)-----Cronolog
  10. 新款MacBook Pro将迎来重大升级!触控条消失、MagSafe回归