0

更新: 我的要求是在我的 LWUIT 表单上将两个 Rss 文件显示为选项卡最初默认情况下,如果最终用户单击第二个选项卡,则第一个 Rss 文件标题和图像应显示在第一个选项卡上,我们应该能够加载第二个 rss 文件标题和图像 我可以加载第一个 Rss 文件标题,但是如果我单击它,我无法加载第二个选项卡 如何捕获 LWUIT 选项卡的单击事件?这是我的代码不起作用: String topNewsurl="TopNews.rss"; 字符串 topStoryurl="TopStory.rss";

public class XMLMidlet extends MIDlet{
    public void startApp() {
               Display.init(this);

        Process p;
        try {
            p = new Process(this);
                    p.process();

        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }



 public class Process extends Form {


     Process(XMLMidlet midlet) throws IOException {
               this.midlet=midlet;
               topnews = new Vector();
            topstory = new Vector();
           tabs = new Tabs();
            form1 = new Form();
            form2=new Form();
                form1.setLayout(new BorderLayout());
                form1.setScrollable(false);
                image = Image.createImage("/res/Tone.jpg");
                Label icon = new Label(image);
                form1.setTitleComponent(icon);
                form2.setTitleComponent(icon);

                form1.setTransitionInAnimator(Transition3D.createRotation(250, true));
                try {
                newsList = new List(topnews);
                newsList.setScrollVisible(false);

                newsList.setRenderer(new NewsListCellRenderer());

                myNewsList = new List(topstory);
                myNewsList.setScrollVisible(false);

                myNewsList.setRenderer(new NewsListCellRenderer());        
         tabs.addTab("Topstory", newsList);
                tabs.addTab("TopNews", myNewsList);
                 tabs.setChangeTabOnFocus(true);
               form1.addComponent(BorderLayout.CENTER, tabs);
        }  
     try{
String url = "http:topnews-20.rss";




             form1.show();


                        ParseThread myThread = new ParseThread(this);
            myThread.getXMLFeed(url);

    } catch (Exception e) {

        e.printStackTrace();
    }

}
public void addNews(News newsItem) {
        //log.debug("addnews");
      //System.out.println("addNews");

            topnews.addElement(newsItem);
            newsList.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent ae) {

                    List source = (List) ae.getSource();
                    News selectedNewsItem = (News) source.getSelectedItem();
                    if (selectedNewsItem != null) {
                        displayCompleteNewsScreen(selectedNewsItem);

                    }

                }


            });
        form1.show();


    } 


     public void keyReleased(int keyCode) {
                   System.out.println("str");

            Component p=this.getFocused();
           String str= p.getClass().getName();
        if(str.toLowerCase().indexOf("radiobutton")!=-1){
            process();
        }
4

1 回答 1

1

从非常模糊的问题来看,您似乎想在 LWUIT 表单上捕获按键。

        jobsForm.addGameKeyListener(Display.GAME_FIRE,
                new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                    //do something here
                    }
                });

        jobsForm.addPointerPressedListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                pointer_click = true;
            }
        });

        jobsForm.addPointerReleasedListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                if (pointer_click) {
                    //
                }
                pointer_click = false;
            }
        });

        jobsForm.addPointerDraggedListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                //System.out.println("POINTER DRAGGED");
                pointer_click = false;
            }
        });
于 2012-08-30T20:53:51.323 回答