• Post Reply Bookmark Topic Watch Topic
  • New Topic

closing a JDialog with a button

 
Klaus Hansen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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...
 
Swastik Dey
Rancher
Posts: 1679
7
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thanks a lot....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!