CUI vs GUI in Java Programming
CUI vs GUI in Java Programming
Event Handling- The Delegation event model- Events, Event sources, Event
Listeners, Event classes, Handling mouse and keyboard events, Adapter classes, Inner
classes, Anonymous Inner classes.
A Simple Swing Application, Applets – Applets and HTML, Security Issues, Applets
and Applications, passing parameters to applets. Creating a Swing Applet, Painting in
Swing, A Paint example, Exploring Swing Controls- JLabel and Image Icon, JText Field,
The Swing Buttons- JButton, JToggle Button, JCheck Box, JRadio Button, JTabbed
Pane, JScroll Pane, JList, JCombo Box, Swing Menus, Dialogs.
Any user interact with java program in two different way
•CUI (Command user Interface)
•GUI (Graphical user Interface)
CUI:If any user interact with java program by passing same commands through command
prompt is known as CUI,
GUI:The environment where the user can interact with an application through graphics or
images is called GUI
Advantages GUI:
It is user Friendly.The user Need not worry about any commands.
It adds attraction and beauty to any application by adding picture,colors,menus,animation.
It is possible to simulate the real life objects using GUI.
For Ex: a calculator program display real calculator on the Screen.
What is AWT?
AWT:
• AWT stands for Abstract Window Toolkit. It is a platform-dependent API to develop GUI
(Graphical User Interface) or window-based applications in Java. It was developed by heavily Sun
Microsystems In 1995.
• The java.awt package contains classes and interfaces to develop GUI so that users can interact
more friendly with the applications.
• The java.awt package contains component classes such as TextField, Label, TextArea,
RadioButton, CheckBox, Choice, List etc.
• AWT components are platform-dependent.
• For example an AWT GUI having a button would have a different look and feel across platforms
like windows, Mac OS & Unix
• AWT components are heavy weight .
Note:
Every AWT component depends on the files of local OS to create GUI.This increases the overhead on
the JVM this is the reason AWT components are heavy weight.
Limitations of AWT:Dis-advantages
3. The AWT programs increase the overhead on the JVM.Because They depend on files of local
operating system in creating GUI.
5. tables and trees these important components are missing. They are commonly used in
desktop applications.
What is Swing?
Swing is the part of JFC (Java Foundation Classes) built on the top of AWT and
written entirely in Java.
Swing is an API for Java programs that provide GUI. It is used to create window-based applications.
The javax.swing package provides all the component classes like JButton,
JTextField, JCheckbox, Jmenu and JRadiobutton.
• Swing provides platform-independent and lightweight components.
• Swing offers much-improved functionality over AWT, new components,
expanded components features, and excellent event handling with drag-and-
drop support.
Light Weight: Swing components are lightweight. The swing components are completely
developed using java code.
Rich Controls: Swing provides a rich set of advanced controls like Tree, TabbedPane, slider,
colorpicker, and table controls.
Highly Customizable: Swing controls can be customized in a very easy way as visual apperance is
independent of internal representation.
Pluggable look-and feel: Swing based GUI Application look and feel can be changed at run time
based on available values.
Swing Class Hirarchy
Difference Between AWT and SWING
Swing classes :
Object: All classes in Java are inherited from the object class.
Component:A component is an object having a Graphical Representation That can be displayed
on the Screen.
Example of components:Buttons,Labels,CheckBoxes TextFields, RadioButtons, etc. are called
components in Java.
Container:The Container is a component in AWT that can contain other components.A container
is like a screen where in we are placing components like buttons, text fields, checkbox etc.
Ex: Jframe and JPanel.
Swing Components:
JLabel: It inherits JComponent class. It is used for placing text in a container.
JButton: It is used to create a labelled button. It is useful to perform some action when the
button is clicked. It inherits the AbstractButton class and is platform-independent.
JTextField: It inherits the JTextComponent class where the user can type single line of text
JTextArea: It inherits the JTextComponent class where user can enter multiple lines of text.
JList: It inherits JComponent class, the JList represents the user a list of text items.
JScrollBar: It is used to add scroll bar, both horizontal and vertical.
JComboBox Class: It inherits the JComponent class and is used to select a value from a drop-
down list. You can choose one and only one element from the list.
JCheckbox: JCheckBox is used to create a checkbox, of which multiple checkboxes could be
selected at the same time
The user can select one or more options from a group of checkboxes.
JRadioButton: RadioButton is used to select one option from multiple Options. Only one
RadioButton selected at a time.
JSlider
JSlider is a component that lets the users select a value by sliding a knob within a specified
interval.
JTable
JTable is used to create a regular two-dimensional table. The table can display data inside of it.
In addition, the user can also edit the data.
JMenu Class: It inherits the JMenuItem class, and is a pull down menu component which is
displayed from the menu bar.
Ex:
We have a File menu, which includes of save, quit submenu, and Edit menu, including copy, cut,
paste submenu, and Help menu
JPasswordField : A JPasswordField object it is a text component specialized for password entry
Commonly used Methods of Component class
The methods of Component class are widely used in java swing that are given below.
Method Description
Syntax:
c.add(“cardname” ,component);
To retrieve the components one by one the following methods can be used.
3.fill: fill is useful to resize the component according to the space available in the display area.
4. ipadx and ipady: are useful to leave space horizontally and vertically
Model-View-Controller (MVC) architecture
The Model-View-Controller (MVC) is a design pattern in web application development. It is a
way to organize our code. The application logic is separated from the user interface while
designing the software using model designs.
Swing uses the Model-view-Controller architecture (MVC) as the fundamental design behind
each of its components.
MVC represents the separation of the model of an object from its view and how it is controlled.
The MVC pattern architecture consists of three layers:
Model: The Model represents the data of the component.
View: The look (the visual appearance) of the component.
Controller: The Controller takes the input from the user on the view and reflects the changes in
the Component’s data. It acts as an interface between the model and view.
The controller determines how the component reacts to the user.
MVC Architecture:
Advantages of MVC Architecture
•The components are easy to maintain because there is less dependency.
•A model can be reused by multiple views that provides reusability of code.
•The developers can work with the three layers (Model, View, and Controller)
simultaneously.
•Using MVC, the application becomes more understandable.
•Using MVC, each layer is maintained separately therefore we do not require
to deal with massive code.
•The extending and testing of application is easier.
EventDelegationModel
• The modern approach to handling events is based on the Event Delegation Model, which
defines standard and consistent mechanisms to generate and process events.
• when an event is generated by the user on the component,the event is not handled by the
component.
• The Component sends (delegates) that event to the listener attached to it.The Listener will
not handle the event.It hands over (delegates) the event to an appropriate method.
• Finally the method is executed and the event is handled.This is called event delegation
model.
There are three participants in event delegation model in Java,
Events: Event is an object that is generated when end user interacts with components,such as
clicking a button, entering a character on the keyboard and Mouse click etc.
Ex: ActionEvent ,MouseEvent
Events Sources:Event source is an object that generates an event.
Ex: JButton creates an Action Event
Events Listeners:A listener is an object that listens to an event. A listener gets notified when an
event occurs.
The events which are generated from the source are handled by the
listeners. Each and every listener represents interfaces that are responsible
for handling events.
What is Event
Event: Changing the state of an object is known as an event. When you click
on the Button the state change from uncliked to click.
Event is an action that is generated when user interacts with components, such as clicking a
button,pressing the keys on keyboard , Mouse click and selecting an item from the list, etc.
The java.awt.event package provides many event classes and Listener interfaces for event
handling.
We can classify the events in the following two categories:
1.Foreground Events
Foreground events are those events that require user interaction to generate. In order to
generate these foreground events, the user interacts with components in GUI. When a user
clicks on a button, moves the cursor, an event will be fired.
2. Background Events
Background events don't require any user interaction. These events automatically generate in
the background. OS failure, OS interrupts, operation completion, etc., are examples of
background events.
Event Sources
What is Event Source?
• A source is an object that generates an event. There are various sources like
buttons, checkboxes, list, menu-item, scrollbar, etc to generate events.
• A Source should provide event information to Listener.
• A source must register to a listener to receive notifications for a specific event. Each event
contains its registration method.
To perform Event Handling, we need to register the source with the listener.
Registering the Source With Listener
Different Classes provide different registration methods.
Syntax:
public void addTypeListener (TypeListener e1)
Type is the name of the event, and e1 is a reference to the event listener.
For ActionEvent we use addActionListener() to register.
Ex: public void addActionListener(ActionListener e1)
•Checkbox
• public void addItemListener(ItemListener a){}
•List
• public void addActionListener(ActionListener a){}
• public void addItemListener(ItemListener a){}
•Button
• public void addActionListener(ActionListener a){}
•MenuItem
• public void addActionListener(ActionListener a){}
•TextField
• public void addActionListener(ActionListener a){}
• public void addTextListener(TextListener a){}
•TextArea
• public void addTextListener(TextListener a){}
Event Classes:
Event classes are the classes that represent events
Event Object: At the root of the Java event class hierarchy is EventObject, which is in java.util. It
is the superclass of all events.
Methods:
1.Object getSource()
The object on which the Event initially occurred.
2.String toString()
returns a String representation of this EventObject.
1. Action Event: The ActionEvent is generated when the button is clicked or the item of a list is
double-clicked or a menu item is selected.
Ex: Button click,
The ActionListener interface is used for receiving the action events.
Methods:
1. getActionCommand()
returns the command string associated with this action.
2.getModifiers()
method returns a value that indicates which modifier keys were pressed when the event was
generated.
2.MouseEvent: MouseEvent is generated when a source such a mouse is moved,
dragged,clicked,pressed or released
Mouse Events are:Mouse_Clicked,Mouse_Dragged,Mouse_Pressed,Mouse_Released
Mouse_Entered,Mouse_Exited etc
Methods
1 int getButton()
This method returns a value representing a mouse button.when it is clicked it returns 1
if left button is clicked ,2 if middle button is clicked, and 3 if right button is clicked.
2.int getClickCount()
Returns the number of mouse clicks associated with this event.
3.The getX() and getY()
methods returns the x and y coordinates of the mouse within the component when the event
occurred.
3.ItemEvent: ItemEvent is generated when a source check-box or list item is clicked
There are two types of item events which are identified by two integer constants:
DESELECTED
The user deselected an item.
SELECTED
The user selected an item.
Methods:
1. The getItem() method returns a reference to the item that generated
an event.
2. The getItemSelectable() method returns a reference to the
ItemSelectable object that generated an event.
3.The getStateChange() method returns the state change(i.e, SELECTED
or DESELECTED) for an event:
4:KeyEvent: KeyEvent is generated when a source such as a key on the keyboard is
pressed,typed
These key events are following
•KEY_PRESSED
•KEY_RELASED
•KEY_TYPED
Methods:
1. getKeyChar()
returns the character associated with the key in this event.
2. getKeyCode()
returns the integer keyCode associated with the key in this event.
3. getKeyLocation()
returns the location of the key that originated this key event.
5:WindowEvent: Window Event generated when a source such as window is activated,
deactivated, opened or closed
Window Events:
WINDOW_ACTIVATED, WINDOW_CLOSED, WINDOW_ DEACTIVATED, WINDOW_DEICONIFIED,
WINDOW_ICONIFIED, WINDOW_OPENED
Methods:
1. getNewState()
For WINDOW_STATE_CHANGED events returns the new state of the window.
2: getOldState()
For WINDOW_STATE_CHANGED events returns the previous state of the window.
3. getWindow()
method returns the object that generated the event.
6.ContainerEvent: Container Event generated when the component is added or removed from
the container
Methods:
1. getContainer() method returns a reference to the container that generated the event.
7.FocusEvent: Focus Event generated when component gains or loses keyboard focus
FocusEvents are identified by integer constants FOCUS_GAINED and FOCUS_LOST.
1. ActionListener Interface: The ActionListener is notified whenever you click on the button or
menu item. It is notified against ActionEvent. It has only one method: actionPerformed().
actionPerformed() method
The actionPerformed() method is invoked automatically whenever you click on the registered
component.
Ex: public void actionPerformed(ActionEvent e)
{
//Write the code here
}
2.MouseListener Interface
MouseListener is notified when mouse is clicked ,pressed,entered and released. It is notified
against MouseEvents.
Mouse Events: mouse clicked ,mouse pressed,mouse entered ,mouse exited,and mouse
released.
Methods:
1.public abstract void mouseClicked(MouseEvent e);
Invoked when the mouse button has been clicked on a component.
2.public abstract void mouseEntered(MouseEvent e);
Invoked when the mouse enters a component.
3.public abstract void mouseExited(MouseEvent e);
Invoked when the mouse exits a component.
4.public abstract void mousePressed(MouseEvent e);
Invoked when a mouse button has been pressed on a component.
5.public abstract void mouseReleased(MouseEvent e);
3.WindowListener:WindowListener is notified whenever you change the state of window.
WindowListener methods:.
1.public abstract void windowActivated(WindowEvent e);
Invoked when the Window is set to be the active Window.
2. public abstract void windowClosed(WindowEvent e);
Invoked when the user attempts to close the window.
3. public abstract void windowDeactivated(WindowEvent e);
Invoked when a Window is no longer the active Window.
class InnerClass
}
ii. Local inner class
A class defined inside a method is called local inner class in java. Local Inner Classes are
the inner classes that are defined inside a block
If you want to invoke the methods of local inner class, you must instantiate this class inside the
method.
Rules:
Local Inner class cannot be accessed from outside method
We cannot create object of local inner class inside the main of the outerclass.
We should create object inside the function in which it is defined to invoke the
methods of local inner class
we can’t use private, public, or protected access modifiers with it. The only allowed modifiers
are abstract or final.
Syntax:
class outer
{
void method()
{
class inner
{
code;
}
} // method
} // outer
iii.Anonymous inner class
Anonymous inner class is an inner class with out a name and for which only a single object is
created. It should be used if you have to override a method of class or
interface.
java.applet.* imports the applet package, which contains the class Applet. Every applet that
you create must be a subclass of Applet class.
Advantages
4.public void destroy(): This method is called when the applet is being terminated from
memory.This method always be called before stop()
EX:The code related to releasing the Memory allocated to applet.
There are two standard ways in which you can run an applet :
Applets are executed by a program called applet engine which is similar to virtual machine
that exists inside the web browser at client side.
</applet>
Now you can click the HTML file to launch the applet in the browser.
Ex:
Step1 : create the applet program with name First.java
import java.applet.Applet;
import java.awt.Graphics;
public class First extends Applet{
MyApplet.java
import java.applet.applet;
import java.awt.*;
g.drawString("welcome II CSE-D",150,150);
} }
Step2: compile the MyApplet
Step3: create a html file with name myapplet.html and embedded java applet in html program
myapplet.html
<html>
</html>
D:\applet>appletViewer param.html
Step5 you will get the output:
•Creating a swing Applet
• We can create swing applet by extending JApplet class of swing package.
• It provides all the functionalities of the AWT applet as well as support for menubars
and layering of components.
• We have to import javax.swing package and import java.awt package
• JApplet that can have all the controls of swing. The JApplet class extends the Applet
class.
• Swing applets provides an easier to use user interface than AWT applets.
Syntax
class className extends JApplet
{
......
// override lifecycle methods
......
}
Note:
When we create an AWT applet, we implement the paint(Graphics g) method to draw in it but
when we create a Swing applet, we implement paintComponent(Graphics g) method to draw
Compile: D:/kiran>javac SwingApplet .java
D:/kiran>appletViewer swingapplet.html
Painting in Swing
Swing's approach to painting is built on the original AWT-based mechanism.
The class Component defines a method called paint() that is used to draw output directly to the
surface of a component.
When drawing on Swing component, an application will override paint().
Because JComponent inherits Component, all Swing's lightweight components inherit the paint()
method.
Swing's painting involves three distinct methods: paintComponent(), paintBorder(), and
paintChildren().
paintComponent() This is the method that paints the interior of the component.
paintBorder(): Paints the border for the specified component with the specified position and size.
paintChildren()Tells any components contained by this component to paint themselves.
When drawing to the surface of a component, you must be careful to restrict
your output to the area that is inside the border.
To obtain the border width, we use getInsets(), shown here:
Insets getInsets():This method is defined by Container and overridden
by JComponent.
It returns an Insets object that contains the dimensions of the border.
The inset values can be obtained by using these fields:
int top;
int bottom;
int left;
int right;
You can obtain the width and height of the component by calling getWidth() and getHeight() on
the component.
They are shown here:
int getWidth()
int getHeight()
Ex to illustrate Painting in Swing
SWING COMPONENTS
Exploring Swing Controls- JLabel and Image Icon, JText Field,JPasswordField
The Swing Buttons- JButton, JToggle Button, JCheck Box, JRadio Button, JTabbed
Pane, JScroll Pane, JList, JCombo Box, Swing Menus, Dialogs.
Exploring Swing Controls- JLabel and Image Icon, JText Field, JPasswordField
All the swing Controls are present in javax.swing package
1.JLabel:
JLabel class is a component for placing text in a container. It is used to display
a single line of read-only text.
A JLabel can display either text, an image, or both.
creating the JLabel or Constructors
Syntax:-
1.JLabel l=new JLabel();
This constructor is used to create an object of Jlabel with no image and an empty string value.
2.Jlabel l=new Jlabel(icon);
This constructor is used to create an object of Jlabel with an Image icon.
3. Jlabel jlb=new Jlabel(“Hello”);
This constructor is used to create an object of JLabel with specific text.
These are the commonly used methods of JLabel class.
1. getText() : This method is used to return the String of JLabel.
2.setText(String text): This method is used to set Text to the JLabel.
3. setIcon(Icon icon): This method is used to set the icon on the JLabel.
4.setBounds(int x,int y,int h,int w): This method is to set the position and size of the component
manually.
5.setFont(Font F): This method is used to set the Font of the JLabel.
6.setForeground(Color c): This method is set the Foreground Color of text on the JLabel.
5.addActionListener(ActionListener al): This method is used to adds the specific action listener
to receive action events from Text Field.
Ex to illustrate TextField and JLabel
import javax.swing.*;
class TextFieldEx
{
public static void main(String args[])
{
JFrame f= new JFrame("TextField");
JLabel lb = new JLabel(" Enter Your Name : ");
JTextField t1=new JTextField(20);
t1.setBounds(100,155, 150,30);
f.add(t1);
f.add(lb);
f.setSize(400,400);
f.setVisible(true);
}
3.ImageIcon
The class ImageIcon is an implementation of the Icon interface that paints Icons from Images.
To display images we have to use ImageIcon class.
syntax:
ImageIcon Icon = new ImageIcon(“C:\nature.jpg")
Image Icon methods
1. getImage() :Returns this icon's Image
2. getDescription():Gets the description of the image.
3. getIconHeight():Gets the height of the icon.
4. getIconWidth():Gets the width of the icon.
5. setImage(Image image):Sets the image displayed by this icon.
Ex to illustrate Image Icon
4.JPasswordField
• JPasswordField is a subclass of JTextField class. This JPasswordField class is used for inserting
passwords into the application.
• swing provides Jpasswordfield that takes user input in encrypted format.
Syntax:
JPasswordField pf=new JPasswordField();
It create a JPasswordField.
Method:
1.getPassword(): This method is used to return text of this component.
Swing Buttons
1.JButton: The JButton class can be used to perform some operations when the user clicks on it.
When the button is pushed, the application results in some action. It inherits the AbstractButton
class.
And we can apply different swing features like setting colors,font for the button and tooltip text
Syntax:-
1.JButton jb=new JButton();
It is used to create a button with no text and icon.
2.JButton jb=new JButton(“OK”);
It is used to creates a button with text.
3.JButton jb=new JButton(Icon);
It is used to create a button with the specified icon object.
Syntax:-
To create JTabbedPane
syntax:
JTabbedPane jtp=new JTabbedPane();
To add tab sheets to the JTabbedPane
Syntax:
jtp.addTab(“title”,object);
Ex 1 To illustrate TabbedPane
4.JComboBox:
JComboBox allows us to create a combobox,with a group of items which are displayed as
dropdownlist.The user can select single item only.
Combo Boxes require less space and hence very useful when size is small or limited.
1.JTo create JComboBox :Syntax
JComboBox jc=new JComboBox()
It creates empty combo box
2.JComboBox jc=new JComboBox(Object arr[])
It creates a new JComboBox that contains elements in the specified array arr[].
Commonly used Methods are :
1. addItem(object):Adds an item to the list
2. removeItem(object):Removes an item from the list
3. object getItemAt(int):Returns the list item at the index position specified by the integer argument
4. int getItemCount() :Returns the number of items in the list
5. int getSelectedIndex() :Returns the position of the currently selected item
6. object getSelectedItem() :Returns the currently selected item
Ex 1: To illustrate JComboBox to display countries
Ex 2 To illustrate JcomboBox
JCheckBox
The JCheckBox class is used to create a checkbox.
JCheckBox represents an item that can be selected or deselected, and which displays its state
to the user.
The user can select one or more options from a group of checkboxes.
Syntax to create JCheckBox class
1.JCheckBox jc=new JCheckBox ();
create a checkbox with out text .
2.JCheckBox jc=new JCheckBox (“apple”);
create a checkbox with text.
3.JCheckBox jc=new JCheckBox (“java”,true);
create a checkbox with text and specify whether or not it is initially selected.
4. JCheckBox jc=new JCheckBox("apple" ,ImageIcon i);
Creates an checkbox with an text and image.
Methods
1.setName(String text) : Sets a name on the JCheckBox, this name will not be displayed.
2.getName() : Gets a String message of JCheckBox, this name will not be displayed.
3.setIcon(Icon icon) : Sets an icon or image over the JCheckBox.
4.isSelected() : This method return true if the check box is selected otherwise it returns
false
5.getModel() : To know which check is selected by the user we should first go to the
model of the check box by calling getModel()
Ex1 to illustrate JCheckBox
JRadioButton
The JRadioButton class is used to create a radio button. It is used to choose one option from
multiple options.
It is used in filling forms, online objective papers and quiz.
We add radio buttons in a ButtonGroup so that we can select only one radio button at a time. We
use “ButtonGroup” class to create a ButtonGroup and add radio button in a group.
Syntax to create RadioButtons:
1.JRadioButton rb=new JRadioButton();
Creates an radio button with no text.
2.JRadioButton rb=new JRadioButton("Apple");
Creates an radio button with text.
3. JRadioButton rb=new JRadioButton(ImageIcon i);
create an radio button with an image
4. JRadioButton rb=new JRadioButton("Java",true)
create a radio button with text and specify whether or not it is initially selected.
Methods
1. isSelected() : it will return a Boolean value true or false, if a JRadioButton is selected it Will
return true otherwise false.
2. setText(String s) : It is used to set specified text on button.
3. getText() : It is used to return the text of the button.
4. setEnabled(boolean b) :It is used to enable or disable the button.
5. setIcon(Icon b) :It is used to set the specified Icon on the button.
JList class:
JList class is used to create a list which displays a list of items and allows us to select one or more
items. It inherits JComponent class.
To create JList syntax:
1.JList jl=new JList() ; create an empty list.
2.JList jl=new JList(object arr[]); creates an list with an elements of an array.
List class Methods:
1. getSelectedIndex()
returns the index of selected item of the list
2. getSelectedValue()
returns the selected value of the element of the list
3. getSelectedValuesList()
returns a list of all the selected items.
4. getSelectedIndices()
returns an array of all of the selected indices, in increasing order
JMenu:
JMenu class is used to create a menu with some options.After creating the menu,it should be
added to the menu bar
JMenuBar:The JMenuBar class is used to display menubar on the window or frame. It may have
several menus.After creating the Menu,it should be added to the menu bar.
JMenuItem:
A menu consists of group of menu items. These menu items can be created using JMenuItem
class
To create Menu bar syntax:
1.JMenuBar mb=new JMenuBar();
creates the new MenuBar();
2.JMenu jm=new JMenu();
Creates a new Menu with no text.
3.JMenu jm=new Jmenu("File");
Creates a new Menu with a specified name.
Methods:
1.add(Component c) : Add component to the end of JMenu
2.add(JMenu c) : Adds menu to the menu bar. Adds JMenu object to the Menu bar.
3.setJMenuBar():This method add menubar to the frame
Ex to illustrate Jmenu and design(Notepad)
JDialog:
The JDialog represents a top level window with a border and a title used to take some form of
input from the user. It inherits the Dialog class.
A JDialog is a top-level Swing container to host components and display a dialog.
it doesn't have maximize and minimize buttons.
Use of Java JDialog
In some applications, information just needs to be displayed with the “OK” button to use so as to
get confirmation from him before submitting the form
Syntax:
1.JDialog jd=new JDialog();
creates an empty dialog without any title or any specified owner
2.JDialog jd=new JDialog(Frame owner)
creates an empty dialog with a specified frame as its owner
3. JDialog jd= new JDialog(Frame owner, String title, boolean modal)
It is used to create a dialog with the specified title, owner Frame and modality.
Methods
1.CreateDialog(): This method creates a new Dialog box which contains JOptionPane.
2.showDialog(): This method is used to make dialog visible.
3.showOpenDialog(): We can use this method to open a dialog box with open on the approve
button.
4.showSaveDialog(): We can use this method to open a dialog box with save on the approve
button.
JScrollPane:
• A JSrollPane is used to make a scrollable view of a component.
• When screen size is limited, we use a scroll pane to display a large component or a
component whose size can change dynamically.
• scroll pane provides horizontal and vertical scroll bars automatically for scrolling the
components through the pane
methods:
1.setColumnHeaderView(Component): It sets the column header for the scroll pane.
2.setRowHeaderView(Component): It sets the row header for the scroll pane.
Syntax: JScrollPane jsp=new JScrollPane(Component , int ver, int hor)
Note:
Where component is the component to be added to the scroll pane
ver and hor specify the policies to display the vertical and horizontal scroll bar.
Some of the standard policies are:
HORIZONTAL_SCROLLBAR_ALWAYS, VERTICAL_SCROLLBAR_ALWAYS.