百度网盘链接: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. dns短域名会引起nslookup解析总解析到一个IP
  2. 世界上最遥远的距离(泰戈尔)
  3. mysql rpm包安装指定路径_安装rpm包时指定路径
  4. 1. 冒泡与选择排序及其比较
  5. GLSL Optimizer
  6. ionic入门教程第五课-举例子说明异步回调$q及$q在项目中的用法
  7. Best Coder Round#25 1003 树的非递归访问
  8. 日撸 Java 三百行(71-80天,BP 神经网络)
  9. sas 服务器版安装文件,安装SAS怎样配置服务器
  10. springboot权限管理系统
  11. pychart绘制中国地图用英文省名
  12. 各种软件系统架构图解析
  13. 【Docker】03 Docker的常用命令
  14. OC中类别(Catagory)基本使用
  15. Python识别二维码条形码?用pyzbar一招搞掂(含代码)
  16. 分布式机器学习_229页CMU博士张昊毕业论文公布,探索机器学习并行化的奥秘
  17. 补色的视觉原理(转)
  18. 教会AI认识麻将牌之实践篇
  19. mac广告拦截软件:1Blocker for Mac
  20. checkstyle + gradle + git pre-commit 实现代码提交前对代码规范的检查

热门文章

  1. No enclosing instance of type xxx is accessible
  2. 九月5G你选谁?瀑布屏外加透明全景屏来袭,OPPO5G手机配置大曝光
  3. redhat6.5搭建smb+www+web+dns服务
  4. Get新技能:用C语言代码打开网页
  5. Python学习(十七)—— 数据库(二)
  6. GIS数据格式坐标转换(地球坐标WGS84、GCJ-02、火星坐标、百度坐标BD-09、国家大地坐标系CGCS2000)
  7. 物联网技术LoRa是什么,主要有哪些技术特色?
  8. mybatis向mysql数据库插入数据时,中文乱码显示为?解决方法
  9. 图的顺序存储及其深度优先遍历和广度优先遍历
  10. 如何明晰定位与责任_学会如何自我定位