473,418 Members | 2,319 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

dismiss modal JDialog

I am coding a reversi game as a java applet. I am using modal dialogs to inform the user if they beet the computer. I can close the dialog by the window decorations 'close', I want to hide the decoration and have my own close button-

Expand|Select|Wrap|Line Numbers
  1. import java.applet.*;
  2. import java.lang.*;
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.net.*;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.WindowAdapter;
  9. import java.awt.event.WindowEvent;
Expand|Select|Wrap|Line Numbers
  1.     private Frame findParentFrame(){ 
  2.         Container c = this; 
  3.         while(c != null){ 
  4.               if (c instanceof Frame) 
  5.                 return (Frame)c; 
  6.  
  7.           c = c.getParent(); 
  8.         } 
  9.     return (Frame)null; 
  10.   } 
Expand|Select|Wrap|Line Numbers
  1. public void endGame(){
  2.         Frame f = findParentFrame(); 
  3.         final JDialog dialog = new JDialog(f, "Game Over", true);
  4.             JButton close = new JButton("Play Again");
  5.         if (counter_black > counter_white) {
  6.             dialog.setLayout(new GridLayout(2, 1));
  7.             dialog.add( new Label("You\nWon!") );
  8.             dialog.add( close );
  9.             dialog.pack();
  10.         } else if (counter_black < counter_white) {
  11.             dialog.setLayout(new GridLayout(2, 1));
  12.             dialog.add( new Label("You\nLost!") );
  13.             dialog.add( close );
  14.             dialog.pack();
  15.         } else {
  16.             dialog.setLayout(new GridLayout(2, 1));
  17.             dialog.add( new Label("Draw!") );
  18.             dialog.add( close );
  19.             dialog.pack();
  20.         } dialog.setLocationRelativeTo(null);
  21.         dialog.setVisible(true);
  22.         repaint();
  23.         close.addActionListener(new ActionListener() {
  24.             public void actionPerformed(ActionEvent e) {
  25.                 dialog.setVisible(false);            }
  26.         });
  27.        }
The dialog displays correctly, but doesn't close with the button
May 4 '10 #1
1 3291
Expand|Select|Wrap|Line Numbers
  1.     public void endGame(){
  2.         Frame f = findParentFrame(); 
  3.         final JDialog dialog = new JDialog(f, "Game Over", true);
  4.             JButton close = new JButton("Play Again");
  5.         if (counter_black > counter_white) {
  6.             dialog.setLayout(new GridLayout(2, 1));
  7.             dialog.add( new Label("You\nWon!") );
  8.             dialog.add( close );
  9.             //dialog.pack();
  10.         } else if (counter_black < counter_white) {
  11.             dialog.setLayout(new GridLayout(2, 1));
  12.             dialog.add( new Label("You\nLost!") );
  13.             dialog.add( close );
  14.             //dialog.pack();
  15.         } else {
  16.             dialog.setLayout(new GridLayout(2, 1));
  17.             dialog.add( new Label("Draw!") );
  18.             dialog.add( close );
  19.             //dialog.pack();
  20.         } dialog.setLocationRelativeTo(null);
  21.         close.addActionListener(new ActionListener() {
  22.         public void actionPerformed(ActionEvent e) {
  23.             dialog.dispose();            }
  24.         });
  25.         dialog.pack();
  26.         dialog.setVisible(true);
  27.         repaint();
  28.  
  29.        }
May 6 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Patrick Lim | last post by:
Here is the problem: I have written a non-modal frame class in Java for displaying help text when a user is using an application. It works as desired in that if the user selects "help" again,...
1
by: amith | last post by:
Hi, I have a javascript, calendar.js which i use to enable my client to select the date. This calendar pops up on the click of a gif image. But the problem is that this poped up window is not...
2
by: Gilles T. | last post by:
Hi, How I can refresh a modal dialog in asp.net? I open a modal dialog in first with a dropdownlist. To add a element in my dropdownlist (table), I open a second modal dialog to ask element and...
2
by: cassidyc | last post by:
Hi, I was wondering if anyone has come accross this issue? And if they have any solutions I have that can create new copies of itself Form1 as = new form1(); af.show(); This form can also...
5
by: CaptainZ | last post by:
When I open a modal window using 'showModalDialog' from an aspx page it works fine. But when I then perform a submit in my modal window to get data from the server, instead of the page returning to...
10
by: Guadala Harry | last post by:
I have a modal dialog that currently does all of the following except item 4. 1. lets users select a graphic from a list of thumbnails (and when selected, displays the full-size image in a...
2
by: Seanus | last post by:
Hi all, I've got a little problem with the JDialogs. Housekeeping: I'm on windows xp, with the latest JRE, I'm getting no error as such. Basically, I've got some JDialogs in my program (are...
9
by: aleplgr | last post by:
Hello, in this code suppose that the dlg is defined in one case as a JDialog, I run it and it seems that the JDialog is executed AFTER closing it, so the message is printed after closing the JDialog....
3
by: sezanawa | last post by:
Hi Guys, I have a small application which i wrote in Java. There is a MainFrame extends jfram class. There is another class named LoginDialog extends JDialog. My MainFrame class have main...
1
by: sibusiso | last post by:
HI Can anyone help with the scenario where where you have to pass a certain data from one JFrame to another. For example, suppose you have a JFrame is your main window you disabled your Jmenu...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.