0

I want to show a Dialog box in my J2ME LWUIT application. In the dialog box i am able to add text area and buttons. Now i wan to close the dialog when i click the button. My code is below and i want to close the button while pressing "ok" button.

              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);
DAC84
  • 421
  • 1
  • 8
  • 20

1 Answers1

1

Why you dont use dialog and adding all components on him?

if you use that you can only write in action premford function:

okbut.addActionListener(new ActionListener() {

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

You can't dispose Container. the only thing that you can do is to give him null and excute the form again.

neb1
  • 209
  • 1
  • 12
  • Thanks for your reply. I am currently using that model only. But the problem is , when i call "dialogName..show("SnorkelOTP-Info", dispback, null,0,TransotionObj);" , "Netbeans" showing warning saying "Accessing static method show". – DAC84 Dec 18 '12 at 09:53
  • If you get into Lwuit class Dialog . you can see that most of the functons show(...) are static except to of them. – neb1 Dec 18 '12 at 10:05
  • So i think we should call those functions using "Dialog.show()" instead of "dialogName.show()". Am i correct?. If i am correct, then how could i use "dialogName.dispose()". – DAC84 Dec 18 '12 at 12:59
  • You can use your dialog and call to show(). but pay attention if you want to controll on text title and text that be have in dialog you can do it by 2 ways: 1. if is standart (title,okbutton and cancel button you can use ststic sohw functions in dialog calss. 2. another way is to add components to dialog and overtake the needed using in static methods – neb1 Dec 18 '12 at 13:19
  • As per my requirement, i must use the second way. I also want to set a image in the background of the dialog also. So can i use "dialogName.show()" ,even though it throw warning? – DAC84 Dec 18 '12 at 14:13
  • Warning is only a warning..it's tell us that we need to be careful because this code may be problamtic In what situation. function show() isn't static so.. – neb1 Dec 19 '12 at 06:25