Hi there. Thanks to the folks who've coached me in creating the code below. This is a program that creates some visuals based on several .txt files. I'm also using the ControlP5 library for help with drop-down menus. Everything is working great but the applet doesn't work when I try to run it from my browser. I know - based on the error message I get in the java console - that the issue is that I'm not declaring the code public. I've tried several times to do this, and have tried to read past posts to figure out how to do this, but still to no avail. Would someone mind looking at my code and help me figure out which lines need to be declared public and how to do this? Also, can someone provide me with a simple explanation of what declaring code as public means (ie. why for libraries, what's the rationale, etc)? Thanks a lot! Kevin
- import controlP5.*;
- public ControlP5 cp5;
- String currentTeam = "";
- String listName = "";
- void setup() {
- size(1280, 800);
- // PFont font = loadFont("CenturyGothic-20.vlw");
- PFont font = loadFont("HelveticaNeue-Light-20.vlw");
- textFont(font);
- linesALSP = loadStrings("ALrankometerSP.txt"); // parsing data from external file (column [0] is list of names, column [1] is ranks, column [2] is abbreviated team name)
- linesALRP = loadStrings("ALrankometerRP.txt"); // parsing data from external file (column [0] is list of names, column [1] is ranks, column [2] is abbreviated team name)
- linesNLSP = loadStrings("NLrankometerSP.txt"); // parsing data from external file (column [0] is list of names, column [1] is ranks, column [2] is abbreviated team name)
- linesNLRP = loadStrings("NLrankometerRP.txt"); // parsing data from external file (column [0] is list of names, column [1] is ranks, column [2] is abbreviated team name)
- cp5 = new ControlP5(this);
- //cp5.setControlFont(new ControlFont(createFont("CenturyGothic", 12), 12));
- cp5.setControlFont(new ControlFont(createFont("HelveticaNeue-Light-20.vlw", 12), 12));
- cp5.getTab("default").setHeight(30).setLabel("AL");
- cp5.addTab("NL").setHeight(30);
- cp5.addTab("NL")
- .setHeight(30)
- .setColorBackground(color(r1, g1, b1))
- .setColorForeground(color(r3, g3, b3))
- .setColorActive(color(r2, g2, b2));
- cp5.addTab("default")
- .setHeight(30)
- .setColorBackground(color(r1, g1, b1))
- .setColorForeground(color(r3, g3, b3))
- .setColorActive(color(r2, g2, b2));
- cp5.getWindow().setPositionOfTabs(1100, 74);
- DropdownList teamAL = cp5.addDropdownList("AL").setPosition(1150, 105).setSize(100, 600);
- DropdownList teamNL = cp5.addDropdownList("NL").setPosition(1150, 105).setSize(100, 600).moveTo("NL");
- String[] ALteamNames = {
- "BAL", "BOS", "CHW", "CLE", "DET", "KAN", "LAA",
- "MIN", "NYY", "OAK", "SEA", "TAM", "TEX", "TOR"
- };
- String[] NLteamNames = {
- "ARI", "ATL", "CHI", "CIN", "COL", "FLA", "HOU",
- "LAD", "MIL", "NYM", "PHI", "PIT", "SD", "SF", "STL", "WSH"
- };
- for (int i=0; i<ALteamNames.length; i++) {
- teamAL.addItem(ALteamNames[i], i);
- }
- for (int i=0; i<NLteamNames.length; i++) {
- teamNL.addItem(NLteamNames[i], i);
- }
- customize(teamAL);
- customize(teamNL);
- }
- // black
- int r1=0;
- int g1=0;
- int b1=0;
- // orange
- int r2=232;
- int g2=88;
- int b2=1;
- //dark gray
- int r3=55;
- int g3=55;
- int b3=55;
- // red
- int r4=255;
- int g4=0;
- int b4=0;
- String[] linesALSP;
- String[] linesALRP;
- String[] linesNLSP;
- String[] linesNLRP;
- int selectedLeague = 0;
- boolean TeamFound = false;
- // entry of team name
- void draw() {
- background (r1, g1, b1);
- int indent = 50;
- fill(r2, g2, b2);
- textSize(48);
- text("Rankometer", 50, 102);
- textSize(16);
- text("{ based on earned run average }", 320, 102);
- text("#1 starter", 50, 670);
- text("#2 starter", 200, 670);
- text("#3 starter", 350, 670);
- text("#4 starter", 500, 670);
- text("#5 starter", 650, 670);
- text("#1 reliever", 860, 670);
- text("#2 reliever", 1010, 670);
- if (currentTeam=="BAL") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="BOS") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="CHW") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="CLE") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="DET") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="KAN") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="LAA") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="MIN") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="NYY") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="OAK") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="SEA") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="TAM") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="TEX") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="TOR") {
- selectedLeague=1;
- }
- else
- if (currentTeam=="ARI") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="ATL") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="CHI") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="CIN") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="COL") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="FLA") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="HOU") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="LAD") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="MIL") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="NYM") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="PHI") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="PIT") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="SD") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="SF") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="STL") {
- selectedLeague=2;
- }
- else
- if (currentTeam=="WSH") {
- selectedLeague=2;
- }
- if (selectedLeague==1) {
- // LOOP FOR STARTING PITCHERS
- for (int k=0; k<5; k++) { // master loop to format 5 columns of names
- TeamFound = false; // re-setting boolean to false
- fill(r1, g1, b1); // re-setting box color to background color (ie. no box appears)
- for (int j=k*14; j<k*14+14; j++) { //sub loop to format 14 rows of names within each column
- int z=j-k*14; // special variable I use to index down and across rows and columns
- String[] name = splitTokens(linesALSP[j+1]);
- // drawing boxes
- if (name[2].equals(currentTeam)) { //Determine if it finds selected team and then highlight boxes for that row and rows below
- TeamFound = true; // Apply box to the remainder of the column
- // smooth();
- // textSize(24);
- //fill(200);
- //text(name[4]+" "+name[5], 250, 102);
- }
- if (TeamFound) {
- fill(r2, g2, b2); // if so, draw box with darker gray and those below in column
- rect(k*150+50, 230+z*30, 140, 25);
- noStroke();
- textSize(16);
- fill(0); //text color
- //text(name[0]+" "+name[3], k*150+55, 250+z*30);
- text(name[0], k*150+55, 250+z*30);
- textSize(10);
- textAlign(RIGHT);
- text(name[3], k*150+180, 250+z*30);
- textAlign(LEFT);
- }
- // overlaying text
- noStroke();
- textSize(16);
- fill(r2, g2, b2, 80); //text color
- text(name[0], k*150+55, 250+z*30);
- textSize(10);
- textAlign(RIGHT);
- text(name[3], k*150+180, 250+z*30);
- textAlign(LEFT);
- }
- }
- // LOOP FOR RELIEF PITCHERS
- for (int k=0; k<2; k++) { // master loop to format 5 columns of names
- TeamFound = false; // re-setting boolean to false
- fill(r1, g1, b1); // re-setting box color to background color (ie. no box appears)
- for (int j=k*14; j<k*14+14; j++) { //sub loop to format 14 rows of names within each column
- int z=j-k*14; // special variable I use to index down and across rows and columns
- String[] name2 = splitTokens(linesALRP[j+1]);
- // drawing boxes
- if (name2[2].equals(currentTeam)) { //Determine if it finds selected team and then highlight boxes for that row and rows below
- TeamFound = true; // Apply box to the remainder of the column
- // smooth();
- // textSize(24);
- //fill(200);
- //text(name[4]+" "+name[5], 250, 102);
- }
- if (TeamFound) {
- fill(r2, g2, b2); // if so, draw box with darker gray and those below in column
- rect(k*150+855, 230+z*30, 140, 25);
- noStroke();
- textSize(16);
- fill(0); //text color
- text(name2[0], k*150+860, 250+z*30);
- textSize(10);
- textAlign(RIGHT);
- text(name2[3], k*150+985, 250+z*30);
- textAlign(LEFT);
- }
- // overlaying text
- noStroke();
- textSize(16);
- fill(r2, g2, b2, 80); //text color
- text(name2[0], k*150+860, 250+z*30);
- textSize(10);
- textAlign(RIGHT);
- text(name2[3], k*150+985, 250+z*30);
- textAlign(LEFT);
- }
- }
- }
- else if (selectedLeague==2) {
- // LOOP FOR STARTING PITCHERS
- for (int k=0; k<5; k++) { // master loop to format 5 columns of names
- TeamFound = false; // re-setting boolean to false
- fill(r1, g1, b1); // re-setting box color to background color (ie. no box appears)
- for (int j=k*16; j<k*16+16; j++) { //sub loop to format 14 rows of names within each column
- int z=j-k*16; // special variable I use to index down and across rows and columns
- String[] name = splitTokens(linesNLSP[j+1]);
- // drawing boxes
- if (name[2].equals(currentTeam)) { //Determine if it finds selected team and then highlight boxes for that row and rows below
- TeamFound = true; // Apply box to the remainder of the column
- // smooth();
- // textSize(24);
- //fill(200);
- //text(name[4]+" "+name[5], 250, 102);
- }
- if (TeamFound) {
- fill(r2, g2, b2); // if so, draw box with darker gray and those below in column
- rect(k*150+50, 170+z*30, 140, 25);
- noStroke();
- textSize(16);
- fill(0); //text color
- //text(name[0]+" "+name[3], k*150+55, 250+z*30);
- text(name[0], k*150+55, 190+z*30);
- textSize(10);
- textAlign(RIGHT);
- text(name[3], k*150+180, 190+z*30);
- textAlign(LEFT);
- }
- // overlaying text
- noStroke();
- textSize(16);
- fill(r2, g2, b2, 80); //text color
- text(name[0], k*150+55, 190+z*30);
- textSize(10);
- textAlign(RIGHT);
- text(name[3], k*150+180, 190+z*30);
- textAlign(LEFT);
- }
- }
- // LOOP FOR RELIEF PITCHERS
- for (int k=0; k<2; k++) { // master loop to format 5 columns of names
- TeamFound = false; // re-setting boolean to false
- fill(r1, g1, b1); // re-setting box color to background color (ie. no box appears)
- for (int j=k*16; j<k*16+16; j++) { //sub loop to format 14 rows of names within each column
- int z=j-k*16; // special variable I use to index down and across rows and columns
- String[] name2 = splitTokens(linesNLRP[j+1]);
- // drawing boxes
- if (name2[2].equals(currentTeam)) { //Determine if it finds selected team and then highlight boxes for that row and rows below
- TeamFound = true; // Apply box to the remainder of the column
- // smooth();
- // textSize(24);
- //fill(200);
- //text(name[4]+" "+name[5], 250, 102);
- }
- if (TeamFound) {
- fill(r2, g2, b2); // if so, draw box with darker gray and those below in column
- rect(k*150+855, 170+z*30, 140, 25);
- noStroke();
- textSize(16);
- fill(0); //text color
- text(name2[0], k*150+860, 190+z*30);
- textSize(10);
- textAlign(RIGHT);
- text(name2[3], k*150+985, 190+z*30);
- textAlign(LEFT);
- }
- // overlaying text
- noStroke();
- textSize(16);
- fill(r2, g2, b2, 80); //text color
- text(name2[0], k*150+860, 190+z*30);
- textSize(10);
- textAlign(RIGHT);
- text(name2[3], k*150+985, 190+z*30);
- textAlign(LEFT);
- }
- }
- }
- stroke(r2, g2, b2);
- strokeWeight(2);
- line (50, 110, 1250, 110);
- line (50, 650, 1250, 650);
- }
- public void controlEvent(ControlEvent theEvent) {
- if (theEvent.isGroup()) {
- String listName = theEvent.getName();
- String itemName = theEvent.getGroup().captionLabel().getText();
- if (listName.equals("AL") || listName.equals("NL")) {
- currentTeam = itemName;
- //println(currentTeam);
- println(listName);
- }
- }
- }
- public void customize(DropdownList ddl) {
- ddl.setBackgroundColor(color(0));
- ddl.setItemHeight(30);
- ddl.setBarHeight(30);
- ddl.captionLabel().style().marginTop = 3;
- ddl.captionLabel().style().marginLeft = 3;
- ddl.valueLabel().style().marginTop = 3;
- ddl.setColorForeground(color(r3, g3, b3));
- ddl.setColorBackground(color(r2, g2, b2));
- ddl.setColorActive(color(r3, g3, b3));
- }
1