•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 401,688 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,704 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 9812 | Replies: 3
![]() |
•
•
Join Date: Jul 2005
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Hiya, I am using following Java file which creates a GUI, in the input field if i put any character why dont I see the JOptionPane.showMessageDialog pop up window as mentioned in the code?
Any clues?
Thx
Rony
//import statements
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.DecimalFormat;
/**
* Sediment Yield MUSLE
* Shahriar Shams
* class description
*/
public class SedimentYield1 extends JFrame implements ActionListener
{
double V, Qp, K, LS, C, P;
String outputSY;
boolean goodInput = true;
double SY;
JPanel SYPanelInput = new JPanel();
JPanel SYPanelCentre = new JPanel();
JPanel SYPanelOutput = new JPanel();
private JButton jbtCalculate = new JButton ("Calculate");
private JButton jbtClear = new JButton ("Clear");
//Input
JLabel Vlbl = new JLabel("Volume of Runoff in acre-ft, V");
JTextField Vtf = new JTextField(8);
JLabel Qplbl = new JLabel("Peak Flow per Storm Event in cfs, Qp");
JTextField Qptf = new JTextField(8);
JLabel Klbl = new JLabel("Soil Erodibility Factor, K");
JTextField Ktf = new JTextField(8);
JLabel LSlbl = new JLabel("Soil Loss Ratio, LS");
JTextField LStf = new JTextField(8);
JLabel Clbl = new JLabel("Cropping Factor, C");
JTextField Ctf = new JTextField(8);
JLabel Plbl = new JLabel("Practice Factor, P");
JTextField Ptf = new JTextField(8);
//ouput
JLabel SYlbl = new JLabel("Sediment Yield per storm in tons");
JTextField SYtf = new JTextField("Will be computed");
public SedimentYield1()
{
SYPanelInput.setLayout(new GridLayout(6,2));
SYPanelInput.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
SYPanelCentre.setLayout(new GridLayout(1,2));
SYPanelCentre.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
SYPanelOutput.setLayout(new GridLayout(1,2));
SYPanelOutput.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
//adding Components
SYPanelInput.add(Vlbl);
SYPanelInput.add(Vtf);
SYPanelInput.add(Qplbl);
SYPanelInput.add(Qptf);
SYPanelInput.add(Klbl);
SYPanelInput.add(Ktf);
SYPanelInput.add(LSlbl);
SYPanelInput.add(LStf);
SYPanelInput.add(Clbl);
SYPanelInput.add(Ctf);
SYPanelInput.add(Plbl);
SYPanelInput.add(Ptf);
//output added
SYPanelCentre.add(SYlbl);
SYPanelCentre.add(SYtf);
// adding buttons
SYPanelOutput.add(jbtCalculate);
jbtCalculate.addActionListener(this);
SYPanelOutput.add(jbtClear);
jbtClear.addActionListener(this);
String strV = Vtf.getText();
String strQp = Qptf.getText();
String strK = Ktf.getText();
String strLS = LStf.getText();
String strC = Ctf.getText();
String strP = Ptf.getText();
try
{
V = Double.parseDouble(strV);
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}
try
{
Qp = Double.parseDouble(strQp);
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}
try
{
K = Double.parseDouble(strK);
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}
try
{
LS = Double.parseDouble(strLS);
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}
try
{
C = Double.parseDouble(strC);
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}
try
{
P = Double.parseDouble(strP);
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}
if (goodInput)
{
//Calculating Sediment Yield
SY = 95.0*(Math.pow((V*Qp),0.56))*K*LS*C*P;
//Create the format for the Celsius text field.
DecimalFormat twoDigits = new DecimalFormat("0.00");
outputSY = twoDigits.format(SY);
}
// JFrame.setDefaultLookAndFeelDecorated(true);
//2. Create the frame.
JFrame frame = new JFrame("Sedidement Yield from Watershed");
//3. Optional: What happens when the frame closes?
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//4. Create components and put them in the frame.
//...create emptyLabel...
frame.getContentPane().add(SYPanelInput, BorderLayout.NORTH);
frame.getContentPane().add(SYPanelCentre, BorderLayout.CENTER);
frame.getContentPane().add(SYPanelOutput, BorderLayout.SOUTH);
//5. Size the frame.
frame.setSize(new Dimension(500,280));
//6. Show it.
frame.setVisible(true);
}
public static void main(String[] args) {
SedimentYield SYframe = new SedimentYield();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()== jbtClear)
{
Vtf.setText("");
Qptf.setText("");
Ktf.setText("");
LStf.setText("");
Ctf.setText("");
Ptf.setText("");
SYtf.setText("Will be calculated");
}
if (e.getSource()== jbtCalculate)
{
System.out.println("Sediment Yield ="+outputSY);
SYtf.setText(outputSY);
}
}
}
Any clues?
Thx
Rony
//import statements
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.DecimalFormat;
/**
* Sediment Yield MUSLE
* Shahriar Shams
* class description
*/
public class SedimentYield1 extends JFrame implements ActionListener
{
double V, Qp, K, LS, C, P;
String outputSY;
boolean goodInput = true;
double SY;
JPanel SYPanelInput = new JPanel();
JPanel SYPanelCentre = new JPanel();
JPanel SYPanelOutput = new JPanel();
private JButton jbtCalculate = new JButton ("Calculate");
private JButton jbtClear = new JButton ("Clear");
//Input
JLabel Vlbl = new JLabel("Volume of Runoff in acre-ft, V");
JTextField Vtf = new JTextField(8);
JLabel Qplbl = new JLabel("Peak Flow per Storm Event in cfs, Qp");
JTextField Qptf = new JTextField(8);
JLabel Klbl = new JLabel("Soil Erodibility Factor, K");
JTextField Ktf = new JTextField(8);
JLabel LSlbl = new JLabel("Soil Loss Ratio, LS");
JTextField LStf = new JTextField(8);
JLabel Clbl = new JLabel("Cropping Factor, C");
JTextField Ctf = new JTextField(8);
JLabel Plbl = new JLabel("Practice Factor, P");
JTextField Ptf = new JTextField(8);
//ouput
JLabel SYlbl = new JLabel("Sediment Yield per storm in tons");
JTextField SYtf = new JTextField("Will be computed");
public SedimentYield1()
{
SYPanelInput.setLayout(new GridLayout(6,2));
SYPanelInput.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
SYPanelCentre.setLayout(new GridLayout(1,2));
SYPanelCentre.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
SYPanelOutput.setLayout(new GridLayout(1,2));
SYPanelOutput.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
//adding Components
SYPanelInput.add(Vlbl);
SYPanelInput.add(Vtf);
SYPanelInput.add(Qplbl);
SYPanelInput.add(Qptf);
SYPanelInput.add(Klbl);
SYPanelInput.add(Ktf);
SYPanelInput.add(LSlbl);
SYPanelInput.add(LStf);
SYPanelInput.add(Clbl);
SYPanelInput.add(Ctf);
SYPanelInput.add(Plbl);
SYPanelInput.add(Ptf);
//output added
SYPanelCentre.add(SYlbl);
SYPanelCentre.add(SYtf);
// adding buttons
SYPanelOutput.add(jbtCalculate);
jbtCalculate.addActionListener(this);
SYPanelOutput.add(jbtClear);
jbtClear.addActionListener(this);
String strV = Vtf.getText();
String strQp = Qptf.getText();
String strK = Ktf.getText();
String strLS = LStf.getText();
String strC = Ctf.getText();
String strP = Ptf.getText();
try
{
V = Double.parseDouble(strV);
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}
try
{
Qp = Double.parseDouble(strQp);
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}
try
{
K = Double.parseDouble(strK);
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}
try
{
LS = Double.parseDouble(strLS);
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}
try
{
C = Double.parseDouble(strC);
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}
try
{
P = Double.parseDouble(strP);
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}
if (goodInput)
{
//Calculating Sediment Yield
SY = 95.0*(Math.pow((V*Qp),0.56))*K*LS*C*P;
//Create the format for the Celsius text field.
DecimalFormat twoDigits = new DecimalFormat("0.00");
outputSY = twoDigits.format(SY);
}
// JFrame.setDefaultLookAndFeelDecorated(true);
//2. Create the frame.
JFrame frame = new JFrame("Sedidement Yield from Watershed");
//3. Optional: What happens when the frame closes?
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//4. Create components and put them in the frame.
//...create emptyLabel...
frame.getContentPane().add(SYPanelInput, BorderLayout.NORTH);
frame.getContentPane().add(SYPanelCentre, BorderLayout.CENTER);
frame.getContentPane().add(SYPanelOutput, BorderLayout.SOUTH);
//5. Size the frame.
frame.setSize(new Dimension(500,280));
//6. Show it.
frame.setVisible(true);
}
public static void main(String[] args) {
SedimentYield SYframe = new SedimentYield();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()== jbtClear)
{
Vtf.setText("");
Qptf.setText("");
Ktf.setText("");
LStf.setText("");
Ctf.setText("");
Ptf.setText("");
SYtf.setText("Will be calculated");
}
if (e.getSource()== jbtCalculate)
{
System.out.println("Sediment Yield ="+outputSY);
SYtf.setText(outputSY);
}
}
}
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,693
Reputation:
Rep Power: 18
Solved Threads: 195
I'm not going to read a thousand lines of unformated code.
Use code tags and post only the relevant bits.
Most likely you never attached the code that shows the message to the component where you want it shown.
Use code tags and post only the relevant bits.
Most likely you never attached the code that shows the message to the component where you want it shown.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
•
•
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation:
Rep Power: 9
Solved Threads: 18
•
•
Join Date: Jun 2004
Posts: 604
Reputation:
Rep Power: 6
Solved Threads: 6
Hi everyone,
It does not pop up because there was no exception thrown as you option pane only shows up if there are exceptions or errors much like your below code
I hope this helps you
Yours Sincerely
Richard West
It does not pop up because there was no exception thrown as you option pane only shows up if there are exceptions or errors much like your below code
try
{
//some code
}
catch (NumberFormatException nfeDouble)
{
JOptionPane.showMessageDialog(null, "You need to enter a\nnumber", "Input Error", JOptionPane.ERROR_MESSAGE);
goodInput = false;
}I hope this helps you
Yours Sincerely
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Java / GUI Developer Needed (UK) (Software Development Job Offers)
- GUI Help (Java)
- java gui libraries (Java)
- two Java GUI problems - please help (Java)
- a Java GUI based program using Swing classes, Vat (Java)
Other Threads in the Java Forum
- Previous Thread: Making a Java Key Logger
- Next Thread: Reading from a file to fill an array



Linear Mode