Java基础知识:Java实现Map集合二级联动3
* 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的更多相关文章
- Java基础知识:Java实现Map集合二级联动1
Java实现Map集合二级联动 Map集合可以保存键值映射关系,这非常适合本实例所需要的数据结构,所有省份信息可以保存为Map集合的键,而每个键可以保存对应的城市信息,本实例就是利用Map集合实现了省 ...
- JAVA基础知识|java虚拟机(JVM)
一.JVM简介 java语言是跨平台的,兼容各种操作系统.实现跨平台的基石就是虚拟机(JVM),虚拟机不是跨平台的,所以不同的操作系统需要安装不同的jdk版本(jre=jvm+类库:jdk=jre+开 ...
- Java基础知识:Java实现Map集合二级联动2
2. 定义获取省份的方法,创建一个Map集合,将上一步得到的映射集合赋值给它,使用Map集合的keySet()方法获取该集合中的所有键对象组成的Set 集合,即为省分集合,创建一个Object型一维数 ...
- Java基础知识:Java实现Map集合二级联动4
comboBox.setModel(new DefaultComboBoxModel(getProvince())); // 添加省份信息 final JLabel label = new JLabe ...
- Java实现Map集合二级联动
Map集合可以保存键值映射关系,这非常适合本实例所需要的数据结构,所有省份信息可以保存为Map集合的键,而每个键可以保存对应的城市信息,本实例就是利用Map集合实现了省市级联选择框,当选择省份信息时, ...
- Java基础知识总结之类的集合
Java集合概述 1.集合类也叫作容器类.它的功能相当于一个容器.可以存储数量不确定的数据,以及保存具有映射关系的数据(也被称为关联数组). 2.Java的集合(容器),它是用来”装对象的“(实际上是 ...
- JAVA基础知识总结15(集合容器)
集合框架:用于存储数据的容器. 1:对象封装数据,对象多了也需要存储.集合用于存储对象. 2:对象的个数确定可以使用数组,但是不确定怎么办?可以用集合.因为集合是可变长度的. 集合和数组的区别: 1: ...
- java基础知识——Java的定义,特点和技术平台
(作者声明:对于Java编程语言,很多人只知道怎么用,却对其了解甚少.我也是其中一员.所以菜鸟的我,去查询了教科书以及大神的总结,主要参考了<Java核心技术>这本神作.现在分享给大家!) ...
- [java基础知识]java安装步骤
jre: java运行环境. jre = java虚拟机 + 核心类库(辅助java虚拟机运行的文件).如果只是运行java程序,只需要安装jre. jdk: java开发工具集 jd ...
随机推荐
- 【Node.js学习笔记】使用Gulp项目自动化构建工具
刚接触node.js,对前端的一些东西还不是很清楚,据说Gulp这东西很强大,先来看看从网上抄的一段关于自动化构建的描述: 在为数众多的中小型软件作坊中,不存在自动化构建和发布工具.构建.交付准备环境 ...
- STM32之关闭JTAG
1.有些时候不想用JTAG口(而用SWJ在线调试),把JTAG暂用的IO通过remap出来使用 2.比如48 pin的STM32F103CBT6单片机: GPIO_PinRemapConfig(GPI ...
- Oracle数据库新装之后出现的监听程序无法正常启动和运行(Oracle-12514)
修改安装目录下的配置文件 比如:F:\app\admin-PC\product\11.2.0\dbhome_1\network\admin\ 修改这个目录下的listener.ora和tns ...
- 《DOM编程艺术》读书笔记<概述>
作为一名前端开发工程师,学习的过程中总少不了各种各样的书籍,作为新手如何在众多书籍中选到适合自己的呢,我们今天先来谈谈<DOM编程艺术>这本书. 其实呢大部分书都是好书,就像LOL中大部分 ...
- python人工智能爬虫系列:怎么查看python版本_电脑计算机编程入门教程自学
首发于:python人工智能爬虫系列:怎么查看python版本_电脑计算机编程入门教程自学 http://jianma123.com/viewthread.aardio?threadid=431 本文 ...
- 竞赛题解 - Karp-de-Chant Number(BZOJ-4922)
Karp-de-Chant Number(BZOJ-4922) - 竞赛题解 进行了一次DP的练习,选几道题写一下博客~ 标签:BZOJ / 01背包 / 贪心 『题目』 >> There ...
- Systemd简介与使用
按下电源键,随着风扇转动的声音,显示器上开启的图标亮起.之后,只需要静静等待几秒钟,登录界面显示,输入密码,即可愉快的玩耍了. 这是我们大概每天都做的事情.那么中间到底发生了什么? 简单地说,从BIO ...
- C#程序员快速上手Angular开发
由vue的技术栈快速切换到Angular,对于C#开发人员来说应该不难,二期是一个比较平滑的过渡.所以最近 记录下切换到Angular框架的一些过程,因为NG天然支持Typescript,特别是当项目 ...
- Java学习笔记十九:Java中的访问控制修饰符
Java中的访问控制修饰符 一:Java修饰符的种类: 访问修饰符 非访问修饰符 修饰符用来定义类.方法或者变量,通常放在语句的最前端.我们通过下面的例子来说明: public class Hello ...
- FIFO队列 ADT接口 链表实现
FIFO.h (接口) #include "Item.h" void QUEUinit(int); int QUEUempty(void); void QUEUput(Item); ...