试图让Hash Maps与JComboBox一起使用

时间:2015-12-02 11:00:24

标签: java hashmap jcombobox

我试图获取一个哈希映射来显示有多少培训师正在使用人们被添加到有多少人正在训练可以任何人帮助我我有jcombox我只是不能让它使用哈希映射它dosnet做任何事。

 {
           String [] carSales = {"Mick", "Jeff", "Ian", "Andrew", "David" };
           JComboBox<String> trainerList = new JComboBox<String>(carSales);
           JOptionPane.showMessageDialog(null,trainerList );
        Map<String, Integer> vehicles = new HashMap<String, Integer>();

        // Add some vehicles.
        trainerList.put("Mick",4 );
        trainerList.put("Mercedes", 3);
        trainerList.put("Audi", 4);
        trainerList.put("Ford", 10);

        System.out.println("Total vehicles: " + vehicles.size());

        // Iterate over all vehicles, using the keySet method.
        for(String key: trainerList.keySet())
            System.out.println(key + " - " + vehicles.get(key));
        System.out.println();

        String searchKey = "Audi";
        if(vehicles.containsKey(searchKey))
            System.out.println("Found total " + vehicles.get(searchKey) + " "
                    + searchKey + " cars!\n");

        // Clear all values.
        vehicles.clear();

        // Equals to zero.
        System.out.println("After c`enter code here`lear operation, size: " + vehicles.size());
           }

0 个答案:

没有答案