0

Hi everybody,

I was wondering if it is possible (and if it is, how to do it) to put a JPasswordField into a JOptionPane.

Thanks in advanced,
C++

2
Contributors
10
Replies
11
Views
11 Years
Discussion Span
Last Post by server_crash
0

can you please explain how to use JDialog???

Thanx in advanced,
C++

0

Here is an example, but remember this is just an inner class.

class processCylinderDialog extends JDialog implements ActionListener
 {
	 JLabel lblRadius;
	 JLabel lblHeight;
	 JTextField txtRadius;
	 JTextField txtHeight;
	 JButton btnDone;
	 
	 JDialog dlg;
	 
	 public processCylinderDialog()
	 {
		
		 JPanel panelOne = new JPanel();
		 lblRadius = new JLabel("Radius");
		 txtRadius = new JTextField(10);
		 panelOne.add(lblRadius);
		 panelOne.add(txtRadius);
	
		 JPanel panelTwo = new JPanel();
		 lblHeight = new JLabel("Height");
		 txtHeight = new JTextField(10);
		 panelOne.add(lblHeight);
		 panelOne.add(txtHeight);
		
		JPanel panelThree = new JPanel();
		btnDone = new JButton("Calculate");
		btnDone.addActionListener(this);
		panelThree.add(btnDone);
		
		 
		 dlg = new JDialog();
		 dlg.setResizable(false);
		 dlg.getContentPane().add(panelOne);
		 dlg.getContentPane().add(panelTwo);
		 dlg.getContentPane().add(panelThree);
		 dlg.setTitle("Cylinder Volume");
		 dlg.getContentPane().setLayout(new FlowLayout());
		 dlg.setSize(350,300);
		 dlg.setVisible(true);
	 }
	 
	 public void actionPerformed(ActionEvent ae)
	 {
		 getInfo();
	 }
	 public void getInfo()
	 {
		 if (txtRadius.getText() != null && txtHeight.getText() != null)
		 {
	   try
	   {
		 double cylRadius = Double.parseDouble(txtRadius.getText());
		 double cylHeight = Double.parseDouble(txtHeight.getText());
		 double cylVolume = Math.PI * cylRadius * cylRadius * cylHeight;
		 txtResult.setText(dec.format(cylVolume) + "");
	   }
	   catch(NumberFormatException nfe)
	   {
	   }
	}
}

You can see that it is just like creating a class that extends JFarme with a few modifications.

When you want to display this dialog, you call it like this:

new className();
0

Thank you very much, server_crash!!!

Your very welcome, and if you need any further help just let me know, or Pm me.

0

Actually, that didn't work!!

Is there any other way (Preferably in JOptionPane)?

0

regard previous message - i forgot to put in:

new className();
0

Why don't you post your code, preferably all of it, but most importantly the JDialog inner class and where you call it.

0

thanx - but the code's working now. I have one more question:

Is there a way to figure out which character is most common in a string?

0

Here's a common example:

static int countChars( String str, char searchChar ) {
                  // Count the number of times searchChar occurs in
                  // str and return the result.
                int i;     // A position in the string, str.
                char ch;   // A character in the string.
                int count; // Number of times searchChar has been found in str.
                count = 0;
                for ( i = 0;  i < str.length();  i++ ) {
                    ch = str.charAt(i);  // Get the i-th character in str.
                    if ( ch == searchChar )
                       count++;
                }
                return count;
            }
This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.