'Incompatible Types JOptionPane java string to png
Well, I have a little problem here, I want to add an image to a JOptionPane but I can't because I am converting it as a string! I don't know how to solve it! Help! This is the code:
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
public class TextBox {
ImageIcon icon0 = new ImageIcon("Picture2_2.png");
String user_input = JOptionPane.showInputDialog(null, "Please enter a card number!", "¡Tu puedes!", JOptionPane.INFORMATION_MESSAGE,icon0,null,"");
public static void main (String [] args)
{
int g = -1;
while (g<0)
{
TextBox n = new TextBox();
if(n.user_input.length() > 0 )
{
numbersreader t= new numbersreader();
t.checkLuhn (n.user_input);
g++;
}else
{
ImageIcon icon1 = new ImageIcon("Picture2_2.png");
JOptionPane.showInputDialog(null, "Please enter a card number!", "¡Ya valio!", JOptionPane.INFORMATION_MESSAGE,icon1, null, "");
}
}
}
}
If it wasn't for this the code does work, a version of the code that works is down below but I really want to put that picture in that JOptionPane, there is got to be a way to!
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
public class TextBox {
String user_input = JOptionPane.showInputDialog(null, "Please enter a card number!", "¡Tu puedes!", JOptionPane.INFORMATION_MESSAGE);
public static void main (String [] args)
{
int g = -1;
while (g<0)
{
TextBox n = new TextBox();
if(n.user_input.length() > 0 )
{
numbersreader t= new numbersreader();
t.checkLuhn (n.user_input);
g++;
}else
{
ImageIcon icon1 = new ImageIcon("Picture2_2.png");
JOptionPane.showInputDialog(null, "Please enter a card number!", "¡Ya valio!", JOptionPane.INFORMATION_MESSAGE,icon1, null, "");
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
