* Returns an image stored in the file at the specified path

  * @param path String The path to the image file

  * @return Image The image stored in the file at the specified path

  */

  public static Image getImage(String path) {

  return getImage("default", path); //$NON-NLS-1$

  }

  /**

  * Returns an image stored in the file at the specified path

  * @param section String The storage section in the cache

  * @param path String The path to the image file

  * @return Image The image stored in the file at the specified path

  */

  public static Image getImage(String section, String path) {

  String key = section + '|' + SwingResourceManager.class.getName() + '|' + path;

  Image image = m_ClassImageMap.get(key);

  if (image == null) {

  try {

  FileInputStream fis = new FileInputStream(path);

  image = getImage(fis);

  m_ClassImageMap.put(key, image);

  fis.close();

  } catch (IOException e) {

  return null;

  }

  }

  return image;

  }

  /**

  * Clear cached images in specified section

  * @param section the section do clear

  */

  public static void clearImages(String section) {

  for (Iterator I = m_ClassImageMap.keySet().iterator(); I.hasNext();) {

  String key = I.next();

  if (!key.startsWith(section + '|'))

  continue;

  Image image = m_ClassImageMap.get(key);

  image.flush();

  I.remove();

  }

  }

  /**

  * Returns an icon stored in the file at the specified path relative to the specified class

  * @param clazz Class The class relative to which to find the icon

  * @param path String The path to the icon file

  * @return Icon The icon stored in the file at the specified path

  */

  public static ImageIcon getIcon(Class clazz, String path) {

  return getIcon(getImage(clazz, path));

  }

  /**

  * Returns an icon stored in the file at the specified path

  * @param path String The path to the icon file

  * @return Icon The icon stored in the file at the specified path

  */

  public static ImageIcon getIcon(String path) {

  return getIcon("default", path); //$NON-NLS-1$

  }

  /**

  * Returns an icon stored in the file at the specified path

  * @param section String The storage section in the cache

  * @param path String The path to the icon file

  * @return Icon The icon stored in the file at the specified path

  */

  public static ImageIcon getIcon(String section, String path) {

  return getIcon(getImage(section, path));

  }

  /**

  * Returns an icon based on the specified image

  * @param image Image The original image

  * @return Icon The icon based on the image

  */

  public static ImageIcon getIcon(Image image) {

  if (image == null)

  return null;

  return new ImageIcon(image);

  }

  }

  MainFrame.java

  import java.awt.EventQueue;

  import java.awt.event.ItemEvent;

  import java.awt.event.ItemListener;

  import java.util.Map;

  import java.util.Set;

  import javax.swing.DefaultComboBoxModel;

  import javax.swing.JButton;

  import javax.swing.JComboBox;

  import javax.swing.JFrame;

  import javax.swing.JLabel;

  import javax.swing.JPanel;

  import javax.swing.JTextField;

  import javax.swing.SwingConstants;

  import javax.swing.UIManager;

  import javax.swing.border.TitledBorder;

  public class MainFrame extends JFrame {

  /**

  *

  */

  private static final long serialVersionUID = -4595347311922711984L;

  private JTextField textField_3;

  private JTextField textField_1;

  private JComboBox comboBox_1;

  private JTextField textField;

  private JComboBox cityComboBox;

  private JComboBox comboBox;

  /**

  * Launch the application

  *

  * @param args

  */

  public static void main(String args[]) {

  EventQueue.invokeLater(new Runnable() {

  public void run() {

  try {

  UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");

Java基础知识:Java实现Map集合二级联动3的更多相关文章

  1. Java基础知识:Java实现Map集合二级联动1

    Java实现Map集合二级联动 Map集合可以保存键值映射关系,这非常适合本实例所需要的数据结构,所有省份信息可以保存为Map集合的键,而每个键可以保存对应的城市信息,本实例就是利用Map集合实现了省 ...

  2. JAVA基础知识|java虚拟机(JVM)

    一.JVM简介 java语言是跨平台的,兼容各种操作系统.实现跨平台的基石就是虚拟机(JVM),虚拟机不是跨平台的,所以不同的操作系统需要安装不同的jdk版本(jre=jvm+类库:jdk=jre+开 ...

  3. Java基础知识:Java实现Map集合二级联动2

    2. 定义获取省份的方法,创建一个Map集合,将上一步得到的映射集合赋值给它,使用Map集合的keySet()方法获取该集合中的所有键对象组成的Set 集合,即为省分集合,创建一个Object型一维数 ...

  4. Java基础知识:Java实现Map集合二级联动4

    comboBox.setModel(new DefaultComboBoxModel(getProvince())); // 添加省份信息 final JLabel label = new JLabe ...

  5. Java实现Map集合二级联动

    Map集合可以保存键值映射关系,这非常适合本实例所需要的数据结构,所有省份信息可以保存为Map集合的键,而每个键可以保存对应的城市信息,本实例就是利用Map集合实现了省市级联选择框,当选择省份信息时, ...

  6. Java基础知识总结之类的集合

    Java集合概述 1.集合类也叫作容器类.它的功能相当于一个容器.可以存储数量不确定的数据,以及保存具有映射关系的数据(也被称为关联数组). 2.Java的集合(容器),它是用来”装对象的“(实际上是 ...

  7. JAVA基础知识总结15(集合容器)

    集合框架:用于存储数据的容器. 1:对象封装数据,对象多了也需要存储.集合用于存储对象. 2:对象的个数确定可以使用数组,但是不确定怎么办?可以用集合.因为集合是可变长度的. 集合和数组的区别: 1: ...

  8. java基础知识——Java的定义,特点和技术平台

    (作者声明:对于Java编程语言,很多人只知道怎么用,却对其了解甚少.我也是其中一员.所以菜鸟的我,去查询了教科书以及大神的总结,主要参考了<Java核心技术>这本神作.现在分享给大家!) ...

  9. [java基础知识]java安装步骤

    jre:  java运行环境.  jre =  java虚拟机 + 核心类库(辅助java虚拟机运行的文件).如果只是运行java程序,只需要安装jre.    jdk: java开发工具集   jd ...

随机推荐

  1. mac os 隐藏文件夹的小技巧

    无论是谁,电脑里总有些不想让人看到的内容,或是私密日记,或是某播下载的奇怪东西,对于这些东西当然是不想被人看到的.怎么办呢? 有人说了几种方法: 1. 改名字: 2. 把文件夹做成加密DMG: 3. ...

  2. asp.net mvc5 step by step(三)—— Entity Framework Database First

    一.先建数据库. 打开,SQL Server Management 新建数据库Employee 并新建表 /****** Object: Table [dbo].[t_Employee] Script ...

  3. 840. Magic Squares In Grid (5月27日)

    开头 这是每周比赛中的第一道题,博主试了好几次坑后才勉强做对了,第二道题写的差不多结果去试时结果比赛已经已经结束了(尴尬),所以今天只记录第一道题吧 题目原文 Magic Squares In Gri ...

  4. 解决微信小程序安卓手机访问不到图片,无法显示图片

    关于微信小程序不显示图片 通病可能有以下几个可能性: 非本地图片:确定图片资源存在,copy 图片url再浏览器打开,确定图片资源存在且能正常访问 本地图片:确定相对路径或者绝对路径正确 微信小程序图 ...

  5. Jquery中菜单的展开和折叠

    jquery内容 <script> $(function () { $("dl dt").click(function () { $(this).siblings(). ...

  6. 使用Wamp搭建Php本地开发环境,HBuilder调试

    初涉Php,此处做点笔记,希望下次不要能够轻松应对,至少不要在入同一个坑 本文摘要: wamp和HBuilder和Mysql5.7的安装包 Wamp的使用,包括80端口,443端口的占用问题 HBui ...

  7. Home Assistant系列美化篇——替换天气 UI

    替换天气组件 weather 的默认 UI,生成美观大方的气象卡片. Home Assistant 原生的天气平台不少,国内用户常用的有雅虎天气和 Darksky.其他论坛和社区也有分享自制的和风.彩 ...

  8. JVM基础知识及拓展

    我们可以吧JVM的基本结构分为四块:类加载器.执行引擎.运行时数据区和本地接口.一般来说Java程序在JVM中的执行流程如下: ①.首先我们会利用javac命令将我们所编写的.java源代码文件变异成 ...

  9. python2.7入门---CGI编程&表单操作&cookie操作

        看到标题我们首先有个疑问,什么是CGI?CGI 目前由NCSA维护,NCSA定义CGI为:CGI(Common Gateway Interface),通用网关接口,它是一段程序,运行在服务器上 ...

  10. Java基础—ArrayList源码浅析

    注:以下源码均为JDK8的源码 一. 核心属性 基本属性如下: 核心的属性其实是红框中的两个: //从注释也容易看出,一个是集合元素,一个是集合长度(注意是逻辑长度,即元素的个数,而非数组长度) 其中 ...