First off I am new to processing and GUI in java. I am trying to port a program I made in matlab (I know what you are thinking, but it was due to the fact I had to take a class that used it for my degree, and since it has a super simple GUI maker) to java so I can make an executable from it and distribute it.
Now the issue I am having is for some reason the settings function under the SecondApplet class seems to affect the window that is made using the original setup function. So when the program is ran, the window is reduced to a super small ~100x100 size even if both size calls are size(1280,650), as well the second window now is the correct size. But if the settings function is commented out, the original window is correct, and the new window will be ~100x100.
Goal is to have the button called "Suspension_Setup" open a new window to enter data about the suspension points on the users vehicle, and then save them in a file to be used by the original window to display what I am trying to do.
If anyone can, could I also get an answer on a good way to close the second window, while preserving the original window? I have looked, but the only thing I have seen is using PFrame, and I don't know if I need that yet.
This is super bare bones right now due to the fact I am trying to just make the framework for the interface first, and ran into this issue very quickly.
Code:
import controlP5.*; // Importing GUI library
ControlP5 cp5; // Creating a new object for the GUI library
CheckBox checkbox; // Creating a checkbox object
DropdownList d1, d2; // Creating a Dropdown menu object
boolean show = false; // Setting the default state of the second window to false
void setup()
{
size(1280, 650);
cp5 = new ControlP5(this);
checkbox = cp5.addCheckBox("checkBox")
.setPosition(500, 500)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.setSize(40, 40)
.setItemsPerRow(3)
.setSpacingColumn(30)
.setSpacingRow(20)
.addItem("0", 0)
.addItem("50", 50)
.addItem("100", 100)
.addItem("150", 150)
.addItem("200", 200)
.addItem("255", 255);
// create a DropdownList
d1 = cp5.addDropdownList("myList-d1").setPosition(500, 20);
formatDropdown(d1); // customize the first list
// create a second DropdownList
d2 = cp5.addDropdownList("myList-d2").setPosition(500, 80);
formatDropdown(d2); // customize the second list
// create a new button with name 'buttonA'
cp5.addButton("Suspension_Setup")
.setPosition(0, 0)
.setSize(80, 30);
}
void formatDropdown(DropdownList ddl)
{
// a convenience function to customize a DropdownList
ddl.setSize(200, 200);
ddl.setBackgroundColor(color(190));
ddl.setItemHeight(30);
ddl.setBarHeight(30);
ddl.setCaptionLabel("dropdown");
for (int i = 0; i < 40; i++)
{
ddl.addItem("item " + i, i);
}
//ddl.scroll(0);
ddl.setColorBackground(color(60));
ddl.setColorActive(color(255, 128));
ddl.close();
// remove items from the pulldown menu by name
// d1.removeItem("item "+cnt);
// add new items to the pulldown menu
// int n = (int)(random(100000));
// d1.addItem("item "+n, n);
}
void keyPressed() // Might be used in future for shortcuts or special features
{
}
// function Suspension_Setup will receive changes from controller with name Suspension_Setup
public void Suspension_Setup(int theValue) {
println("a button event from Suspension_Setup: "+theValue);
show = true;
String[] args = {"TwoFrameTest"};
SecondApplet sa = new SecondApplet();
PApplet.runSketch(args, sa);
}
void controlEvent(ControlEvent theEvent)
{
// DropdownList is of type ControlGroup.
// A controlEvent will be triggered from inside the ControlGroup class.
// therefore you need to check the originator of the Event with
// if (theEvent.isGroup())
// to avoid an error message thrown by controlP5.
if (theEvent.isGroup())
{
// check if the Event was triggered from a ControlGroup
println("event from group : "+theEvent.getGroup().getValue()+" from "+theEvent.getGroup());
} else if (theEvent.isController())
{
println("event from controller : "+theEvent.getController().getValue()+" from "+theEvent.getController());
}
}
void draw()
{
background(0);
}
public class SecondApplet extends PApplet
{
public void settings()
{
size(1280, 650);
}
public void draw()
{
if (show)
{
background(255);
noFill();
ellipse(100, 50, 10, 10);
}
show = false;
}
}
Thank you for the help!