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?
 
rjackmanConnect With a Mentor Commented:
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
 
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
 
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
All Courses

From novice to tech pro — start learning today.