如何使用LWUIT TAB单击事件

时间:2012-08-30 05:26:16

标签: java-me lwuit

更新 我的要求是在我的LWUIT表单上显示两个Rss文件作为选项卡 最初默认情况下,第一个选项卡上应显示第一个Rss文件标题和图像 如果最终用户点击第二个标签,我们应该能够加载第二个rss文件标题和图像 我能够加载第一个Rss文件标题,但如果我点击它我无法加载第二个标签 如何捕获LWUIT标签的点击事件? 这里我的代码不起作用: String topNewsurl =“TopNews.rss”; String 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();
        }

1 个答案:

答案 0 :(得分: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;
            }
        });