not fully sure what your intention is
and not fully sure whether you know what a 2D grid means
Here is my version
- where you can add your input (instead of splice I wrote my own function myConcat to splice a new line BEFORE the old lines) and
- where the screen shows the 2D grid…
final int maxColumns = 6;
Blocks[][] Bl = new Blocks[maxColumns][20];
String str_num = "";
// ----------------------------------------------------------------------------------------
void setup() {
size(1740, 860);
for (int i= 0; i < 20; i++) {
Bl[0][i]=new Blocks(i, 0, 0, 0, 0);
Bl[1][i]=new Blocks(0, 0, 0, 0, 0);
Bl[2][i]=new Blocks(0, 0, 0, 0, 0);
Bl[3][i]=new Blocks(0, 0, 0, 0, 0);
Bl[4][i]=new Blocks(0, 0, 0, 0, 0);
Bl[5][i]=new Blocks(0, i, 0, 0, 0);
}
background(255);
}
void draw() {
//
background(255);
showScreen();
// Black
fill(9);
stroke(9);
// show TABLE
for (int i2=0; i2<Bl.length; i2++) {
for (int i=0; i<Bl[i2].length; i++) {
text( "Bl " + i2 +", " + i +" : "
+ Bl[i2][i].getProperties(),
19+260*i2, 39+29*i,
260, 133);
}
}// for
}//func
// ----------------------------------------------------------------------------------------
void showScreen() {
// Black
fill(9);
stroke(9);
// Headline
text("2D-Table with rows and columns",
244, 19);
line( 24, 22,
width-55, 22);
// show RED Input area
fill(255, 0, 0);
stroke(255, 0, 0);
text ("Enter: "+str_num,
200, height- 46);
line (200, height- 62,
1200, height- 62);
}
void keyPressed() {
if ( key >= '0' && key <= '9' ) {
str_num += key;
} else if ( key == ENTER || key == RETURN ) {
int num = 0;
num = int( str_num );
// we init the new line
Blocks[][] Bl_new = new Blocks[ maxColumns] [1];
int i=0;
Bl_new[0][i]=new Blocks(0, 0, 0, 0, 0);
Bl_new[1][i]=new Blocks(0, 0, 0, 0, 0);
Bl_new[2][i]=new Blocks(0, 0, 0, 0, 0);
Bl_new[3][i]=new Blocks(0, 0, 0, 0, 0);
Bl_new[4][i]=new Blocks(0, 0, 0, 0, 0);
Bl_new[5][i]=new Blocks(0, -1, 0, 0, 0);
Bl_new[1][i].Duration=num;
str_num = "";
//for (int i=0; i<=19; i++) {
// Bl[1][i].ShowProperties();
//}
// Bl = (Blocks[][]) splice (Bl, Bl_new, 0);
// Add new line at START of table
Bl = myConcat (Bl_new, Bl );
}
}
Blocks[][] myConcat( Blocks[][] newBl,
Blocks[][] oldBl ) {
// Add new line at START of table
println(oldBl.length+1);
Blocks[][] Bl_result = new Blocks[oldBl.length][oldBl[0].length+1];
// init 1st line
for (int i_row = 0; i_row < 6; i_row++) {
Bl_result[i_row][0]=new Blocks(0, 0, 0, 0, 0);
Bl_result[i_row][0]=newBl[i_row][0];
}
// init other lines
for (int i_row=1; i_row<Bl_result[0].length; i_row++) {
for (int i = 0; i < 6; i++) {
Bl_result[i][i_row]=new Blocks(0, 0, 0, 0, 0);
Bl_result[i][i_row]=oldBl[i][i_row-1];
}
}
return Bl_result;
}
// =====================================================================================
class Blocks {
int Lower, Duration, Start, AVG_RPM, State;
// constr
Blocks (int LowerTemp, int DurationTemp,
int StartTemp, int AVG_RPMTemp, int StateTemp) {
Lower=LowerTemp;
Duration=DurationTemp;
Start=StartTemp;
AVG_RPM=AVG_RPMTemp;
State=StateTemp;
}// constr
void ShowProperties() {
println ("Bl[1]: " +Lower, Duration, Start, AVG_RPM, State);
}//method
String getProperties() {
return
Lower +", "
+ Duration + ", "
+ Start + ", "
+ AVG_RPM + ", "
+ State;
}//method
//
}//class
//