We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Problem with dialog box
Page Index Toggle Pages: 1
Problem with dialog box (Read 1821 times)
Problem with dialog box
Sep 2nd, 2009, 2:17pm
 
I have some trouble with dialog boxes using javax.swing.JOptionPane.
My simple program is on the bottom. If I put showMessageDialog in draw(), it works fine. Draw waits for user to press ok before continuing. If I put showMessageDialog in any of the mouse functions, like click, press, release, it freezes screen. I want to pop up a dialog when I click the mouse but why doesn't this work? But strangely if I drag the dialog away from processing window, then click ok I get no problem. I did some tests. The program freezes if my mouse click on the ok button is within processing window! This seems to be an mouse click handling problem within processing. How do I solve this problem? Thank you!!!


//http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
//http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html

void setup()
{
 size(400,300);
}

void draw()
{
 background(150);
 line(0,0,width-1,height-1);
}

void mouseReleased()
{
 println("mouse released");
}

void mouseClicked()
{
 println("mouse clicked");
 javax.swing.JOptionPane.showMessageDialog(frame,"what?");
}
void mousePressed()
{
 println("mouse pressed");
}
Re: Problem with dialog box
Reply #1 - Sep 2nd, 2009, 2:38pm
 
FAQ
Quote:
The main rule when using Java code: You cannot use most of the AWT or Swing (which is built on the AWT), because it will interfere with the graphics model.
Re: Problem with dialog box
Reply #2 - Sep 2nd, 2009, 2:48pm
 
Thanks PhiLho.

So this means if I want to input a number, I need to keep reading keyboard or try someone's text input library?

Getting a number from user is kind of a basic necessity for me. What do you suggest I do? I've already created my buttons class with several features. I know how to make something from scratch now but I'm not willing to make a text input from scratch. Seems time consuming. Can I somehow exit graphic mode when using dialog and re-enter it?
Re: Problem with dialog box
Reply #3 - Sep 2nd, 2009, 6:03pm
 
you can use controlP5, it has textField and textArea
http://www.sojamo.de/libraries/controlP5/
Re: Problem with dialog box
Reply #4 - Sep 3rd, 2009, 10:38am
 
Thanks for the info Cedric. It seems the controlP5 controls pick up mouse clicks and don't discard them. I can still pick up the same click in my mouseClicked(). Is there an option to stop throwing mouse and keyboard events to mouseClicked() and such? I'll try to find an appropriate board to ask any future questions on controlP5.
Re: Problem with dialog box
Reply #5 - Sep 4th, 2009, 11:39pm
 
You could use this if you don't mind interrupting your app (such as while typing something in).
Code:
...
noLoop();
javax.swing.JOptionPane.showMessageDialog(frame,"what?");
loop();
...
Re: Problem with dialog box
Reply #6 - Sep 6th, 2009, 7:58pm
 
Update 2: this method seems to work fine. One observation, when draw stops, mouse events are still processed by the processing mouse functions like mouseClicked().

Update: the method worked. I was wrong earlier. I included noLoop() and loop() at the wrong place. What a silly mistake. I'll incorporate it into my main program and test it out. Update when I finish testing.

NoahBuddy,

I tried this way you suggested. It still won't work. Same screen freeze. Is there any way to minimize processing window so the clicks don't land inside processing and then restore processing window? Thanks.
Page Index Toggle Pages: 1