Been trying to change my code all around to catch the exceptions but can't figure out how to go about it with this one. I run into double instantiation of the JOptionPane from time to time too depending on where I put it.
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class JCalculateWeight extends JFrame {
Font font = new Font("Arial", Font.BOLD, 14);
JFrame frame;
String name = JOptionPane.showInputDialog(frame, "What's your name?");
String weight = JOptionPane.showInputDialog(frame, "What's your weight (lbs)");
@Override
public void paint(Graphics brush) {
super.paint(brush);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
double lbs = Double.parseDouble(weight);
double oz = lbs * 16;
double kilo = lbs / 2.204623;
double metricton = lbs / 2204.623;
brush.setFont(font);
brush.drawString(name, 55, 50);
brush.drawString(String.valueOf(lbs), 55, 150);
brush.drawString(String.valueOf(oz), 55, 170);
brush.drawString(String.valueOf(kilo), 55, 190);
brush.drawString(String.valueOf(metricton), 55, 210);
}
public static void main(String[] args) {
JCalculateWeight frame = new JCalculateWeight();
frame.setSize(500, 450);
frame.setVisible(true);
}
}