I assume that you know how to create a Java Application and add a frame to your application, If not then don’t worry you can navigate to the self explanatory post where I’ve already taught How to Create a Java Application and add a frame to it.
After you finish adding a Frame to your Application, Follow the steps I say to complete the purpose for what you are here.
- Drag the button from the Palette located at the right side of the IDE to the desired position, after dragging rename the Button to the desired name. The design of the frame will look similar to the below image.
- Double click the button the source window will appear in which you will have to write the code for action which should take place on clicking the button. The source code area of the button will be looking like the below showed Image when you double click on it.
JOptionPane.showMessageDialog(null,“Welcome to the world of Java”);
After writing this you will see that the IDE will show a bulb like thing on the lines where you’ve written the code, don’t get worried if you see this.
Just click on the bulb you will see many options coming in it but you should click on add import for javax.swing.JOptionPaneafter importing you will see that the bulb will go away and the source window will look like this
- The tutorial doesn’t end’s here, Run the application by the shortcut keys SHIFT + F6 and Frame will appear, It will look similar to the window shown below
And on clicking the button and you will see that a Dialog box will appear which will show the message “Welcome to the World of Java”See here is the output
Doesn’t it look awesome just writing one line of code to display the Dialog box with the desired text?
Here ends the tutorial but still now you aren’t free, I’ll give you some tasks to complete, Display “Techfiest a technology blog” in place of the above text in a Dialog Box.
If you have any problem related to this post or any other problem related to Java then Post it out.
Article publié pour la première fois le 06/10/2013