Java Swing Hello World example

The below program launch a Java Swing application; It configures a JFrame and attach a JLabel to display a hello world and center the JLabel component. Read the comment for self-explanatory. SwingHelloWorld.java package com.mkyong.swing import javax.swing.*; import java.awt.*; public class SwingHelloWorld { public static void main(String[] args) { JFrame frame = new JFrame("Hello World Java …

Read more

Java Swing – JOptionPane showOptionDialog example

The showOptionDialog method of JOptionPane is the Grand Unification of showConfirmDialog, showInputDialog and showMessageDialog. The showOptionDialog returns an integer which represents the position of the user’s choice in the Object[]. Note If you want to read more about the different showXxxDialog methods, refer to Java Swing – JOptionPane showConfirmDialog example Java Swing – JOptionPane showInputDialog …

Read more

Java Swing – JOptionPane showConfirmDialog example

This is a review of the showConfirmDialog() method of JOptionPane Class. This method is a quick and easy way to get user input by asking a confirming question, like yes/no/cancel . The showConfirmDialog() can be called using the following combinations of parameters: Component, Object Component, Object, String, int Component, Object, String, int, int Component, Object, …

Read more

Java Swing – JOptionPane showMessageDialog example

This is a review of the showMessageDialog() method of JOptionPane Class. This method is a quick and easy way to tell the user about something that has happened . The showMessageDialog() can be called using the following combinations of parameters: Component, Object Component, Object, String, int Component, Object, String, int, Icon Component – The first …

Read more

Java Swing – JOptionPane showInputDialog example

This is a review of the showInputDialog() method of JOptionPane Class. With this method we can prompt the user for input while customizing our dialog window. The showConfirmDialog returns either String or Object and can be called using the following combinations of parameters: Object (returns String) – Shows a question-message dialog requesting input from the …

Read more

Java Swing – JFileChooser example

JFileChooser is a quick and easy way to prompt the user to choose a file or a file saving location. Below are some simple examples of how to use this class. JFileChooser has 6 constructors: JFileChooser() – empty constructor that points to user’s default directory JFileChooser(String) – uses the given path JFileChooser(File) – uses the …

Read more

Java AWT – Drawing rectangle, line and circle

The java.awt libraries are set of classes provided by Java in order to draw shapes on a window. The abbreviation AWT stands for Abstract Windowing Toolkit. Today, the library has been converted into a huge set of classes which allows the user to create an entire GUI based application. The visual appearance of these classes …

Read more