# Button on a touchscreen

**URL:** <https://discourse.processing.org/t/button-on-a-touchscreen/1505>\
**Category:** Coding Questions\
**Created:** [July 5, 2018, 1:18am UTC](https://discourse.processing.org/t/button-on-a-touchscreen/1505 "2018-07-05T01:18:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AidanLand](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aidanland/32/614_2.png) [@AidanLand](https://discourse.processing.org/u/AidanLand)\
**Post date:** [July 5, 2018, 1:18am UTC](https://discourse.processing.org/t/button-on-a-touchscreen/1505/1 "2018-07-05T01:18:00Z")

</div>

**Hi,** I’m trying to create a drawing program that will work with a touch screen. Right now I can draw on the screen with a pen, but if I try to click a button on the screen my program won’t respond. I have to either swipe, or double tap for my program to work. All my code works well with a mouse. I use an if() statement and mousePressed for the buttons. I have tried mouseClicked() and mouseRealesed() and they have worked either the same way or worse. I was wondering if there were any touch commands for processing, or any java ones I could use. If anyone has the solution please help. Thanks! 🙂

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 5, 2018, 4:48am UTC](https://discourse.processing.org/t/button-on-a-touchscreen/1505/2 "2018-07-05T04:48:20Z")

</div>

Please provide specs of your system. It might help, or provide a better lead.

Not an expert on this, but maybe the next links could be relevant.

> [6 Working with Touch Events (Release 8)](https://docs.oracle.com/javase/8/javafx/events-tutorial/touch_events.htm)  
> [TouchEvent (JavaFX 8)](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/input/TouchEvent.html)  
> [java - Separate touch from mouse event - Stack Overflow](https://stackoverflow.com/questions/23239239/separate-touch-from-mouse-event)

There could be a bit of an issue with mouse events, and connecting to touch events, as Processing seems to define its own MouseEvent class. Not sure if this is a problem at the end but it is good to keep it in mid during the debugging process. For this, check [Library Basics](https://github.com/processing/processing/wiki/Library-Basics).

Kf

---

<div class="post-metadata">

**Author:** ![AidanLand](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aidanland/32/614_2.png) [@AidanLand](https://discourse.processing.org/u/AidanLand)\
**Post date:** [July 5, 2018, 11:24pm UTC](https://discourse.processing.org/t/button-on-a-touchscreen/1505/3 "2018-07-05T23:24:49Z")

</div>

Sorry I couldn’t respond sooner,  
I use windows 8.1 and processing 3.3.7 on a 2 in 1 laptop.  
here is my code for the buttons:  
void appBar() {  
if (bar==true) {  
noStroke();  
//stroke(r, g, b);  
//strokeWeight(10);  
fill(150);  
rect(0, 0, width, 100);  
textAlign(CENTER, BOTTOM);  
fill(0);  
textSize(60);  
text(“Aidan Land Ink”, width/2, 100);  
fill(255, 0, 0);  
rect(0, 0, 100, 100);  
fill(0, 255, 0);  
rect(100, 0, 100, 100);  
fill(0, 0, 255);  
rect(200, 0, 100, 100);  
fill(0);  
rect(300, 0, 100, 100);  
if (mouseX\<400&&mouseY\<100&&mousePressed) {  
r=red(get(mouseX, mouseY));  
g=green(get(mouseX, mouseY));  
b=blue(get(mouseX, mouseY));  
}  
if (e==false) {  
fill(r, g, b);  
} else {  
fill(255);  
}  
if (s==true) {  
ellipse(450, 50, 100, 100);  
} else {  
ellipse(450, 50, 50, 50);  
}  
if (mouseY\<100&&mouseX\>400&&mouseX\<500&&mousePressed) {  
s=!s;  
delay(100);  
}

```
fill(255);
ellipse(550, 50, 100, 100);
if (mouseY<100&&mouseX>500&&mouseX<600&&mousePressed) {
  e=!e;
  delay(100);
}
if (mouseX>600&&mouseX<displayWidth-100&&mouseY<100&&red(get(mouseX, mouseY))==0&&mousePressed) {
  launch(path[0]);
  save("data\\saved.png");
  exit();
}

```

}else{  
noStroke();  
fill(255);  
rect(0,0,width,100);  
}  
}

I then call the appbar() command in my draw loop.  
I did look at the links in your reply and the TouchEvent looked like something that would work, but I couldn’t figure out how to use them in processing.(I’m no expert either)  
I hope some of this helps.
