博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java基础知识:Java实现Map集合二级联动3
阅读量:5126 次
发布时间:2019-06-13

本文共 3767 字,大约阅读时间需要 12 分钟。

* 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");

转载于:https://www.cnblogs.com/-zpy/p/5016273.html

你可能感兴趣的文章
提高码力专题(未完待续)
查看>>
pair的例子
查看>>
前端框架性能对比
查看>>
uva 387 A Puzzling Problem (回溯)
查看>>
12.2日常
查看>>
同步代码时忽略maven项目 target目录
查看>>
Oracle中包的创建
查看>>
团队开发之个人博客八(4月27)
查看>>
发布功能完成
查看>>
【原】小程序常见问题整理
查看>>
C# ITextSharp pdf 自动打印
查看>>
【Java】synchronized与lock的区别
查看>>
django高级应用(分页功能)
查看>>
【转】Linux之printf命令
查看>>
关于PHP会话:session和cookie
查看>>
STM32F10x_RTC秒中断
查看>>
display:none和visiblity:hidden区别
查看>>
C#double转化成字符串 保留小数位数, 不以科学计数法的形式出现。
查看>>
牛的障碍Cow Steeplechase
查看>>
Zookeeper选举算法原理
查看>>