We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I would like to create a button, when pressed on, will create a new window and disable the button. When the window is closed, the button will be enabled again. How can I do that? This is my code:
void handleButtonEvents(GButton button, GEvent event)
{
if (event == GEvent.CLICKED)
{
createWindows();
}// if
}
void createWindows()
{
window = new GWindow(this, "Help", 500, 50, 477, 538, false, JAVA2D);
window.setBackground(help);
window.setActionOnClose(GWindow.CLOSE_WINDOW);
}// createWindow
Answers
Like this
If i want to put a text in these new window, how can i do?
You need to register a draw method fro the new window. This behaves kust like the main draw() method but you have to prefix all the calls to Processing methods - see below import g4p_controls.*;
ok, i want to put these code in the new window, i on't know how to do it. String title = "MICROHERBS: Software to help you to identify herbal drug"; String Name = ""; void setup() { size(760, 300); textAlign(LEFT, LEFT); textSize(25); fill(0); } void draw() { background(255); text (title,10,0, width, height); text("Name: "+Name, 10, 140, width, height); } void keyPressed() { if (keyCode == BACKSPACE) { if (Name.length() > 0) { Name = Name.substring(0, Name.length()-1); } } else if (keyCode == DELETE) { Name = ""; } else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) { Name = Name + key; } }
Please format your code for this forum : highlight the code and press Ctrl+K
ok, I want to put these code in the new window and I don't know how to do it.
Please format your code for this forum see here if you don't know how to do it.
On this occassion I have formatted the code for you but please find out how to do this yourself.
I have change the variable
Name
toname
because we only capitalise the first letter if it is the name of a class.I have also modified the example to show how to use key event handling n GWindows.
hello, I tried the code (the first one to open a new window) but tells me: ClassNoFoundException: processing.core.PGraphicsJava2d
this is not the first time, also when I tried to run examples from p4g often happens. can you please help me? thank you for any suggestions