A problem with variables or libraries

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]);

    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;
}

  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)ā€);

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.

What do you see when you type java --version into your Terminal utility (Mac)? OpenJDK may be downloaded from here: https://openjdk.org if you donā€™t have it.

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

I read something about it. But it wouldnā€™t help me

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/

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

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

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

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

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.

1 Like

Donā€™t think that I forgot about you