🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #18428

Re: Creating and Destroying Dialogs

#18428
From: Davide De Benedictis
Date: Mon, 29 Jun 1998 00:00
97 lines
3368 bytes
You have to call the dispose() yourself in the WindowClosing event like a frame.

You can also put a button on the dialog like in this simple one:

import java.awt.*;
import java.awt.event.*;

public class InfoDLG extends Dialog implements ActionListener
{
     Frame frame;
     Button close_button;
     Label info_label;
     Panel back_panel;
     String msg;

     public InfoDLG(Frame parent, String mess)
    {

          super(parent,"Warning !", true);

          msg = mess;
          frame = parent;
          setLayout(new BorderLayout(5,5));
          create();
          this.setResizable(false);
     }

     void create()
     {
          back_panel = new Panel();

          back_panel.setLayout(new FlowLayout());

          close_button = new Button(" Close ");

          info_label = new Label((" " + msg + " "), Label.CENTER);
          info_label.setFont(new Font("Helvetica", Font.BOLD, 18));
          info_label.setForeground(Color.red);
          info_label.setFont(new Font("Helvetica", Font.BOLD, 14));
          close_button.addActionListener(this);

          add("North", info_label);
          back_panel.add(close_button);
          add("South", back_panel);
     }

     public void actionPerformed( java.awt.event.ActionEvent event )
    {
          Object pEvtSource = event.getSource();

          if ( pEvtSource == close_button )
          {
               dispose();
          }
     }
}

If you need to continue with the execution in your program while the Dialog is
showing
(for example your main application is  listening to sockets or something else..)

You should call the show method from another thread.

Augh !

Thomas Wynne wrote:

>     I'm currently transforming from a MFC programmer to a Java one, and
> I'm having a hard time destroying or getting rid of a dialog. I'm
> creating it as follows from a menu event:
>
>   void New_Monster_actionPerformed(ActionEvent e) {
>     CREATE_MONSTER monster = new CREATE_MONSTER(this, true);
>     monster.show();
>
>     Once the .show() is called control is supposed to be contained
> inside of the .show() because the dialog is modal.  When the user closes
> the dialog via the x in the upper right corner the program should
> continue on, at least that's what all the books say.  When the user
> clicks on the x the dialog remains on the screen and there is no way to
> close the dialog.  Does anybody know what I am doing wrong here?  The
> dialog is not a Javabean.  Thanks
>
> Thomas Wynne



--
-----------------------------------------------------------
Davide De Benedictis

Pegaso Srl
Via Asiago 9,  00195 Roma,  Italy
tel +39 6 32.20.437   fax +39 6 37.00.454
email :  pegaso@mclink.it
-----------------------------------------------------------
Technical Details
Message-ID: <3596CD9B.D8AF1010@mclink.it>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <35971C85.89095C3D@comp.uark.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,4578d7f28fa841f1
X-Google-Attributes: gidf74b3,public
From: Davide De Benedictis <pegaso@mclink.it>
Subject: Re: Creating and Destroying Dialogs
Date: 1998/06/29
Message-ID: <3596CD9B.D8AF1010@mclink.it>
X-Deja-AN: 367252621
Content-Transfer-Encoding: 7bit
References: <35971C85.89095C3D@comp.uark.edu>
Content-Type: text/plain; charset=us-ascii
Organization: Pegaso Srl
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language