After importing one icon i want to give functionality

i use user account icon and i want to give some functionality for that icon.
image

We need a bit more Information, like the way your User Icon works. Some Code would be good.

i try to create an application for windows

You might want to try something like this :

void mousePressed() {
   if (mouseX > iconPosX && mouseX < iconPosX + iconWidth && mouseY > iconPosY && mouseY < iconPosY + iconHeight)
      iconFunctionality();
}

Or adapt that to a class if your Icon is one.

more details please,
like do you want
[ letter ] [ memo ] [ delete ]
as 3 rectangles with text ( or a icon/image ) and do something ( different )
on mouse click?


did you try/test already to use the
processing 3.5.3 / File / Export Application /
on any working example?

yes when the mouse is click on letter icon it open new window
image

i want to create two type of user accounts

  1. users
  2. admins
    on the admin side they can see database system like

good, so after 3 action buttons,
need a new screen with 3 text input fields
and fill a spread sheet ( on screen / CSV file export / or even database connection )

how many days / weeks you got to learn all this? ( this is NOT bad talking ! )

i don’t know it will take much time. but could you please help me on it.

YOU start first,
use a empty screen
make a rectangle
and use above @Lexyth
void mousePressed()
to print a msg to console,

YOUR FIRST BUTTON

after that works show the code here using the
</> code button from editor header menu
and we can talk how to make more and better buttons

1 Like

It is letter registration application. i work in automotive company and we use a book to register letter and memo reference no.s that is why i want to create this software.

1 Like

Please post how far you‘ve come and if you encountered any troubles. :wink:

PImage img;
PImage img2;
PImage img4;
PFont f;
String s = “New Letter”;
String t = “New Memo”;
String u = “Delete”;
void setup() {
size(450, 230);
img=loadImage(“Untitled-6.png”);
img2=loadImage(“Delete.png”);
img4=loadImage(“plus.png”);
f=loadFont(“CenturyGothic-48.vlw”);
textFont(f, 20);
fill(0);
}
void draw() {
noFill();
background(245);
text(s, 265, 78);
text(t, 265, 120);
text(u, 280, 165);
image(img4, 378, 50);
image(img4, 378, 95);
image(img2, 378, 140);
strokeWeight(5);
stroke(242, 204, 47, 102);
rect(5, 5, 440, 220);
strokeWeight(1);
stroke(110);
rect(5, 5, 440, 220);
strokeWeight(2);
stroke(0);
rect(260, 50, 158, 38);
strokeWeight(2);
stroke(0);
rect(260, 95, 158, 38);
strokeWeight(2);
stroke(255,0,0);
rect(260, 140, 158, 38);
image(img, 405, 10);
}
image

PImage img;
PImage img1;
PFont f;
String s = “Company Name”;
String t = “Reason”;
String u = “Remark”;
void setup() {
size(450, 230);
img=loadImage(“ab.png”);
img1=loadImage(“create.png”);
f=loadFont(“CenturyGothic-48.vlw”);
textFont(f, 20);
fill(0);
}
void draw() {
noFill();
background(245);
text(s, 50, 68);
text(t, 50, 108);
text(u, 50, 148);
strokeWeight(5);
stroke(242, 204, 47, 102);
rect(5, 5, 440, 220);
strokeWeight(1);
stroke(110);
rect(5, 5, 440, 220);
strokeWeight(2);
stroke(110);
rect(260, 50, 140, 25);
strokeWeight(2);
stroke(110);
rect(260, 90, 140, 25);
strokeWeight(2);
stroke(110);
rect(260, 130, 140, 25);
image(img, 25, 15);
image(img1, 380, 165);
}

image

please format your code posting by pasting it into the

</> code button

of the editor header menu ( context name: Preformatted text )
it looks like
```
type or paste code here
```

also can use the ``` manually above and below your code.

thank you.


to make functioning buttons need
rectangle or image
( here combined and you can disable what you not need )

// using a function for the button and one for mouse over: 
// please see how little change needed to make (2) more buttons

// made some nice buttons for you, using
// https://dabuttonfactory.com/

PImage b_delete,b_letter,b_memo;

void get_images() {
  b_delete = loadImage("data/button_delete.png");  
  b_letter = loadImage("data/button_letter.png");  
  b_memo   = loadImage("data/button_memo.png");  
}

int x1 = 100, y1 = 100, w1 =108, h1 =42;
boolean sel1 = false;
String text1 = "letter";

int x2 = x1, y2 = y1+h1+10, w2 =w1, h2 =h1; //_________________ (2)
boolean sel2 = false; //_______________________________________ (2)
String text2 = "memo"; //______________________________________ (2)

int x3 = x1, y3 = y2+h1+10, w3 =w1, h3 =h1; //_________________ (3)
boolean sel3 = false; //_______________________________________ (3)
String text3 = "delete"; //____________________________________ (3)

void setup() {
  size(300, 300);
  strokeWeight(3);
  textSize(20);
  get_images();
}

void draw() {
  background(200, 200, 0);
  myButton(x1, y1, w1, h1, sel1, text1,b_letter);
  myButton(x2, y2, w2, h2, sel2, text2,b_memo); //____________________ (2)
  myButton(x3, y3, w3, h3, sel3, text3,b_delete); //____________________ (3)
}

void keyPressed() {
}

void mousePressed() {
  if ( over(x1, y1, w1, h1) ) {
    sel1 = ! sel1;            // button 1 action
    if ( sel1 ) { 
      println(" pressed event 1"); // here add your code
      // sel1=false; // reset for push button thinking
    }
  }
  if ( over(x2, y2, w2, h2) ) {
    sel2 = ! sel2;            // button 2 action //_ (2)
    if ( sel2 ) { 
      println(" pressed event 2"); // here add your code
      // sel2=false; // reset for push button thinking
    }
  }  
  if ( over(x3, y3, w3, h3) ) {
    sel3 = ! sel3;            // button 3 action //_ (3)
    if ( sel3 ) { 
      println(" pressed event 3"); // here add your code
      // sel3=false; // reset for push button thinking
    }
  }
}

void myButton(int x, int y, int w, int h, boolean sel, String atext, PImage btn) {
  if ( sel )               fill(0, 200, 0);
  else                     fill(0, 0, 200);
  strokeWeight(3);
  if ( over(x, y, w, h) )  stroke(200, 0, 200);
  else                     stroke(0, 200, 200);
  rect(x, y, w, h);
  noStroke();
  fill(200);
  text(atext, x+10, y+h-10);
  // image button version  
  image(btn,x+1, y+1);
}

boolean over(int x, int y, int w, int h) {
  return ( mouseX > x & mouseX < x + w &  mouseY > y & mouseY < y + h ) ;
}

now that would not work without images,
unless you disable all code line ( // ) using them.

try to catch here, save under /data/,
OR make your own.

button_delete
button_letter
button_memo


__
ok, that code uses some concepts you might need more help to understand,
please ask here anytime

1 Like

import g4p_controls.*;

GButton btnMakeWindow;
GButton btnMakeWindow1;
GButton btnMakeWindow2;
GWindow window;
int x1=259, y1=40, w1=170, h1=50;

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

btnMakeWindow = new GButton(this, x1, y1, w1, h1);
btnMakeWindow.setIcon(“Letter.png”, 1, GAlign.EAST, GAlign.MIDDLE, GAlign.MIDDLE);
btnMakeWindow1 = new GButton(this, x1, y1+60, w1, h1);
btnMakeWindow1.setIcon(“Memo.png”, 1, GAlign.EAST, GAlign.MIDDLE, GAlign.MIDDLE);
btnMakeWindow2 = new GButton(this, x1, y1+120, w1, h1);
btnMakeWindow2.setIcon(“Delete.png”, 1, GAlign.EAST, GAlign.MIDDLE, GAlign.MIDDLE);
}

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

void handleButtonEvents(GButton button, GEvent event) {
if (button == btnMakeWindow && event == GEvent.CLICKED) {
createWindows();
btnMakeWindow.setEnabled(false);
}
{
if (button == btnMakeWindow1 && event == GEvent.CLICKED) {
createWindows1();
btnMakeWindow.setEnabled(false);
}
}
}

void createWindows() {

println(“Making Window”);
window = GWindow.getWindow(this, “Letter”, 100, 100, 450, 230, JAVA2D);
rect(10,10,100,100);
stroke(2);
window.addOnCloseHandler(this, “windowClosing”);
background(202, 239, 127);
}// createWindow
void createWindows1() {

println(“Making Window”);
window = GWindow.getWindow(this, “Letter”, 100, 100, 450, 230, JAVA2D);
window.addOnCloseHandler(this, “windowClosing”);

}// createWindow

public void windowClosing() {
println(“Window closing”);
btnMakeWindow.setEnabled(true);
}

Capture

currently i update the code based on your comment and when the button is clicked it opens other window so could you please help me

  • how can i edit and add some thing on second window
  • if when i create a button when i create a back button how can i back to the first window
    -also how can i make close the window after creating letter reference no. and i want to display data that i fill in the second window on the first window left side

please format your code posting by pasting it into the

</> code button

of the editor header menu ( context name: Preformatted text )
it looks like
```
type or paste code here
```

also can use the ``` manually above and below your code.

thank you.


you switched to G4P lib,
good


no, i not talk WINDOW, i talked SCREEN ( same window / different content )

but G4P can do good 2 window applications,
see [SOLVED] G4P options in second window problem here
if it fits into your program flow


basically,
a second window can have the G4P text edit fields
with own event handler store the text content ( on ENTER )
to global variables.
so independent if window closed or not
the input is available in main window.

GButton btnMakeWindow;
GButton btnMakeWindow1;
GButton btnMakeWindow2;
GWindow window;
int x1=259, y1=40, w1=170, h1=50;

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

btnMakeWindow = new GButton(this, x1, y1, w1, h1);
btnMakeWindow.setIcon(“Letter.png”, 1, GAlign.EAST, GAlign.MIDDLE, GAlign.MIDDLE);
btnMakeWindow1 = new GButton(this, x1, y1+60, w1, h1);
btnMakeWindow1.setIcon(“Memo.png”, 1, GAlign.EAST, GAlign.MIDDLE, GAlign.MIDDLE);
btnMakeWindow2 = new GButton(this, x1, y1+120, w1, h1);
btnMakeWindow2.setIcon(“Delete.png”, 1, GAlign.EAST, GAlign.MIDDLE, GAlign.MIDDLE);
}

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

void handleButtonEvents(GButton button, GEvent event) {
if (button == btnMakeWindow && event == GEvent.CLICKED) {
createWindows();
btnMakeWindow.setEnabled(false);
}
{
if (button == btnMakeWindow1 && event == GEvent.CLICKED) {
createWindows1();
btnMakeWindow.setEnabled(false);
}
}
}

void createWindows() {

println(“Making Window”);
window = GWindow.getWindow(this, “Letter”, 100, 100, 450, 230, JAVA2D);
rect(10,10,100,100);
stroke(2);
window.addOnCloseHandler(this, “windowClosing”);
background(202, 239, 127);
}// createWindow
void createWindows1() {

println(“Making Window”);
window = GWindow.getWindow(this, “Letter”, 100, 100, 450, 230, JAVA2D);
window.addOnCloseHandler(this, “windowClosing”);

}// createWindow

public void windowClosing() {
println(“Window closing”);
btnMakeWindow.setEnabled(true);`

not understand the question,
?edit the second window?

  • you not know how to add editable G4P text fields on the second window?

  • you have that, but ‘user’ can not store text there?

  • or the text is stored in the widget but you not know how to use that in first window?
    ? second window needs like a [SEND] button
    to inform main sketch code the 3 text input finished,
    inside that button event also that copy 3 texts to global vars could take place.

for example

  • add button on the second window