1

我无法弄清楚为什么在单击按钮更新页面内容后下一页/上一页按钮停止工作。

我的示例程序的代码如下。在您使用方向键单击 Kindle 上的“开始”按钮之前,下一页/上一页按钮可以正常工作。之后,下一页/上一页按钮不做任何事情。我究竟做错了什么?

package com.example;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.apache.log4j.Logger;

import com.amazon.kindle.kindlet.AbstractKindlet;
import com.amazon.kindle.kindlet.KindletContext;
import com.amazon.kindle.kindlet.ui.KBoxLayout;
import com.amazon.kindle.kindlet.ui.KButton;
import com.amazon.kindle.kindlet.ui.KPages;
import com.amazon.kindle.kindlet.ui.KPanel;
import com.amazon.kindle.kindlet.ui.pages.PageProviders;

public class MyKindlet extends AbstractKindlet {    
    private static Logger logger = Logger.getLogger(MyKindlet.class);

    private KindletContext context;
    private final KPages pages = new KPages(PageProviders.createKBoxLayoutProvider(KBoxLayout.Y_AXIS));

    public void create(final KindletContext context) {
        this.context = context;

        for (int i = 0; i < 50; i++) {
            pages.addItem("This is item " + i);
        }
        logger.debug("pages: " + pages.getComponentCount());

        context.getRootContainer().add(pages, BorderLayout.CENTER);

        KPanel pnlControls = new KPanel();
        KButton btnGo = new KButton("Go!");
        pnlControls.add(btnGo);

        context.getRootContainer().add(pnlControls, BorderLayout.SOUTH);

        btnGo.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        addMoreItems("Yet another item ");
                    }
                });
            }
        });

        addMoreItems("Another item ");
    }

    private void addMoreItems(String prefix) {
        for (int i = 0; i < 50; i++) {
            pages.addItem(prefix + i);
        }
    }

    public void start() {
    }    

    public void stop() {
    }    

    public void destroy() {
    }
}

开发/测试环境:

KDK API 1.0
Kindle Keyboard (Kindle 3) emulator
JDK6/JRE6
Eclipse Indigo SR1
JDK compliance level 1.4
4

1 回答 1

1

KPages当容器失去焦点时,我们已经看到了这个问题。试着打电话

pages.requestFocus();
于 2012-03-23T10:04:19.040 回答