After importing one icon i want to give functionality

sorry, but above i give you the link to a post from quark ( he makes G4P )

when you run that code you get 2 windows ( with 2 option groups )
and see how that can be operated from both windows,


.p.s. i made for you a ready ( optional image ) button code
( also with the idea you want learn processing )
but you ignored and go for G4P buttons AND a 2 windows concept…
is ok, but not expect using such a high-level library is easier…

ONLY A START:

// https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/21


import g4p_controls.*;

GButton btnMakeWindow1,btnMakeWindow2,btnMakeWindow3;
GButton saveW1;
GWindow window1,window2,window3;

GTextField txf1, txf2, txf3;    // input text fields for window1 : letter 
GLabel lbltxf1,lbltxf2,lbltxf3; // with labels

String W1_input_txf1, W1_input_txf2, W1_input_txf3;  // global strings as result from window 1 / ON button click

void setup() {
  size(450, 230);
  make_main_buttons();
}

void draw() {
  background(202, 239, 127);
}



void make_main_buttons() {
  int x1=259, y1=40, dy=50, w1=170, h1=50;
  btnMakeWindow1 = new GButton(this, x1, y1, w1, h1);
  btnMakeWindow1.setIcon("Letter.png", 1, GAlign.EAST, GAlign.MIDDLE, GAlign.MIDDLE);
  btnMakeWindow2 = new GButton(this, x1, y1+dy, w1, h1);
  btnMakeWindow2.setIcon("Memo.png", 1, GAlign.EAST, GAlign.MIDDLE, GAlign.MIDDLE);
  btnMakeWindow3 = new GButton(this, x1, y1+2*dy, w1, h1);
  btnMakeWindow3.setIcon("Delete.png", 1, GAlign.EAST, GAlign.MIDDLE, GAlign.MIDDLE); 
}

void handleButtonEvents(GButton button, GEvent event) {
  if (button == btnMakeWindow1 && event == GEvent.CLICKED) {
    createWindow1();
    btnMakeWindow1.setEnabled(false);
  }
  if (button == btnMakeWindow2 && event == GEvent.CLICKED) {
    createWindow2();
    btnMakeWindow2.setEnabled(false);
  }
  if (button == btnMakeWindow3 && event == GEvent.CLICKED) {
    createWindow3();
    btnMakeWindow3.setEnabled(false);
  }
}


void createWindow1() {
  println("W1 letter ");
  window1 = GWindow.getWindow(this, "Window Letter", 70, 160, 500, 300, JAVA2D);
  window1.setActionOnClose(G4P.CLOSE_WINDOW);
  window1.addData(new MyWinData());
  window1.addDrawHandler(this, "windowDraw");
  window1.addMouseHandler(this, "windowMouse");
  window1.addKeyHandler(this, "windowKey");
  
  make_W1_widgets();
}

void createWindow2() {
  println("W2 memo ");
}

void createWindow3() {
  println("W3 delete ");
}

void make_W1_widgets() {
  int x1=30, dx=200, y1=40, dy=50, w1=170, h1=20;  

  lbltxf1 = new GLabel(window1, x1, y1, w1, h1);
  lbltxf1.setTextAlign(GAlign.LEFT, null);
  lbltxf1.setText("T1");

  lbltxf2 = new GLabel(window1, x1, y1+dy, w1, h1);
  lbltxf2.setTextAlign(GAlign.LEFT, null);
  lbltxf2.setText("T2");

  lbltxf3 = new GLabel(window1, x1, y1+2*dy, w1, h1);
  lbltxf3.setTextAlign(GAlign.LEFT, null);
  lbltxf3.setText("T3");

  
  txf1 = new GTextField(window1, x1+dx, y1, w1, h1);
  txf1.tag = "txf1";
  txf1.setPromptText("Text field 1");
  //txf1.setText("t1");

  txf2 = new GTextField(window1, x1+dx, y1+dy, w1, h1);
  txf2.tag = "txf2";
  txf2.setPromptText("Text field 2");
  //txf2.setText("t2");
  
  txf3 = new GTextField(window1, x1+dx, y1+2*dy, w1, h1);
  txf3.tag = "txf3";
  txf3.setPromptText("Text field 3");
  //txf3.setText("t3");

  saveW1 = new GButton(window1, x1+dx+10, height-h1, 80, 25);
  saveW1.setText(" BACK ");
  
  saveW1.addEventHandler(this,"backW1click"); //___ must be this, not window1 !!
}

public void backW1click(GButton button, GEvent event) {
  if ( button == saveW1 ) {
    println("W1 back button pressed "+event);
    W1_input_txf1 = txf1.getText();
    W1_input_txf2 = txf2.getText();
    W1_input_txf3 = txf3.getText();
    println(lbltxf1.getText(), W1_input_txf1,lbltxf2.getText(),W1_input_txf2,lbltxf3.getText(),W1_input_txf3 );    
  }
}

public void handleTextEvents(GEditableTextControl textcontrol, GEvent event) { /* code */ }

class MyWinData extends GWinData {
  int sx, sy, ex, ey;
  boolean done;
  int col;
}

public void windowMouse(PApplet appc, GWinData data, MouseEvent event) {
  MyWinData data2 = (MyWinData)data;
  switch(event.getAction()) {
  case MouseEvent.PRESS:

    break;
  case MouseEvent.RELEASE:

    break;
  case MouseEvent.DRAG:

    break;
  }
}

public void windowDraw(PApplet appc, GWinData data) {
  MyWinData data2 = (MyWinData)data;
  appc.background(200,200,0); // winX background
}  

public void windowKey(PApplet appc, GWinData data, KeyEvent keyevent ) {
  MyWinData data2 = (MyWinData)data;
}  

1 Like
  • is there any suggestion that i can create the database to store the data i fill on the 3 rows
  • and the way that can i see the text i fill in second window on the first window

yes, a good thing is using a file:
/data/mydata.csv

with or without excel/csv headerline

and in processing use

checkout how powerful that is

different syntax but functions like arrayList

but it might also depend on HOW the data
( the result of your program is? stored user input ? )
have to be used further?


did you test my program?
there i declared and set global variables
you can use in any window

1 Like

thank you for your support !! if i create user account system for the application is that possible some users to access the database system
also please recommend me about

  • user account making codes
  • getting time and date directly from internet
  • when i go to second window to hide the first window & when i click back button to close the second window then return to the the first window
  • like button making website please suggest me better icon making websites or icon websites
  • is that good add some python codes on my coding?

-a- database:
https://github.com/fjenett/sql-library-processing ,

-b- date time
https://processing.org/reference/day_.html

-c- window select open close G4P
http://www.lagers.org.uk/g4p/ref/classg4p__controls_1_1_g_window.html

-d- why you not draw that buttons with draw or paint tools
if you not find good ones online
the buttons i make for you and show you i do online, sure, the link is inside the code
After importing one icon i want to give functionality,
you have own button pictures in your post already.
and not forget, anything you find in browser ( like with google )
you can snap to a picture, snip out just the area you want use for a button
and use that from file from processing as image button.

-e- mix with python difficult, but you might do the whole thing in python
https://py.processing.org/
— worst case can do 2 separate applications what talk via stored file…