Anda di halaman 1dari 4

Creating Front End

A well laid out user interface is an effective means of making applications user
friendly. User interfaces are used by organizations for various purposes, for
example, accepting orders from customers and obtaining feedback on their
products.

Types of User Interfaces

There are two types of use interfaces, Character User Interface (CUI) and
Graphical User Interfaces (GUI).

In a CUI, you interact with the system by keying in commands. You need to
remember all the commands and the complete syntax. An example of CUI is MS-
DOS. GUIs, on the other hand, provide a graphical way of interacting with the
system. The elements of a typical GUI include windows, drop-down menus,
buttons, scroll bars, icons and wizards.

The Abstract Window Toolkit

The Abstract Window Toolkit (AWT) is a package that provides an integrated set
of classes to manage user interface components such as windows, dialog boxes,
buttons, check boxes, lists, menus, scrollbars, and text boxes.

The Frame Class

A Frame is a powerful feature of AWT. You can create a window for your
application using the Frame class. A frame has a title bar, an optional menu bar,
and resizable border. As it is derived from java.awt.Container, you can add
components to a Frame using the add() method.

The constructor of the Frame class receives the title of the frame as a parameter.
The string is displayed on the title of the frame.

Frame frame = new Frame (Frame Window);

After the window is created, it can be displayed by calling the setVisible()


method. The window can be sized by calling the setSize() method.

Import java.awt.*;

Public class frame extends Frame


{
Public static void main (String args[])
{
Frame frame = new Frame (My Frame);
Frame.setSize(300,400);
Frame.setBackground(Color.red);
Frame.setVisible(true);
}
}
The Panel Class

Panels are used for organizing components. To create a panel, give the following
command.

Panel panel = new Panel();

Once you have created the panel, add it to a frame or an applet. This can be
done using the add() method of the Container class.

Public static void main (String args[])


{
Frame frame = new Frame(My Frame);
Panel panel = new Pnel();
Frame.setSize(300,400);
Frame.setBackground(Color.red);
Frame.setVisible(true);
Button button1= new Button(Button1);
Button button2= new Button(Button2);
Button button3= new Button(Button3);
Frame.add(panel);
Panel.add(button1);
Panel.add(button2);
Panel.add(button3);
}

Creating Menus

Most windows applications have menu bars that enable users to easily locate and
select various commands and options supported by the program. There are two
kinds of menus supported by Java- Regular menus and Pop-ip menus. Java
supports the following classes for creating and managing menus.

I. MenuBar
II. Menu
III. MenuItem
IV. CheckboxMenuItem

Creating a Regular Menu

Create an Object of the MenuBar Class


MenuBar mb = new MenuBar();
Call the setMenuBar() method to attach the menu bar to the frame.
setMenuBar(mb);
Create objects of the Menu Class for each menu you want on the menu bar.
Menu fileMenu = new Menu(File);
Menu editMenu = new Menu(Edit);
Menu optionMenu = new Menu(Options);
Call the add() method of the menuBar Class to add each menu object to the
menu bar.
Mb.add(fileMenu);
Mb.add(editMenu);
Mb.add(optionMenu);
Create object of the MenuItem or CheckboxMenuItem class for each sub-
menu item. The following code adds menu items to the option menu created
earlier.
MenuItem opt1 = new MenuItem(Option1);
MenuItem opt2 = new MenuItem(Option2);
MenuItem sep = new MenuItem(-); // separator
MenuItem opt3 = new MenuItem(Option3);
Call the add() method of the Menu class to add each menu item to its
appropriate menu.
optionMenu.add(opt1);
optionMenu.add(opt2);
optionMenu.add(sep);
optionMenu.add(opt3);

import java.awt.*;

public class myMenu


{
Public static void main (String args[])
{
Frame frame = new Frame (Menu Frame);
Panel panel = new Panel();
MenuBar mb = new MenuBar();
Frame.setMenuBar(mb);
Menu mFile = new Menu(File);
Menu mEdit = new Menu(Edit);
Mb.add(mFile);
Mb.add(mEdit);
MenuItem mNew = new MenuItem(New);
MenuItem mClose = new MenuItem(Close);
MenuItem mCopy = new MenuItem(Copy);
MenuItem mPaste = new MenuItem(Paste);
mFile.add(mNew);
mFile.add(mClose);
mEdit.add(mCopy);
mEdit.add(mPaste);
frame.setSize(400,400);
frame.setVisible(true);
}
}
The javax.swing Package

The javax.swing package provides an integrated set of classes to manage user


JComponent
interfaces

JToggleButto
JButton JComboBox JLabel JList JMenuBar JMenuItem
n

JCheckBoxMenuIt
JRadioButton
em

JRadioButtonMenuIt
JCheckBox
em

Java.awt.Windo
w Java.awt.Applet

Dialog Frame JWindow JApplet

JDialog JFrame

The JFrame Class

Frames are a powerful feature of Swing. You can create a window for your
application using the JFrame class. A frame is a special kind of window, which has
a titlebar, an optional menu bar, and resizable border. As it is derived from the
java.awt.Frame class, you can add components to a JFrame object using the
add() method.

To create a frame window, call the constructor of JFrame class. The constructor
receives the title of the frame as a parameter. The string is displayed on the title
of the frame.

JFrame frame = new JFrame(Frame Window);

After the window is created, it can be displayed by calling the setVisible()


method. The window can be sized by calling the setSize() method. The following
program displays a frame.

Anda mungkin juga menyukai