* 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. ASP.NET 跨域请求之jQuery的ajax jsonp的使用解惑 (转载)

    前天在项目中写的一个ajax jsonp的使用,出现了问题:可以成功获得请求结果,但没有执行success方法,直接执行了error方法提示错误——ajax jsonp之前并没有用过,对其的理解为跟普 ...

  2. 多python版本下,使用pip安装第三方库

    说明:win10系统,先安装有Python3.5.2,后又安装了Python2.7.13(并重命名了Python27文件夹下python.exe为python2.7.13.exe),试图使用pip安装 ...

  3. 小程序内嵌H5——判断小程序环境的坑

    现在各种小程序风靡,这边H5的需求还没有搞定,产品又要求做小程序版本,做可以,关键是618前上线,我-- whatever,618要做推广,日期订了,剩下的就只能是排期,定方案,尽可能完成. 最后和产 ...

  4. windows安装的mysql中文乱码的坑

    本机装的mysql为5.6的,从代码执行的中文inert语句总是显示问号,然后在中文查询是都会报问题 今天终于解决了! 问题解决方法为: 找到my.ini文件在文件中加入 [client]defaul ...

  5. 常见的springmvc、SpringBoot的注解

    springMvc的常用注解 : @Controller :用于标记在一个类上,使用它标记的类就是一个springmcv Controller对象,分发处理器将会扫描使用了该注解 的类的方法,并检测该 ...

  6. 算法基础-dfs

    最近在学dfs(深度优先搜索),dfs与树的遍历差不多,就是先从一个点开始一直搜索,直到走不动为止.现在推荐一个简单的dfs题, 百炼的2815, ########################## ...

  7. CF1066B Heaters(贪心)

    题意描述: Vova先生的家可以看作一个n×1的矩形,寒冷的冬天来了,Vova先生想让他的家里变得暖和起来.现在我们给你Vova先生家的平面图,其中111表示这个地方是加热炉,0表示这个地方什么也没有 ...

  8. 【2015 ICPC亚洲区域赛长春站 G】Dancing Stars on Me(几何+暴力)

    Problem Description The sky was brushed clean by the wind and the stars were cold in a black sky. Wh ...

  9. Eclipse易卡死

    在用eclipse编辑项目的时候,经常卡死,经过查询知道原来是我的JDK和eclipse版本对应的不好,我们都知道,eclipse的环境需要配置. 当时情况是这样的 2.容易出现卡死或者如图所示的情况 ...

  10. 【Spark】源码分析之spark-submit

    在客户端执行脚本sbin/spark-submit的时候,通过cat命令查看源码可以看出,实际上在源码中将会执行bin/spark-class org.apache.spark.deploy.Spar ...