此API如何获取JList(String)的项

时间:2013-03-31 03:20:56

标签: java swing casting jlist defaultlistmodel

我有一个包含几个项目的JList,然后我得到了一个API,需要获取所选项目并使用它来提供有关该项目的一些信息。我的问题是JList的类型是String,我的API的类型显然是不同的。让我们说LocationAPI。因此,API仅从其自己的类型而不是其他类型获取索引。我正在寻找一个解决方案,将选定的项目(String)转换为适合API的东西。以下是API的一个简单示例。

LinkedList<LocationAPI> stations = FetchWeatherForecast.findWeatherStationsNearTo("cityName");
for (LocationAPI station : stations) { System.out.println(station); }

// Assume the first match on the list is correct
LocationAPI firstMatch = stations.getFirst();

List<ForecastForOneDay> forecast = FetchWeatherForecast.getWeatherForecast(firstMatch);

所以这是一个简单的API如何工作的例子,但是我必须使用自己的项目和列表来代替'firstMatch'和'Station'。我得到了项目和列表,但我做了不同的事情:

DefaultListModel<String> cityPlace = new DefaultListModel<String>();
JList myList = new JList(cityPlace);

那么如何在API中使用上面列表中的项目?

0 个答案:

没有答案