zoukankan      html  css  js  c++  java
  • 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");

  • 相关阅读:
    前缀判断 蓝桥杯
    dedecms 网站内容静态化和动态化的切换
    dedecms 频道标签 channel.lib.php的分析
    JavaScript通过闭包解决只能取得包含函数中任何变量最后一个值的问题
    JavaScript闭包 取for循环i 【转】
    JavaScript装饰模式
    JavaScript闭包意义谈
    JavaScriptjs闭包测试
    JavaScript闭包的作用谈(转)
    Zend Engine 简介
  • 原文地址:https://www.cnblogs.com/-zpy/p/5016273.html
Copyright © 2011-2022 走看看