Learn How To Make A Java Program To Accept A String And Display The String In Dialog Box Using Netbeans IDE
In the previous Java tutorials we learn to make some static Java applications in NetBeans IDE, In which we already coded what should be the output and on clicking of the Button we just showed the same and same message, In this tutorial we’ll teach you How to make a Java application to accept a string from the user and to display dynamic output.
To make this application you must know to create a jFrame and a Java Application. If you don’t know then you can visit this link in which I have explained step-by-step – How to start programming in Java, make a jFrame and designing the frame. Let’s begin the tutorial, Follow the steps given below.
I assume that you’ve already added a frame to your Application.
- Drag the label from the palette in the IDE. Change the name of the label to “Enter name”, Drag the Text field from the palette, empty it and place it next to the label and drag a Button from the palette, See How I’ve placed in the Image below.
If you finish the above step then designing part of the application is over, Now double click on the button and write a code given below
String name = jTextField1.getText();
JOptionPane.showMessageDialog(null,”Hello “ + name);
If you don’t get any errors then you’ve successfully coded the application,
You don’t end up just by designing and coding the application. The last part is testing whether your application is working or not. Press SHIFT+F6 key combination to run your application and click on the button and check for the output. You’ve made your First dynamic Java Application using NetBeans IDE.