Taking a user input using a console (a user might enter an invalid input such as a number out of Range or a string containing non-digit characters):Taking a user input using Applet (a user is forced to choose among 0 through 7):
Making a Java program to generate a GUI is accomplished by using pre-defined classesin packages such as javax.swing and java.awt.Swing is a comprehensive solution to developing graphical use interfaces.There are more than 250 classes.
GUI Class Hierarchy (Swing)Dimension Font FontMetrics Component Graphics Object Color Container Panel Applet Frame Dialog Window JComponent JApplet JFrame JDialog Swing Components in the javax.swing package Lightweight Heavyweight Classes in the java.awt package 1 LayoutManager*
JFrame, JApplet, and JDialog are heavy weightcontainerclasses that can be displayed alone andare used to contain other components.JFrame: the container that holds other Swing user-interface components in Java Graphical applications.It can be used in a Java program with a main method (Applications).JApplet: It is a subclass of the Applet class. Applet is defined in java.applet package and JApplet is defined in javax.swing package. You need to create a class that extendsJApplet to create a Swing based Java applet. Such class will not contain a main method. Instead it contains applet purpose methods such as init(), start(), stop(), and destroy(). Theapplet will be displayed with a html file or appletviewer.JDialog/JOptionPane: a popup window or message box generally used as a temporary window to receive information from a user or provide notification that an event has occurred.