showMessageDialog() function gives an error

hello very new to processing, this code is from the book Processing: An Introduction to Programming

when I use showMessageDialog after using JOptionPane i get an error saying "frame cannot be resolved to a variable"

import static javax.swing.JOptionPane.*;
String input;
input=showInputDialog("Enter an integer to be squared: ");

int integer;
integer = int(input);

int square;
square = integer*integer;

showMessageDialog(frame,integer+" squared is " + square);


Here is a working example that replaced frame with null:

Adding this to your code will also work:

    import javax.swing.JFrame;
    JFrame frame = new JFrame("JOptionPane showMessageDialog example");

Insight gleaned from here:
Java: JOptionPane showMessageDialog examples (part 1) |


1 Like

Thank you glv, hopefully one day I’ll understand WHY that worked, lol, baby steps!

Hopefully you also checked that input != null just in case someone hits the ‘Cancel’ button and a null pointer exception is raised.