How To Pass the Input string in the JTextField to JLabel using Java

In this first article I made in java, we are going to create a program that enables you to pass the input from the textfield to label using java programming. The main content of the program is to greet you, by entering your name.

I used the Netbeans IDE for this article demonstration, Let’s begin.

Step 1:
First, create a New Project , In the Categories option, select Java then Java Application and Click Next. Put the name of your Project, Location, Folder Location and check the Create Main Class.

Step 2:
Add 1 JTextFIeld, 2 JButton and 1 JLabel


To clear the value of TextField, Right click the textfield and select Edit Text then Clear it. After that right click again and Change Variable Name to tfName.

Change Variable Name: JTextField – tfName
JButton1 – bGreet, JButton2 – bClear, JLabel – lMessage


Step 3:
Copy the Code:

private void bGreetActionPerformed(java.awt.event.ActionEvent evt) {
String message = "Hello, " + tfName.getText();
lMessage.setText(message);
}
private void bClearActionPerformed(java.awt.event.ActionEvent evt) {
tfName.setText(null);
lMessage.setText("");
}


Final Output:

How To Pass the Input string in the JTextField to JLabel using Java How To Pass the Input string in the JTextField to JLabel using Java Reviewed by code-dev on 11:01 AM Rating: 5

No comments:

Powered by Blogger.