How show a frame as Dialog.?

I had create Frame1 as main form and Frame2 as option form.

I want to show Frame2 then click the Option button in Frame1.
And user can not return to Frame1 until close Frame2.

In delphi and VB has ShowModal method but I don't khow how in JAVA.
wachiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amitdCommented:
in java we have class called dialog in java.awt
so insted of using Frame2 which gets pop up after clicking options use dialog object
which has a constructor
public Dialog(Frame parent,
               String title,
               boolean modal)
so set modal =true
u get  ur requirement
public class  FrameDemo extends Frame implements ActionListener
{
   private Dialog d;
   private Button b;
   public void FrameDemo()
{
 
   b = new Button("click");
}

click()
{
  d = new Dialog( this,"options",true);
  d.addWindowListener(newWndowAdapter())
  add(d);
 setSize(300,200);//as per ur requirement
 b.addActionListner(this);
 add(BorderLayout.SOUTH,b);
 setVisible(true);
}
public void actionPerformed()
{
 d.show();

}
}
now what u have to do is write a class windowAdapter which will call method d.dispose()
so that control can be back to main window when u click X on the window bar
Best of luck
0
wachiAuthor Commented:
I dont under standand  the Click method.
Do you mean.? I must create
Class Frame2 extands Dialog {

}
0
MurthyMvlnCommented:
Yes, Frame2 should extend Dialog.

Actually the concept of Dialog is same in any language. The main concept,
which type of window you are making. is it modal window or modalless window.
modal window is nothing but response window. it means unless you are closing that window you can't go back.

so in java, go for Dialog api. check for any method to set this property( setModal(...) ). and go thru the Dialog constructors.


Murthy Mvln
murthy@claygency.com

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

rjackmanCommented:
no need
frame1 extends the frame
and instead of frame 2 use Dialog object
i mena just create
Dialog d = new Dialog(this,"name".true);
as i have shown in program
do 1 thing
copy the code i have given
prior to that at begining add
import java.awt.*;
import java. awt.event.*;
then copy the code
and try to compile and run
iguess u got the primary knowledge of java
0
rjackmanCommented:
no need
frame1 extends the frame
and instead of frame 2 use Dialog object
i mena just create
Dialog d = new Dialog(this,"name".true);
as i have shown in program
do 1 thing
copy the code i have given
prior to that at begining add
import java.awt.*;
import java. awt.event.*;
then copy the code
and try to compile and run
iguess u got the primary knowledge of java
0
rjackmanCommented:
public class  FrameDemo extends Frame implements ActionListener
                   {
                      private Dialog d;
                      private Button b;
                      public void FrameDemo()
                   {
                     
                      b = new Button("click");
                   }

                   click()
                   {
                     d = new Dialog( this,"options",true);
                     d.addWindowListener(newWndowAdapter())
                     add(d);
                    setSize(300,200);//as per ur requirement
                    b.addActionListner(this);
                    add(BorderLayout.SOUTH,b);
                    setVisible(true);
                   }
                   public void actionPerformed()
                   {
                    d.show();

                   }
           private class WindowAdapter
{
       public void windowClosing(WindowEvent e)
{
    d.hide;
   
}
//then write main () for testing
}

  }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wachiAuthor Commented:
Who should I give points.?
Amitd  or Rjackman or MurthyMvln .
I try that code it has many error.
How ever  I understand to use Dialog class.

Thank you.
Ps..
Has wrong in code.?
click()  { .... }

Must it be
FrameDemo (){.... }
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.