This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

pop-up window issue  RSS feed

 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make it so that a popup window will not close until the "close" button is pressed.....however I keep on getting to where it either never closes or never does anything...
This is the best logic I have so far is anyone can help me I woull appreciate it!!
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class numericMessage extends Frame implements ActionListener,WindowListener
{
private Label err = new Label("This field must be numeric");
Font textFont = new Font("courier", Font.BOLD,10);

private Button closeButton = new Button("Close");
boolean pressed = false;
public static void main(String[] args)throws Exception{

numericMessage NMG = new numericMessage();
NMG.setResizable(false);
}
public numericMessage() {
super("VITGUSA");

setSize(250,100);
setBackground(Color.lightGray);
setLayout(new FlowLayout());

add(err);
err.setForeground(Color.red);
err.setFont(textFont);
add(closeButton);
closeButton.addActionListener(this);
closeButton.setVisible(true);
closeButton.setBackground(Color.red);

setVisible(true);
addWindowListener(this);
}
public void actionPerformed(ActionEvent e1) {
pressed = true;
}
public void windowClosing(WindowEvent e){
if (pressed = true){
setVisible(false);
}
else if (pressed = false){
setVisible(true);
}
}
public void windowClosed(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
}
 
Sainudheen Mydeen
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Replace "=" with "==". You are comparing values.
----------------
Sainudheen
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris, don't mean to be rude, but did you actually get the code to compile?
 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it compiles and runs
 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the "==" with the same results. Is there a better way to do this that I am over looking?
 
Brian Pipa
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just put the

into the actionPerformed() method? Why use the pressed boolean at all? I just tried that and it worked fine for me.
Brian
 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm.....what I want is to make it so the user has to press the "close" button in order to exit the screen. right now if they click off of the window they can access the screens behind it making it so they can have multiple messages at the same time. I want to fix it so there will only be one. If I set the setVisible(false)in the actionPerformed section it wont solve that.
I already tried that but thanks though. What I'm trying to do is lock this on the screen until they press the close button.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Swing forum.
 
Brian Pipa
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a totally different question than what you first asked You need ot use a JDialog or a JOptionPane. They disable the main window until you deal with the dialog. Here is an example of a JOptionPane:

Brian
[ October 07, 2003: Message edited by: Brian Pipa ]
[ October 07, 2003: Message edited by: Brian Pipa ]
 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry.... I forgot to post to this one
Ok fist off I know all about making this with a the swing package but I needed to do with on a windows CE device and much to my shock and surprise the swing classes were not recognized by the JVM that was running on the device. Next I did in fact get this working with some interesting, ah logic :roll:
I have been working with Windows CE for a little while now and let me tell you I can't wait until someone else comes out with a competitive solution to this....

thanks for all the help!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!