How do I convert Java deque to defaultlistmodel?

I wrote a class containing deque < T > (we call it model. Java), which contains methods for queuing and dequeuing items Now I want to bind it to GUI JList I'm confused about how to use my "model" data – deque – in some way as the defaultlistmodel JList wants I'm still trying to really get OO concepts because they're suitable for GUI programming Defaultlistmodel document description:

Is there a way for defaultlistmodel to use my deque < T > instead of vector to allow my model The Java code remains basically unchanged, and all listening / notification behaviors are provided for free? Or do I have to rewrite the model Java to use defaultlistmodel instead of deque < T >?

Solution

Note that the JList constructor takes listmodel (Interface) instead of defaultlistmodel (Implementation) This is an OO principle (contract) that specifies that JList can use any object that happens to implement the listmodel interface Java tutorial from object oriented programming concepts:

Since listmodel has only four methods, your class should easily implement them and delegate operations to your internal deque Your class should be declared

public class Model implements ListModel
{
     ....

It will include four other methods that implement the listmodel method These implementations can do whatever you need, but they must comply with the definition of listmodel and any behavior specified in Javadoc as part of the listmodel contract

After this operation, you can construct a JList and pass an instance of the class model to the constructor

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>