带有自定义按钮,LWUIT,J2ME的对话框

时间:2012-12-17 14:56:34

标签: java-me lwuit

我想在J2ME LWUIT应用程序中显示一个对话框。在对话框中,我可以添加文本区域和按钮。现在,当我点击按钮时,我想关闭对话框。我的代码在下面,我想在按下“确定”按钮的同时关闭按钮。

              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 个答案:

答案 0 :(得分:1)

为什么你不使用对话框并在他身上添加所有组件?

如果您使用它,您只能写入行动前福特函数:

okbut.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ae)                    {                          dialogName.dispose();
                   }                    } );

您无法处置Container。你唯一能做的就是让他失效并再次执行该表格。

相关问题