MDI Form in SWING
(Creating MDI Form in SWING)Design a
class, which extends JFrame and has three objects of three classes whose name
are ColorPanel, CitiesPanel, and FlavourPanel. All the three classes
(ColorPanel: Names of colors inside it, CitiesPanel: Names of cities inside it,
and FlavourPanel- Names of Icecream flavours) extend JInternalFrame and have a
method, which makes the Panel visible.
The main JFrame has an object of JDesktopPane and this object holds the
three panels, which are displayed on the click of the menu bar item.
Packages
used:
1.
javax.swing.* : Provides a set of
"lightweight" (all-Java language) components that, to the maximum
degree possible, work the same on all platforms.
2.
java.awt.* : Contains all of the classes for
creating user interfaces and for painting graphics and images.
3.
java.awt.event.* : Provides interfaces and classes for
dealing with different types of events fired by AWT components.
Classes used:
·
JMenuBar : An implementation of a menu bar.
JMenu
objects are added to the menu bar to
construct a menu
·
JMenu : An implementation of a menu -- a
popup window containing
JMenuItem
s
that is displayed when the user selects an item on the JMenuBar
.
·
JMenuItem : An implementation of an item in a menu. A
menu item is essentially a button sitting in a list.
·
JDesktopPane
: A container used to create a multiple-document interface or a virtual
desktop.
Logical flow of the program:
·
A menu is
created with an object of JMenuBar which holds a JMenu object.
·
This
JMenu object contains three JMenuItem objects,each attached to ActionListener.Clicking
on those menuitems will lead to an JInternalFrame object on the JDesktopPane.
·
Object of
JDesktopPane class is created which holds objects of JInternalFrame class.
·
Each
JInternalFrame object contains a JPanel container holding different components.
Important Notes :
·
In all
swing program the package that should be imported is “javax.swing.*”.
·
If in the
program JApplet is inherited then
the “init()” method is used to
initialize the applet.
·
If in the
program JFrame is inherited then the
inheriting class’s constructor initializes the swing application.
1. If super() method is called ,it should be the
first line inside the constructor.
2. Frame’s visibility and size must be set.
0 comments: