# After importing one icon i want to give functionality

**URL:** <https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859>\
**Category:** Libraries\
**Created:** [November 27, 2019, 9:15am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859 "2019-11-27T09:15:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![aronisha](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aronisha](https://discourse.processing.org/u/aronisha)\
**Post date:** [November 27, 2019, 9:15am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/1 "2019-11-27T09:15:09Z")

</div>

i use user account icon and i want to give some functionality for that icon.  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/5b47380787e42e5314608284221c57229ca4cf7b.png)

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 27, 2019, 10:19am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/2 "2019-11-27T10:19:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aronisha](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aronisha](https://discourse.processing.org/u/aronisha)\
**Post date:** [November 27, 2019, 10:22am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/3 "2019-11-27T10:22:53Z")

</div>

i try to create an application for windows

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 27, 2019, 10:29am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/4 "2019-11-27T10:29:10Z")

</div>

You might want to try something like this :

```auto
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.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 27, 2019, 10:55am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/5 "2019-11-27T10:55:42Z")

</div>

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?

* * *

> [@aronisha](#):
>
> create an application for windows

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

---

<div class="post-metadata">

**Author:** ![aronisha](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aronisha](https://discourse.processing.org/u/aronisha)\
**Post date:** [November 27, 2019, 10:58am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/6 "2019-11-27T10:58:25Z")

</div>

yes when the mouse is click on letter icon it open new window  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/61a78bfd9f70c3cf853bfedca0fa1cc2c850924f.png)

---

<div class="post-metadata">

**Author:** ![aronisha](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aronisha](https://discourse.processing.org/u/aronisha)\
**Post date:** [November 27, 2019, 11:01am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/7 "2019-11-27T11:01:41Z")

</div>

i want to create two type of user accounts

1. users
2. admins  
on the admin side they can see database system like  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c5374b78a1566759c3e173fdbaf077b3cb396664.png)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 27, 2019, 11:03am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/8 "2019-11-27T11:03:22Z")

</div>

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 ! )

---

<div class="post-metadata">

**Author:** ![aronisha](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aronisha](https://discourse.processing.org/u/aronisha)\
**Post date:** [November 27, 2019, 11:07am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/9 "2019-11-27T11:07:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 27, 2019, 11:15am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/10 "2019-11-27T11:15:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aronisha](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aronisha](https://discourse.processing.org/u/aronisha)\
**Post date:** [November 27, 2019, 11:49am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/11 "2019-11-27T11:49:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 27, 2019, 4:37pm UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/12 "2019-11-27T16:37:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aronisha](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aronisha](https://discourse.processing.org/u/aronisha)\
**Post date:** [November 30, 2019, 6:36am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/13 "2019-11-30T06:36:33Z")

</div>

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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/de0f42e738cdf2abffc3e215b23a9ad318d026bd.png)

---

<div class="post-metadata">

**Author:** ![aronisha](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aronisha](https://discourse.processing.org/u/aronisha)\
**Post date:** [November 30, 2019, 6:37am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/14 "2019-11-30T06:37:29Z")

</div>

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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1ff618b8c7e4d2c420206da123da23a189f89103.png)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 30, 2019, 9:25am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/15 "2019-11-30T09:25:09Z")

</div>

please format your code posting by pasting it into the

```auto
</> 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 )

```auto
// 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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a4f5b2468b774ba812433eba5434943a13dcfa98.png)  
 ![button_letter](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8c0779cfa4fc872b47811ad760ce17d31b695881.png)  
 ![button_memo](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0737fde2e5abc9856e7978954477ef270fdcd937.png)

 ![button_three_image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/15f0b4905edb99aa56cbbfd3c86a3959044ab29d.png)  
\_\_  
ok, that code uses some concepts you might need more help to understand,  
please ask here anytime

---

<div class="post-metadata">

**Author:** ![aronisha](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aronisha](https://discourse.processing.org/u/aronisha)\
**Post date:** [December 2, 2019, 2:02pm UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/16 "2019-12-02T14:02:12Z")

</div>

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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c420d6132e4ebd6257572d3131cad0c7c5b6eb57.png)

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

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 2, 2019, 2:16pm UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/17 "2019-12-02T14:16:14Z")

</div>

please format your code posting by pasting it into the

```auto
</> 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](https://discourse.processing.org/t/solved-g4p-options-in-second-window-problem/4552/3) 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.

---

<div class="post-metadata">

**Author:** ![aronisha](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aronisha](https://discourse.processing.org/u/aronisha)\
**Post date:** [December 2, 2019, 2:19pm UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/18 "2019-12-02T14:19:04Z")

</div>

```auto
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);`

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 3, 2019, 5:22am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/19 "2019-12-03T05:22:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aronisha](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aronisha](https://discourse.processing.org/u/aronisha)\
**Post date:** [December 3, 2019, 5:44am UTC](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859/20 "2019-12-03T05:44:47Z")

</div>

for example

- add button on the second window

[Next page](https://discourse.processing.org/t/after-importing-one-icon-i-want-to-give-functionality/15859.md?page=2)
