2012-12-17 33 views
0

我想在我的J2ME LWUIT應用程序中顯示一個對話框。在對話框中,我可以添加文本區域和按鈕。現在我想單擊按鈕時關閉對話框。我的代碼在下面,我想關閉按鈕,同時按下「確定」按鈕。帶自定義按鈕的對話框,LWUIT,J2ME

   Container dispback = new Container(new BoxLayout(BoxLayout.Y_AXIS)); 
       TextArea textArea = new TextArea(Message); //pass the alert text here 
       textArea.setFocusable(false); 
       textArea.setEditable(false); 
       Font fnt=Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM); 
       textArea.getStyle().setFont(fnt); 
       textArea.getSelectedStyle().setBorder(null); 
       textArea.getUnselectedStyle().setBorder(null); 
       textArea.getStyle().setFgColor(0xFF0000); 
       textArea.getStyle().setBgTransparency(0); 
       textArea.setIsScrollVisible(false); 
       textArea.getStyle().setMargin(20,0,0,0); 

       Button okbut = new Button("OK"); 
       //okbut.setAlignment(Component.CENTER); 
       okbut.getStyle().setFont(fnt); 
       okbut.addActionListener(new ActionListener() { 

         public void actionPerformed(ActionEvent ae) 
         { 
         **//How to close my dialog here** 
         } 
         }); 

       dispback.addComponent(textArea); 
       okbut.setWidth(10); 
       dispback.addComponent(okbut); 

       Dialog.show("SnorkelOTP-Info", dispback, null,0,null); 

回答

1

爲什麼你不使用對話框並添加他所有的組件?

如果你使用,你可以在行動premford功能只寫:

okbut.addActionListener(新的ActionListener(){

公共無效的actionPerformed(ActionEvent的AE) { dialogName.dispose();
} } );

您不能處理Container。你唯一能做的就是給他null並且再次執行表單。

+0

感謝您的回覆。我目前只使用該模型。但問題是,當我調用「dialogName..show(」SnorkelOTP-Info「,撤銷,null,0,TransotionObj);」 ,「Netbeans」顯示警告「訪問靜態方法顯示」。 – DAC84

+0

如果你進入Lwuit類對話框。你可以看到大多數函數表示(...)除了它們之外都是靜態的。 – neb1

+0

所以我認爲我們應該使用「Dialog.show()」而不是「dialogName.show()」來調用這些函數。我對麼?。如果我是正確的,那麼我怎麼能使用「dialogName.dispose()」。 – DAC84

相關問題