O'Reilly Forums: Esc And Cancel In User Input Dialog - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Esc And Cancel In User Input Dialog

#1 User is offline   BertusJ 

  • New Member
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 09-May 11

Posted 22 May 2011 - 09:44 AM

I managed to get the code not to crash with any key press except for cancel escape and the small cross on the input dialog.

Will anybody please help on that? Is there a unicode character corresponding to these keys so I can filter it or can I disable them or is there a way to display a userinput dialog without a cancel button?

Thanks

Bertus





import javax.swing.JOptionPane;//For user input dialogs
boolean isInteger;
String y = "0";

class Button {
int x, y; // The x- and y-coordinates
int size; // Dimension (width and height)
color baseGray; // Default gray value
color overGray; // Value when mouse is over the button
color pressGray; // Value when mouse is over and pressed
boolean over = false; // True when the mouse is over
boolean pressed = false; // True when the mouse is over and pressed
Button(int xp, int yp, int s, color b, color o, color p) {
x = xp;
y = yp;
size = s;
baseGray = b;
overGray = o;
pressGray = p;
}
// Updates the over field every frame
void update() {
if ((mouseX >= x) && (mouseX <= x+size) &&
(mouseY >= y) && (mouseY <= y+size)) {
over = true;
} else {
over = false;
}
}
boolean press() {
if (over == true) {
pressed = true;
return true;
} else {
return false;
}
}
void release() {
pressed = false; // Set to false when the mouse is released
}
void display() {
if (pressed == true) {
fill(pressGray);
} else if (over == true) {
fill(overGray);
} else {
fill(baseGray);
}
stroke(255);
rect(x, y, size, size);
}}
Button button1, button2, button3;
int mode = 0;
void setup() {
frameRate (2);
size(100, 100);
smooth();
color gray = color(204);
color white = color(255);
color black = color(0);
button1 = new Button(10, 80, 10, gray, white, black);
}
void draw(){
frameRate (2);
background(204);
manageButtons();
noStroke();
fill(0);
isInteger = true;

int y1 = 100;
if (mode == 1) {
y = JOptionPane.showInputDialog(null,
"Enter new setpoint (0 to 120):",
"Setpoint adjustment",
JOptionPane.PLAIN_MESSAGE);}
if (y == null) {
isInteger = false;
} int length = y.length();
if (length == 0) {
isInteger = false;
}
int i = 0;
if (length == 1) {
if (y.charAt(0) == '-') {
isInteger = false;
}
i = 0;
}
for (; i < length; i++) {
char c = y.charAt(i);
if (c <= '/' || c >= ':') {
isInteger = false;
}
}
mode = 0;
if(isInteger == true){
y1 = Integer.parseInt(y);}
else{println(" Not integer");}
println(y1);
}
void manageButtons() {
button1.update();
button1.display();
}
void mousePressed() {
if (button1.press() == true) { mode = 1; }
}
void mouseReleased() {
button1.release();
}
0

#2 User is offline   grauwald 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 20
  • Joined: 26-August 10

Posted 02 June 2011 - 08:08 AM

Hi Bertus, I really recommend that you post Processing related questions on the official Processing forum:

http://forum.processing.org/

That's where the majority of the Processing community "hangs out".

Cheers,
-Joe
0

#3 User is offline   trxsale 

  • New Member
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 24-October 12

Posted 19 November 2012 - 09:22 PM

This article is very good. I like it so much. It is useful, keep working. good job, friends.
0

#4 User is offline   Paresh Aegis 

  • New Member
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 12-October 12

Posted 10 January 2013 - 02:21 AM

Keyboard options were unknown to the computer operators. Computer operators depended solely on the mouse. All the computer applications available today existed only as scientific fiction. With intensified effort on the part of computer scientists and technologists there is a number of computer applications. Computer operators can now beam with smiles due to the number of shortcut available to them which make work easier for them.

SharePoint Consulting

Thanks.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users