Technically our (my) code is not good, because we have very similar sections that could be unified and made much better.
E.g. we have 8 buttons now, 4 on the right side (Load etc.) and 4 buttons above the 4 columns. But we don't have a nice structure to check them for mouse click.
Look at this code, there are a lot of repetitions going on:
// functions to register if mouse is over buttons / funzione da registrare se il mouse è sui pulsanti
boolean overSave() { // modificato
return mouseX > width-50 &&
mouseY > height-740 &&
mouseY < height-740+25 ;
}
boolean overLoad() { //modificato
return mouseX > width-50 &&
mouseY > height-710 &&
mouseY < height-710+25 ;
}
boolean overNew() { //modificato
return mouseX > width -50 &&
mouseY > height-680 &&
mouseY < height-680+25 ;
}
boolean overHelp() { //modificato
return mouseX > width -50 &&
mouseY > height-650 &&
mouseY < height-650+25 ;
}
Instead it would be cool to have a list of buttons and say something like
for (Button btn : buttons) // for all our buttons do something
if (mouseIsOver btn)
do button btn command;
}
That's pseudo code obviously but it's much shorter.
At the moment you just have numbers like height-650. Now you could put them in variables like xpositon1.
Then you could have one list for the x position of all buttons, one list of the y positions of all buttons, the heights and so on.
Then there is the concept of object oriented programming (OOP) which allows us to define what ONE button is (seen in an abstract way), a x position, y position, widthButton and heightButton ajnd its text (caption, "Load" etc.) and it should be able to register the mouse on it of course. Such a package is called a class.
Then we can make a list (array) of that Button class. Very cool.
What I said about the buttons being redundant and the necessity to unify them in a list / array is also true for the 4 columns of data : they also share a lot of common code which contradicts the DRY principle of programming: don’t repeat yourself.
Button[] buttons;
String status="";
void setup() {
size(440, 400);
int unit = 40;
int count = 440/unit;
buttons = new Button[count];
for (int x = 0; x < buttons.length; x++) {
Button newButton = new Button(x*unit+6, 50,
25, 55,
color(255, 0, 0), color(0, 255, 0), color(0, 0, 255),
x);
buttons[x] = newButton;
}
}
void draw() {
background(0, 0, 0); // black
text (status, 44, height-44);
for (Button but : buttons) {
but.update();
but.display();
fill(0, 255, 0); // green
textAlign(CENTER);
text(but.index, but.x+but.sizeWidth/2, 40);
textAlign(LEFT);
}//for
}//func
//_____________________________//
void mousePressed() {
for (Button but : buttons) {
but.press();
if (but.pressed) {
println(but.index);
doCommand(but.index);
break; // Other buttons won't be pressed, just stop
}
}
}
void mouseReleased() {
for (Button but : buttons) {
but.release();
}
}
void doCommand(int cmd) {
switch(cmd) {
case 0:
status="Interesting Button 0";
break;
case 1:
status="Button 1";
break;
case 2:
status="Now Button 2";
break;
default:
status="Something else...";
break;
}//switch
}//func
//_____________________________//
class Button {
int x, y; // The x- and y-coordinates
int sizeWidth, sizeHeight; // 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
int index;
// constructor
Button(int xp_, int yp_,
int sizeWidth_, int sizeHeight_,
color b_,
color o_,
color p_,
int index_) {
x = xp_;
y = yp_;
sizeWidth = sizeWidth_;
sizeHeight = sizeHeight_;
baseGray = b_;
overGray = o_;
pressGray = p_;
index=index_;
} // constructor
// Updates the over field every frame
void update() {
if ((mouseX >= x) && (mouseX <= x + sizeWidth) &&
(mouseY >= y) && (mouseY <= y + sizeHeight)) {
over = true;
} else {
over = false;
}
}
boolean press() {
if (over) {
pressed = true;
return true;
} else {
return false;
}
}
void release() {
pressed = false; // Set to false when the mouse is released
}
void display() {
if (pressed) {
fill(pressGray);
} else if (over) {
fill(overGray);
} else {
fill(baseGray);
}
stroke(255);
rect(x, y, sizeWidth, sizeHeight);
}
}//class
//
Thanks Chrisir,
the merit of where I arrived and all yours, I still have to study and apply myself so much .....
This is where I came to create the sketch ......
// https : // forum.processing.org/two/discussion/26719/save-and-load-array-list#latest
import processing.serial.*;
Serial myPort; // The serial port:
// buttons above columns pulsanti sopra colonne
int[] arrayOfXValuesFrom = { 900, 1010,1120, 1230 };
int[] arrayOfXValuesTFile = { 275, 305, 335, 365};
int[] arrayOfXValuesTo = { 990, 1100, 1210, 1320 };
// text for file names for each column // testo per i nomi dei file per ogni colonna
String[] fileNames = { "not a file",
"not a file",
"not a file",
"not a file" };
// 4 columns
ArrayList<PVector> points1 = new ArrayList(); // 1st
ArrayList<PVector> points2 = new ArrayList(); // 2nd
ArrayList<PVector> points3 = new ArrayList(); // 3rd
ArrayList<PVector> points4 = new ArrayList(); // 4th
// active column
int activeArrayListHasNumber = 0;
// some flags for texts
boolean showHelpText1 = false;
boolean showText = true;
String inString; // Input string from serial port:
int lf = 10; // ASCII linefeed
float deg, val,MasA,PCil,PAtm;
final String pathFolder="";//CARTELLA DI PERCORSO
final String fileExtension = ".txt";//estensione file
// unique numbers for constants:
final int normal = 0;
final int save = 1;
final int load = 2;
final int help = 3;
/// current state (must be one of them)
/// stato attuale (deve essere uno di loro)
int state=normal;
// Paths
String savePath="";
String loadPath="";
// --------------------------------------------------------------------------
void setup() {
size(1350, 750);
//// not necessary
//for (int i = 0; i < 3; i++) {
// points1.add(new PVector(i, 20 + 10*noise(i*0.1)));
//}//for
//for (int i = 0; i < 13; i++) {
// points2.add(new PVector(i, 30 + 10*noise(i*0.1)));
//}//for
//for (int i = 0; i < 5; i++) {
// points3.add(new PVector(i, 40 + 10*noise(i*0.1)));
//}//for
//for (int i = 0; i < 7; i++) {
// points4.add(new PVector(i, 50 + 10*noise(i*0.1)));
//}//for
PFont f= createFont ("Georgia", 25);
// myPort = new Serial(this, "com3", 9600);
// myPort.bufferUntil(lf);
}
void draw() {
switch (state) {
case normal:
drawForStateNormal() ;
break;
case save:
// wait for Save Dialog
waitForSaveDialog();
break;
case load:
// wait for Load Dialog
waitForLoadDialog();
break;
case help:
// help
drawForStateHelp() ;
break;
default:
//Error
println("Fail 192; unknown state: "
+state);
exit();
break;
//
} //switch
//
}//func
// ------------------------------------------------
void drawForStateNormal() {
background(245);
{
strokeWeight(2);//spessore linea rettangolo grafico
stroke(50);;//colore contorno rettangolo grafico
fill(245);
rect(width-1320, height-590, 820, 565); //posizione e grandezza rettangolo grafico
rect(width-490, height-495, 480, 120); //posizione e grandezza rettangolo nome file
rect(width-490, height-740, 430, 235); //posizione e grandezza rettangolo valori
//linee grafico verticali.
strokeWeight(2);
stroke (200);
fill(255);
line(width-1270,height-60,width-1270,height-580);
line(width-1215,height-60,width-1215,height-580);
line(width-1160,height-60,width-1160,height-580);
line(width-1105,height-60,width-1105,height-580);
line(width-1050,height-60,width-1050,height-580);
line(width-995,height-60,width-995,height-580);
line(width-940,height-60,width-940,height-580);
line(width-885,height-60,width-885,height-580);
line(width-830,height-60,width-830,height-580);
line(width-775,height-60,width-775,height-580);
line(width-720,height-60,width-720,height-580);
line(width-665,height-60,width-665,height-580);
line(width-610,height-60,width-610,height-580);
line(width-555,height-60,width-555,height-580);
//linee grafico verticali
//line(width-1200,height-30,width-1200,height-580);
//line(width-1200,height-30,width-1200,height-580);
//line(width-1200,height-30,width-1200,height-580);
//numeri grafico orizzontali
stroke(0);
strokeWeight(1);
fill(0);
line(width-1270,height-50,width-1270,height-60);
line(width-1215,height-50,width-1215,height-60);
line(width-1160,height-50,width-1160,height-60);
line(width-1105,height-50,width-1105,height-60);
line(width-1050,height-50,width-1050,height-60);
line(width-995,height-50,width-995,height-60);
line(width-940,height-50,width-940,height-60);
line(width-885,height-50,width-885,height-60);
line(width-830,height-50,width-830,height-60);
line(width-775,height-50,width-775,height-60);
line(width-720,height-50,width-720,height-60);
line(width-665,height-50,width-665,height-60);
line(width-610,height-50,width-610,height-60);
line(width-555,height-50,width-555,height-60);
line(width-1280,height-50,width-540,height-50);
// line(width-1275,height-50,width-1275,height-580);// linea verticale bianca
textSize(15);
text("0,0",width-1280,height-30); // numeri grafico
text("1,0",width-1225,height-30);
text("2,0",width-1170,height-30);
text("3,0",width-1115,height-30);
text("4,0",width-1060,height-30);
text("5,0",width-1005,height-30);
text("6,0",width-950,height-30);
text("7,0",width-895,height-30);
text("8,0",width-840,height-30);
text("9,0",width-785,height-30);
text("10,0",width-740,height-30);
text("11,0",width-685,height-30);
text("12,0",width-630,height-30);
text("13,0",width-575,height-30);
textSize(38);
text(MasA,width-495,height-695);
text(nf(PCil,0,2),width-200,height-695);
text(nf(PAtm,0,2),width-200,height-617);
//text(Temp,1000,200);
text(((nf(PAtm- PCil,0,2))), width-200,height-539);
textSize(16);
text("(In/Wg)",width-200,height-670);
text("(In/Wg)",width-200,height-592);
text("(In/Wg)",width-200,height-514);
text("(Kg/s)",width-485,height-670);
strokeWeight(1);
fill(0);
textSize(15);
text(" (mm)", width-1180, height-5);
// text verticale
fill(0);
float x = width-1330;
float y = height-130;
textAlign(CENTER,BOTTOM);
pushMatrix();
translate(x,y);
rotate(-HALF_PI);
text("(Kg/s)",0,0);
popMatrix();
// tabella
strokeWeight(2);//spessore linea rettangolo grafico
stroke(50);;//colore contorno rettangolo grafico
fill(245);
rect(width-490, height-365, 480, 340);//posizione e grandezza rettangolo tabella
// stroke(200);
fill(0);
text("0",width-470,height-290); //numeri tab.
text("1",width-470,height-270);
text("2",width-470,height-250);
text("3",width-470,height-230);
text("4",width-470,height-210);
text("5",width-470,height-190);
text("6",width-470,height-170);
text("7",width-470,height-150);
text("8",width-470,height-130);
text("9",width-470,height-110);
text("10",width-475,height-90);
text("11",width-475,height-70);
text("12",width-475,height-50);
text("13",width-475,height-30);
stroke(0);
strokeWeight(1);
fill(0);
line(width-480,height-290,width-20,height-290);
line(width-480,height-270,width-20,height-270);
line(width-480,height-250,width-20,height-250);
line(width-480,height-230,width-20,height-230);
line(width-480,height-210,width-20,height-210);
line(width-480,height-190,width-20,height-190);
line(width-480,height-170,width-20,height-170);
line(width-480,height-150,width-20,height-150);
line(width-480,height-130,width-20,height-130);
line(width-480,height-110,width-20,height-110);
line(width-480,height-90,width-20,height-90);
line(width-480,height-70,width-20,height-70);
line(width-480,height-50,width-20,height-50);
line(width-480,height-30,width-20,height-30);
//line val
line(width-490,height-662,width-60,height-662);
line(width-347,height-505,width-347,height-740);
line(width-490,height-584,width-60,height-584);
line(width-204,height-505,width-204,height-740);
textSize(14);
showData1();
showData2();
showData3();
showData4();
//fill(255, 2, 2);
textSize(77);
text("thank you Chrisir", width-910,90);//TITOLO
textSize(40);
textAlign(LEFT);
//// help
if (showHelpText1) {
float widthOfBox = 210;
fill(240, 544, 2); // yellow
stroke(0); // black
rect(420, 27, widthOfBox, 322);
fill(0); // black
text("Use mouse above columns (or 0..3) to set the active table "
+"which is marked by the horizontal line on top.\n\n"
+"New, Load and Save are referring to the active table (and Backspace).\n"
+"m to hide / show text data.\n\nHit x to hide / show this text.",
425, 30, widthOfBox-10, 522);
}
// ----------------------
// buttons
showButtons();
// gray lines above columns
for (int i=0; i < arrayOfXValuesFrom.length; i++) {
if (activeArrayListHasNumber!=i) {
stroke(111); //
strokeWeight(2.8); //spessore linea richiamo
line (arrayOfXValuesFrom [i], 405, //linea richiamo
arrayOfXValuesTo[i], 405);
strokeWeight(0.8); //spessore linea richiamo
line (arrayOfXValuesFrom [i]+10, 415, //
arrayOfXValuesTo[i]-10, 415);
line (arrayOfXValuesFrom [i]+10, 400-4,
arrayOfXValuesTo[i]-10, 400-4);
}//if
fill(0);
text (fileNames[i],
875, arrayOfXValuesTFile [i]); // posizione fileNames = //
}//for
// reset
strokeWeight(1.0);
} //
} //draw
void drawForStateHelp() {
// Help
background(245);
//MasA.setVisible(false);
//PCil.setVisible(false);
//PAtm.setVisible(false);
////myKnob4.setVisible(false);
fill(255, 2, 2);
text("My little Graph program\n\nUse buttons on the right and below;\n" //testo e posizione testo
+"use Backspace to delete last data point of each list.\n\n"
+"Use 1 and 2 to set the active table which is marked by the horizontal line on top.\n"
+"New, Load and Save are referring to the active table (and also Backspace).\n\n"
+"You can click now above each column to activate it.\n"
+"You can press m to hide/show data text and x to show / hide quick help."
+"\n\nHit any key to return to main program.",
113, 122, width-200, 422);
}
// --------------------------------------------------
// functions to show buttons funzione per mostrare i bottoni
void showButtons() {
//
strokeWeight(2);
stroke(0);
textSize(15);
fill(0);
if ( overSave() ) {
fill(#FF0303);
}
rect(width-50, height-740, 40, 20, 5);// modificato posizione bottone "salve"
fill(255);
text("Save",
width-50+2, height-740+9+6);
// ---
fill(0);
if ( overLoad() ) {
fill(#49C3FA);
}
rect(width-50, height-710, 40, 20, 5);// modificato posizione" load"
fill(255);
text("Load",
width-50+2, height-710+9+6);
// ---
fill(0);
if ( overNew() ) {
fill(#1FFF03);
}
rect(width-50, height-680, 40, 20, 5);// modificato posizione "new"
fill(255);
text("New",
width-50+4, height-680+9+6);
// ---
fill(0);
if ( overHelp() ) {
fill(#1AAF03);
}
rect(width-50, height-650, 40, 20, 5);// modificato posizione "help"
fill(255);
text("Help",
width-50+4, height-650+9+6);
}
//----------------------------------------------------------------------------
// functions to register if mouse is over buttons funzione da registrare se il mouse è sui pulsanti
boolean overSave() { // modificato
return mouseX > width-50 &&
mouseY > height-740 &&
mouseY < height-740+25 ;
}
boolean overLoad() { //modificato
return mouseX > width-50 &&
mouseY > height-710 &&
mouseY < height-710+25 ;
}
boolean overNew() { //modificato
return mouseX > width -50 &&
mouseY > height-680 &&
mouseY < height-680+25 ;
}
boolean overHelp() { //modificato
return mouseX > width -50 &&
mouseY > height-650 &&
mouseY < height-650+25 ;
}
// ---------------------------------------------------------------------------
// Inputs
void keyPressed() {
if (state==help) {
goBackToMainState();
return;
}
if (state!=normal)
return;
//
if ( keyCode == BACKSPACE ) {
//
backspaceOnActiveList();
//
}
// ----
else if ( keyCode == DELETE ) {
//
// ignore
//
} else if ( keyCode == ESC ) {
//
// If yellow help box is ON
if (showHelpText1) {
showHelpText1 = false; // yellow help box off
} else {
// else toggle
showText = !showText; // data text / tables
}//else
// kill Esc so we stay in the program
key=0;
//
}
// ------
else {
if ( key != CODED ) {
//
switch(key) {
case '0':
activeArrayListHasNumber = 0;
break;
case '1':
activeArrayListHasNumber = 1;
break;
case '2':
activeArrayListHasNumber = 2;
break;
case '3':
activeArrayListHasNumber = 3;
break;
case 'x':
showHelpText1 = !showHelpText1; // yellow help box
break;
case 'm':
showText = !showText; // data text / tables
break;
//
}//switch
//
}//if
}//else
}// func
void mousePressed() {
if (state==help) {
goBackToMainState();
return;
}
if (state!=normal)
return;
// for the buttons
if ( overSave() ) {
initSave();
}
//---
else if ( overLoad() ) {
initLoad();
} else if ( overHelp() ) {
state=help;
}
//---
else if ( overNew() ) {
//
if ( activeArrayListHasNumber==0 ) {
points1.clear(); //cancellare punti con new
} else if ( activeArrayListHasNumber==1 ) {
points2.clear(); //cancellare punti con new
} else if ( activeArrayListHasNumber==2 ) {
points3.clear(); //cancellare punti con new
} else if ( activeArrayListHasNumber==3 ) {
points4.clear(); //cancellare punti con new
}// else if
// set name
fileNames[activeArrayListHasNumber] = "not a File";
//
}
//---
boolean done = false;
if (mouseY>390 && mouseY<425){
for (int i=0; i < arrayOfXValuesFrom.length; i++) {
if (mouseX>arrayOfXValuesFrom[i] &&
mouseX<arrayOfXValuesTo[i]) {
//
activeArrayListHasNumber=i;
done = true;
break;
}//if
}//for
}//if
if (!done) {
// points.add(new PVector(points.size(), mouseY/10));
if ( activeArrayListHasNumber == 0 ) {
points1.add(new PVector(points1.size(), MasA));
// points1.add(new PVector(points1.size(), mouseY));
} else if ( activeArrayListHasNumber == 1 ) {
points2.add(new PVector(points2.size(), MasA));
//points2.add(new PVector(points2.size(), mouseY));
} else if ( activeArrayListHasNumber == 2 ) {
points3.add(new PVector(points3.size(), MasA));
//points3.add(new PVector(points3.size(), mouseY));
} else if ( activeArrayListHasNumber == 3 ) {
//points2.add(new PVector(points2.size(), MasA.getValue()));
//points4.add(new PVector(points4.size(), mouseY));
points4.add(new PVector(points4.size(), MasA));
}
}
}//func
// -------------------------------------------------
// Save and load
void initSave() {
// init save process
// reset
savePath="";
// make date time stamp (the expression nf(n,2) means leading zero: 2 becomes 02)
String dateTimeStamp = year()
+ nf(month(), 2)
+ nf(day(), 2)
+ "-"
+ nf(hour(), 2)
+ nf(minute(), 2)
+ nf(second(), 2);
// prepare fileDescription which occurs in the dialogue
// prepara la descrizione del file che avviene nel dialogo
File fileDescription = new File( sketchPath()
+ "//"
+ pathFolder
+ "//"
+ dateTimeStamp
+ fileExtension);
// open the dialog
selectOutput("Select a file to write to", "fileSelectedSave", fileDescription);
// set state to wait
state=save;
}
void initLoad() {
// init load process
// reset
loadPath="";
// prepare fileDescription which occurs in the dialogue
File fileDescription = new File( sketchPath()+"//"+pathFolder+"//"+"*" + fileExtension );
// open the dialog
selectInput("Select a file to load", "fileSelectedLoad", fileDescription);
// set state to wait
state=load;
}
void fileSelectedSave(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// println ("La finestra è stata chiusa o l'utente ha premuto annulla.");
// torna indietro
state=normal; // go back
} else {
// println("User selected " + selection.getAbsolutePath());
savePath=selection.getAbsolutePath();
}
}
void fileSelectedLoad(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// go back
state=normal;
} else {
// println("User selected " + selection.getAbsolutePath());
loadPath=selection.getAbsolutePath();
}
}
void waitForSaveDialog() {
if (!savePath.equals("")) {
// waiting is over
saveIt();
// go back
state=normal;
}
}
void waitForLoadDialog() {
if (!loadPath.equals("")) {
// waiting is over
loadIt();
// go back
state=normal;
}
}
void saveIt() {
// save
// make array (to save it)
String[] strs;
strs = new String[0];
if (activeArrayListHasNumber==0) {
strs = new String[points1.size()];
int i=0;
for (PVector pv : points1) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//
else if (activeArrayListHasNumber==1) {
strs = new String[points2.size()];
int i=0;
for (PVector pv : points2) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//else
else if (activeArrayListHasNumber==2) {
strs = new String[points3.size()];
int i=0;
for (PVector pv : points3) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//else
else if (activeArrayListHasNumber==3) {
strs = new String[points4.size()];
int i=0;
for (PVector pv : points4) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//else
// check if file extension (fileExtension, e.g. .txt) is there
int len = savePath.length();
if (len<4 || !savePath.substring( len-4 ).equals(fileExtension)) {
// file Extension is not present, we have to add it
savePath += fileExtension; // add the file Extension
}
// save
println("Saved: " + savePath);
saveStrings( savePath, strs );
// get file name for list
fileNames[activeArrayListHasNumber] = nameFromPath(savePath);
} //func
void loadIt() {
// load
if (activeArrayListHasNumber==0)
{
points1.clear();
} else if (activeArrayListHasNumber==1)
{
points2.clear();
} else if (activeArrayListHasNumber==2)
{
points3.clear();
} else if (activeArrayListHasNumber==3)
{
points4.clear();
}
fileNames[activeArrayListHasNumber] = nameFromPath(loadPath);
String[] strs = loadStrings( loadPath );
for (String s : strs) {
String[] thisLine=split(s, ",");
if (activeArrayListHasNumber==0)
{
points1.add(new PVector(float(thisLine[0]), float(thisLine[1])));
} else if (activeArrayListHasNumber==1)
{
points2.add(new PVector(float(thisLine[0]), float(thisLine[1])));
} else if (activeArrayListHasNumber==2)
{
points3.add(new PVector(float(thisLine[0]), float(thisLine[1])));
} else if (activeArrayListHasNumber==3)
{
points4.add(new PVector(float(thisLine[0]), float(thisLine[1])));
}//else
//
}//for
}//func
// -------------------------------------------------
void showData1() {
//
// show data 1
PVector prev = new PVector(-1, -1);
int y=50;
if (activeArrayListHasNumber==0) {
stroke(255, 2, 2); // RED
line (900, 405, 990, 405); //linea sopra tabella
line (870, 260, 1330, 260);
line (870, 280, 1330, 280);// linee text file
ellipse (865, 270, 6, 6);
}
for (PVector pv : points1) {
if (showText) {
fill(255, 2, 2); // RED
// show data
text(pv.x, 970-50, y+410);
text(pv.y, 970, y+410);
}
fill(0, 2, 2);
stroke(255, 2, 2); // RED
float yvalue = map( pv.y, 0,1, 700, 180); //mappatura linea grafica RED
if (prev.x!=-1) {
line(80 + pv.x*55, yvalue,
prev.x, prev.y);// linea grafico red
}
stroke(150);
ellipse (80 + pv.x*55, yvalue, 4, 4);
prev = new PVector(80 + pv.x*55, yvalue);
y+=20; //next line
}//for
if (showText) {
// middle line
stroke(255, 2, 2); // RED
line(1275-330,440, 1275-330,720);
}
//
}
void showData2() {
//
// show data 2
if (activeArrayListHasNumber==1) {
// activeArrayListHasNumber is FALSE, right side is active
stroke(2, 255, 2); // GREEN
line (1010, 405, 1100, 405);
line (870, 290, 1330, 290);
line (870, 310, 1330, 310);// linee text file
ellipse (865, 300, 6, 6);
}
Answers
and the sketch is now too long to post in one go
this is so lame............................
I made a new version that can display the file name for each column
Thanks Chrisir ..... you know a more than wikipedia ..... you're teaching me a lot ......
you are not making progress
only I make progress
can you read arduino data and fill in table 1 please?
Technically our (my) code is not good, because we have very similar sections that could be unified and made much better.
E.g. we have 8 buttons now, 4 on the right side (Load etc.) and 4 buttons above the 4 columns. But we don't have a nice structure to check them for mouse click.
Look at this code, there are a lot of repetitions going on:
Its almost the same 4 times:
Instead it would be cool to have a list of buttons and say something like
That's pseudo code obviously but it's much shorter.
At the moment you just have numbers like
height-650
. Now you could put them in variables likexpositon1
. Then you could have one list for the x position of all buttons, one list of the y positions of all buttons, the heights and so on.Then there is the concept of object oriented programming (OOP) which allows us to define what ONE button is (seen in an abstract way), a x position, y position, widthButton and heightButton ajnd its text (caption, "Load" etc.) and it should be able to register the mouse on it of course. Such a package is called a
class
.Then we can make a list (array) of that Button class. Very cool.
To dive into it read:
https://github.com/Kango/Processing-snippets/wiki/Variables,-Arrays-and-object-oriented-programming
https://www.processing.org/tutorials/objects/
Chrisir ;-)
In this new version, file names are written under the 4 columns
My advice, read careful the entire code, think about what I do there, grab a pen of paper and make some notes about the components of the sketch
What I said about the buttons being redundant and the necessity to unify them in a list / array is also true for the 4 columns of data : they also share a lot of common code which contradicts the DRY principle of programming: don’t repeat yourself.
here is an example of buttons in an Array (list)
Thanks Chrisir, the merit of where I arrived and all yours, I still have to study and apply myself so much ..... This is where I came to create the sketch ......
Can you read data from arduino now...?
Read them
yes....
;-)
however, from me it is said the appetite is eating .....
What do you mean by this?