• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

closing a JDialog with a button

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
moin,

i have a problem with the following code:

i create a frame, than a dialog and with a click on the close button the dialog should be closed, so that i can work in the frame.
the control-line "hello" is displayed in the console, but the dialog doesn't disappear.

please help me...
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
// Should work now, look at the commented line below you should get the idea, a new JDailog object was getting created.
package testen;
import java.awt.event.*;
import javax.swing.*;

public class ProbDialogClose {

static JFrame f = new JFrame("test");
static JDialog dialog = new JDialog( f, true );

ProbDialogClose()
{
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.setVisible( true );
showWelcomeMessage();

}

private void showWelcomeMessage(){
//JDialog dialog = new JDialog( f, true );
dialog.setSize( 450, 400 );
dialog.setLayout(null);

JButton closeButton = new JButton("Fenster schließen");
closeButton.setSize(150, 30);
closeButton.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
closeWelcomeMessage();
}
} );
dialog.add( closeButton );
dialog.setVisible( true );
}

private void closeWelcomeMessage(){
System.out.println("hello");
dialog.setVisible(false);
dialog.dispose();
}

public static void main( String[] args ) {
new ProbDialogClose();
}
}
 
Klaus Hansen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot....
 
reply
    Bookmark Topic Watch Topic
  • New Topic