开发者

Can LinkedList accept an Image Icon?

How can I write a GUI LinkedList program by Java to push Image files instead of other data type items?

For the push instruction I wish to give开发者_JAVA技巧 the name of the image file to add it in to the LinkedList, and set the pop instruction to remove the image ?


As you can store any Object in a LinkedList you could either store the Filename as a String, the File Object or the ImageIcon Object in the list. Using genercis makes things easy:

List<String> fileAsString = new LinkedList<String>();
List<File> fileObject= new LinkedList<File>();
List<ImageIcon> imageIcon= new LinkedList<ImageIcon>();


Yes LinkedList accepts Object


You can use generic linked lists from java.util package for type safety.

LinkedList<Image> imageList = new LinkedList<Image>();

However to be able push by name, you need wrap it around in your own implementation class. And override the push method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜