Results 1 to 7 of 7
Thread: Help with JOptionPane
- 11-13-2010, 09:37 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
Help with JOptionPane
I am writing a GUI program to calculate sales tax. I am trying to make it more robust by making it catch an exception of the user enters somthing other than a double. I try to compile this code, but it tells me that on the lines where "JOptionPane" appears, that the compiler cannot find the symbol. Help? Thanks.
Java Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.text.DecimalFormat; class TaxGUI extends JFrame { private JLabel billLabel = new JLabel("Bill"); private JLabel totalLabel = new JLabel("Bill + tax"); private JTextField billField = new JTextField("$00.0"); private JTextField totalField = new JTextField("$00.0"); private JButton taxButton = new JButton(">>>>>"); public TaxGUI() { JPanel dataPanel = new JPanel(new GridLayout(2,2,20,10)); dataPanel.add(billLabel); dataPanel.add(billField); dataPanel.add(totalLabel); dataPanel.add(totalField); JPanel buttonPanel = new JPanel(); buttonPanel.add(taxButton); Container container = getContentPane(); container.add(dataPanel, BorderLayout.NORTH); container.add(buttonPanel, BorderLayout.SOUTH); taxButton.addActionListener(new TaxListener()); } private class TaxListener implements ActionListener { public void actionPerformed(ActionEvent e) { double bill = 0; while(true) { try { String input = billField.getText(); bill = Double.parseDouble(input); break; } catch(Exception ex) { JOptionPane.showMessageDialog("You need to enter a number!", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.setVisisble(true); String input = billField.getText(); bill = Double.parseDouble(input); } } bill = bill + (bill * .05); bill = roundTwoDecimals(bill); totalField.setText("$" + bill); } } private double roundTwoDecimals(double d) { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(d)); } }
- 11-13-2010, 09:49 PM #2
Member
- Join Date
- Oct 2010
- Posts
- 94
- Rep Power
- 0
Have a close look at the signature of the three overloaded showMessageDialog methods of JOptionPane at JOptionPane. Yours does not match.
I'm new to Java but I like to help where ever I can. :)
- 11-13-2010, 10:10 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
Thanks! I got it!
- 11-13-2010, 10:20 PM #4
Member
- Join Date
- Oct 2010
- Posts
- 94
- Rep Power
- 0
You're welcome.
I'm new to Java but I like to help where ever I can. :)
- 11-13-2010, 10:29 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
Another question though, is there a way to make a JFrame visible in a location other than the top left corner of the screen?
- 11-13-2010, 10:36 PM #6
Member
- Join Date
- Oct 2010
- Posts
- 94
- Rep Power
- 0
Nope, all frames must stick to to the top left corner... ;)
No, seriously, it is possible of course. Have a look here: How to Make FramesI'm new to Java but I like to help where ever I can. :)
- 11-13-2010, 10:40 PM #7
Member
- Join Date
- Sep 2010
- Posts
- 56
- Rep Power
- 0
Similar Threads
-
JOptionPane
By hfbroady in forum AWT / SwingReplies: 3Last Post: 11-12-2010, 11:07 AM -
JOptionPane
By izzy in forum New To JavaReplies: 1Last Post: 03-17-2010, 04:55 PM -
Help with JOptionPane
By sanctishit in forum New To JavaReplies: 1Last Post: 03-10-2010, 10:20 AM -
need help with a JOptionPane
By dr4g0nk1ng in forum Advanced JavaReplies: 2Last Post: 02-19-2010, 09:40 PM -
JOptionPane
By whosadork in forum New To JavaReplies: 2Last Post: 10-23-2008, 02:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks