* 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. LeetCode18.四数之和 JavaScript

    给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target 相等?找出所有满 ...

  2. Error Note1:错误修复笔记

    1.遍历同时修改数组内容导致崩溃 bugly上bug提醒如下图所示,经检查发现,可能是页面上数据加载惹得祸. 页面加载过程是这样的,首先进入页面,初始化页面,将本地数据加载到array中刷新table ...

  3. SQLMAP注入常见用法

    1.检查注入点 sqlmap -u http://www.com.tw/star_photo.php?artist_id=11 2.列数据库信息当前用户和数据库 sqlmap -u http://ww ...

  4. 用VMWare搭建服务器集群不能上外网的三种模式下对应解决办法

    前言 决心要花费宝贵时间写下这篇心得,是因为从昨天晚上到今天上午被这个VMWare模拟搭建的服务器集群不能上外网的问题搞得很心烦,最后决定跟它杠上了!上午还通过远程连接得到了“空白”同学的帮助,在此表 ...

  5. systemd的新特性及常见的systemd unit类型分析

    systemd概述 )systemd是一种新的linux系统服务管理器,用于替换init系统,能够管理系统启动过程和系统服务,一旦启动起来,就将监管整个系统.在centos7系统中,PID1被syst ...

  6. 解决jquey中当事件嵌套时,内层事件会执行多次的问题

    出现情景:当内层事件需要外层事件触发后产生的一些值得时候 情景复现: <!DOCTYPE html> <html lang="en"> <head&g ...

  7. @Component注解、@Service注解、@Repository注解、@Controller注解区别

    --------------------------------------------------------------------------------------------------- ...

  8. UML类图介绍以及PlantUML使用方法

    类的UML表示方法 UML介绍 类图,是UML(统一建模语言)中用于描述"类"以及"类与类"之间的示意图.它形象的描述出了系统的结构,帮助人们理解系统. 类图是 ...

  9. QWT编译与配置-Windows/Linux环境

    QWT编译与配置-Windows/Linux环境 QWT和FFTW两种开源组件是常用的工程软件支持组件,QWT可以提供丰富的绘图组件功能,FFTW是优秀数字波形分析软件.本文使用基于LGPL版权协议的 ...

  10. PTA基础编程题目集7-3逆序三位数

    7-3 逆序的三位数 (10 分) 程序每次读入一个正3位数,然后输出按位逆序的数字.注意:当输入的数字含有结尾的0时,输出不应带有前导的0.比如输入700,输出应该是7. 输入格式: 每个测试是一个 ...