# A problem with variables or libraries

**URL:** <https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [November 22, 2023, 6:43pm UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281 "2023-11-22T18:43:33Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vodin](https://avatars.discourse-cdn.com/v4/letter/v/74df32/32.png) [@Vodin](https://discourse.processing.org/u/Vodin)\
**Post date:** [November 22, 2023, 6:43pm UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/1 "2023-11-22T18:43:33Z")

</div>

Hi, I Try to do a radar. But now I have an error: frame cannot be resolved to a variable. May be I have problems with my libryries or something like that. I believe in you guys. If it will help the radar consist of: 2 ultrasonic sensors, 1 servo, 1 arduino nano. And here is the code:  
import processing.serial._;  
import static javax.swing.JOptionPane._;

Serial myPort; // The serial port  
String serialin;  
int data = new int[360];  
PFont f;

final boolean debug = true;

void setup() {  
String COMx, COMlist = “”;  
size(1280, 720);  
f = createFont(“Verdana”, 32, true); // Arial, 16 point, anti-aliasing on  
textFont(f, 20);  
frameRate(60);  
for (int i = 0; i \< 360; i++) {  
data[i] = 0;  
}  
try {  
if (debug) printArray(Serial.list());  
int i = Serial.list().length;  
if (i != 0) {  
if (i \>= 2) {  
// need to check which port the inst uses -  
// for now we’ll just let the user decide  
for (int j = 0; j \< i; ) {  
COMlist += char(j+‘a’) + " = " + Serial.list()[j];  
if (++j \< i) COMlist += ", ";  
}  
COMx = showInputDialog(“Which COM port is correct? (a,b,…):\n”+COMlist);  
if (COMx == null) exit();  
if (COMx.isEmpty()) exit();  
i = int(COMx.toLowerCase().charAt(0) - ‘a’) + 1;  
}  
String portName = Serial.list()[i-1];  
if (debug) println(portName);  
myPort = new Serial(this, portName, 9600); // change baud rate to your liking  
myPort.bufferUntil(‘\n’); // buffer until CR/LF appears, but not required…  
} else {  
showMessageDialog(frame, “Device is not connected to the PC”);  
exit();  
}  
}  
catch (Exception e)  
{ //Print the type of error  
showMessageDialog(frame, “COM port is not available (may\nbe in use by another program)”);  
println(“Error:”, e);  
exit();  
}  
}

void draw() {  
background(26, 26, 36, 200);  
textSize(18);  
stroke(255, 255, 255, 150);  
fill(255, 50, 200, 200);  
text(“Arduino RADAR 2D Visualization”, 20, 710);  
text(hour(), 1050, 710);  
text(“:”, 1075, 710);  
text(minute(), 1085, 710);  
text(“:”, 1110, 710);  
text(second(), 1120, 710);  
fill(36, 255, 100, 200);  
strokeWeight(3);  
circle(640, 360, 600);  
circle(640, 360, 500);  
circle(640, 360, 400);  
circle(640, 360, 300);  
circle(640, 360, 200);  
circle(640, 360, 100);

for (int i = 0; i \< 360; i++) {  
fill(255, 10, 255, 200);  
stroke(50, 10, 255, 150);  
point(float(640) + (map\_values(data[i]))\*cos(radians(i)), float(360) + (map\_values(data[i]))\*sin(radians(i)));  
}

while (myPort.available() \> 0) {  
serialin = myPort.readStringUntil(10);  
try {  
String serialdata = splitTokens(serialin, “,”);  
if (serialdata[0] != null) {  
serialdata[0] = trim(serialdata[0]);  
serialdata[1] = trim(serialdata[1]);  
serialdata[2] = trim(serialdata[2]);

```auto
    int i = int(serialdata[0]);
    data[179-i] = int(serialdata[1]);
    data[(179-i)+180] = int(serialdata[2]);
  }
} 
catch (java.lang.RuntimeException e) {
}

```

}  
}

float map\_values(float x) {  
float in\_min = 0, in\_max = 200, out\_min = 0, out\_max = 700;  
return (x - in\_min) \* (out\_max - out\_min) / (in\_max - in\_min) + out\_min;  
}

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [November 23, 2023, 1:05am UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/2 "2023-11-23T01:05:46Z")

</div>

1. Add these two imports:

> import javax.swing.JFrame;  
> import javax.swing.JOptionPane;

1. Inside setup() add this line of code:

> JFrame frame = new JFrame();

1. Call JOptionPane like this:

> JOptionPane.showMessageDialog(frame, “COM port is not available (may\nbe in use by another program)”);

---

<div class="post-metadata">

**Author:** ![Vodin](https://avatars.discourse-cdn.com/v4/letter/v/74df32/32.png) [@Vodin](https://discourse.processing.org/u/Vodin)\
**Post date:** [November 23, 2023, 6:32am UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/3 "2023-11-23T06:32:24Z")

</div>

Thanks. But where can I find a library for “javax.swing.JFrame” and other. I can’t find them in the processing or on sites.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 23, 2023, 10:46am UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/4 "2023-11-23T10:46:19Z")

</div>

> **[JFrame (Java SE 17 & JDK 17)](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/JFrame.html)**
>
> declaration: module: java.desktop, package: javax.swing, class: JFrame

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [November 23, 2023, 1:40pm UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/5 "2023-11-23T13:40:21Z")

</div>

What do you see when you type _java --version_ into your Terminal utility (Mac)? OpenJDK may be downloaded from here: [https://openjdk.org](https://openjdk.org) if you don’t have it.

---

<div class="post-metadata">

**Author:** ![Vodin](https://avatars.discourse-cdn.com/v4/letter/v/74df32/32.png) [@Vodin](https://discourse.processing.org/u/Vodin)\
**Post date:** [November 23, 2023, 4:27pm UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/6 "2023-11-23T16:27:59Z")

</div>

If I understand correctly the previous java version was 17.0.8.0. What should I do with the new file?

---

<div class="post-metadata">

**Author:** ![Vodin](https://avatars.discourse-cdn.com/v4/letter/v/74df32/32.png) [@Vodin](https://discourse.processing.org/u/Vodin)\
**Post date:** [November 23, 2023, 4:33pm UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/7 "2023-11-23T16:33:05Z")

</div>

I read something about it. But it wouldn’t help me

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [November 23, 2023, 6:22pm UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/8 "2023-11-23T18:22:02Z")

</div>

In order to make a call ‘work’ you usually have to have it installed on your system (or a URL to some web source). I don’t understand why you don’t already have the requisite files. What operating system are you using?

Something you can try:

1. Instead of supplying a ‘frame’ for the dialog try making it _null_ and see if it will run. For example:

> JOptionPane.showInputDialog(null,…)

1. You are still going to need Swing for the JOptionPane, so I think you are going to have to have the files installed on your system either way. You can’t use them if they are not installed. Search the web for installation technique if you don’t know how to do it. For whatever it’s worth I’m using _openjdk 20.0.1_

May be helpful: [https://openjdk.org/install/](https://openjdk.org/install/)

---

<div class="post-metadata">

**Author:** ![Vodin](https://avatars.discourse-cdn.com/v4/letter/v/74df32/32.png) [@Vodin](https://discourse.processing.org/u/Vodin)\
**Post date:** [November 24, 2023, 9:17am UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/9 "2023-11-24T09:17:48Z")

</div>

I just recently bought a laptop and started studying electronics. so even basic things are difficult for me

---

<div class="post-metadata">

**Author:** ![Vodin](https://avatars.discourse-cdn.com/v4/letter/v/74df32/32.png) [@Vodin](https://discourse.processing.org/u/Vodin)\
**Post date:** [November 24, 2023, 9:23am UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/10 "2023-11-24T09:23:40Z")

</div>

I’m already downloaded it. But don’t know, where should I put this file.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [November 24, 2023, 2:18pm UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/11 "2023-11-24T14:18:06Z")

</div>

Go to [https://openjdk.org/install/](https://openjdk.org/install/) and see if you can find your operating system listed there, then do what it says.

---

<div class="post-metadata">

**Author:** ![Vodin](https://avatars.discourse-cdn.com/v4/letter/v/74df32/32.png) [@Vodin](https://discourse.processing.org/u/Vodin)\
**Post date:** [November 24, 2023, 5:18pm UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/12 "2023-11-24T17:18:46Z")

</div>

The first one was right. You just a god for me. In gratitude, I would like to send you a parcel of sweets from my country. Although it will take a lot of time to figure it all out. But I would still like to thank you somehow. I hope you can understand all of my messages, I’m not a native English speaker

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [November 24, 2023, 5:39pm UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/13 "2023-11-24T17:39:51Z")

</div>

Your gratitude is enough reward for me. It was my pleasure to try and help you. I wish you the best in your future programming endeavors.

---

<div class="post-metadata">

**Author:** ![Vodin](https://avatars.discourse-cdn.com/v4/letter/v/74df32/32.png) [@Vodin](https://discourse.processing.org/u/Vodin)\
**Post date:** [December 3, 2023, 4:20pm UTC](https://discourse.processing.org/t/a-problem-with-variables-or-libraries/43281/14 "2023-12-03T16:20:43Z")

</div>

Don’t think that I forgot about you
