Retrieve Data from user in java
getText
and SetText Method
getText() :-
This method is used to retrieve (or receive) the text of a component like Text Feild at run time
This method is used to retrieve (or receive) the text of a component like Text Feild at run time
e.g :
name.getText();
setText:-
This method is used to change the display text of a component like label, text field or button at run time
This method is used to change the display text of a component like label, text field or button at run time
e.g nn.setText(""+name);
Message
Pop-Ups : JOptionPane Dialog
if you just
want to show a JOptionPane dialog with a simple text message, all you need is
one line of Java source code, like this:
JOptionPane.showMessageDialog(frame,
"A basic JOptionPane message dialog"
examples
Starting with a
simple example, if you just want to show a JOptionPane dialog with a simple
text message, all you need is one line of Java source code, like this:
JOptionPane.showMessageDialog(frame,
"A basic JOptionPane message dialog");
When this line of
code is executed it will display the following message dialog:
In
that example my first argument to the
JOptionPane showMessageDialog method is a frame object,
which presumably is an instance of a JFrame. If for some reason you don't
have a reference to JFrame or JWindow instance, you can
make that field null, and still display the
identical JOptionPane dialog, as shown in this example:
JOptionPane.showMessageDialog(null,
"A basic JOptionPane message dialog");
Note
that when you supply a null argument like that, the JOptionPane dialog will be
centered on the user’s screen. When you supply a JFramereference, the
dialog is centered on that JFrame, so this behavior can be slightly
different.
Note:
don’t forget to include import
javax.swing.JOptionPane;
Parse Method in java
This method is used to get
the primitive data type of a certain String. parseXxx() is a static method and
can have one argument or two.
Example
public class StringToIntExample{
public static void main(String args[]){
String s="200";
int i=Integer.parseInt(s);
System.out.println(s+100);
//200100 because + is string concatenation operator
//200100 because + is string concatenation operator
System.out.println(i+100);
//300 because + is binary plus operator
//300 because + is binary plus operator
}}
Output
200100
300
Comments
Post a Comment