0% found this document useful (0 votes)
17 views

Chapter 1 Advanced Programming - Part II

hh

Uploaded by

Umer Hassanur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Chapter 1 Advanced Programming - Part II

hh

Uploaded by

Umer Hassanur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

Chapter One

Introduction to Java
( Java GUI Design)
Part II
J a v a GUI (Graphical User Interface)
⦁ J ava GUI
• A visual interface to a program that are built from GUI
components (buttons, menus, labels etc).
• A G U I component is an object with which the user interacts
via the mouse or keyboard.

• The classes that are used to create G U I com ponents are


part of the java.awt or javax.swing package.

• Both these packages provide rich set of user interface


components.
2
J a v a GUI (Graphical User Interface)
⦁ AWT (Abstract Window Toolkit)
• is an API to develop G U I or window-based applications in java.
• It provided only the minimal amount of functionality necessary to
create a windowing application.

import java.awt.*; / / for AWT graphics


• AWT C omponents su ch as Fram e, Label, B u tton, TextField,
ComboBox, Radiobox, Textbox etc.

• As J ava technologies becam e more popular, users realized AWT


was extremely slow and unreliable.
3
J a v a GUI (Graphical User Interface)
⦁ AWT (Abstract Window Toolkit)
• The AWT provides nine basic non-container component and three
container classes.

• J ava AWT Hierarchy

4
J a v a GUI (Graphical User Interface)
⦁ Swing
• a next-generation G U I toolkit that enable enterprise development
• A set of customizable graphical components whose look-and-feel
can be dictated at runtime.

• Swing is built on top of the core AWT libraries

import javax.swing.*;
• Consists nine AWT components, plus menus and containers, ha s
grown to a more complete and complex set of around 50 Swing
component.
5
J a v a GUI (Graphical User Interface)
⦁ Swing
• Swing components are the newest G U I components and called
pure java components.

• allow the programmer to specify a uniform look and


feel across all platforms.

• Name start from J of swing class


•Consists of J B u t to n , JTextField,

JTextArea, JRadioButton, Jcheckbox etc.

6
J a v a GUI (Graphical User Interface)

Swing VS AWT

• O S independent • O S dependent

• Light weight • Heavy weight


• base on Write once use • Not consistent as compared
anywhere to Swing

• Uniform feel and look • change behavior due to O S

• rich set of object • less as compared to swing

7
J a v a GUI (Graphical User Interface)
⦁ Swing
• Some of the components that didn’t originate in the AWT are:-
• JPasswordField: • JToolTip:
• JEditorPane and JTextPane: • JToolBar:
• JSpinner • JRadioButtonMenuItem
• JToggleButton: • JSeparator:
• JSlider: • JDesktopPaneand
• JProgressBar: JInternalFrame:
• JFormattedTextField: • JOptionPane:
• JTable: • JColorChooser:
• JTree: • JSplitPane:
8 • JTabbedPane:
J a v a GUI (Graphical User Interface)
⦁ Container
• a component that can contain another components like buttons,
Textfields, labels etc.
• S u b classes of Container are called as Container.

For example: Panel, Frame and Window.

• Container can add only a Component to itself.


• A defau lt layou t is present in each container which can be
overridden using setLayout method.

9
J a v a GUI (Graphical User Interface)
⦁ Container
• Window
 a container that have no borders and no menu bars.
• Panel
 A container that doesn't contain title bar and menu bars.
 It provides space in which any other component like button,
textfield etc can be placed, including other panels.
• Frame
 A container that contain title and border.
 It can have other components like button, textfield etc.
10
J a v a GUI (Graphical User Interface)
⦁ Methods of Component Class
• add(Component C)
• Inserts a component of the component
• setSize (int width, int Height)
• Sets the size of the component
• setLayout(LayoutManager M)
• Defines the layout manager for the component
• setVisible(Boolean status)
• Changes the visibility of the component, by default false
11
J a v a GUI (Graphical User Interface)
⦁ Methods of Component Class
 setTitle(String)
• used to set display user defined message on title bar.
 setBackground(color)
• used to set background color.
 setForeground(color)
• used to set Foreground or text color.

12
J a v a Layouts Managers
⦁ The most important layout managers are:
• BorderLayout
• Provides five areas into which you can put components
• default layout manager for both JFrame and Japplet

• FlowLayout : Components are added left to right, top to bottom

• GridLayout : Components are put in a rectangular grid with the


same size and shape

• BoxLayout : Creates a horizontal row or a vertical stack and it’s


a little weird to use
13
J a v a GUI Swing Elements
• JLabel • JformatedTextField • JTable, JTree

• JButton • JTextArea • JToolTip

• JTextField • JScrollBar • JToolBar

• JPasswordField • Jspinner • Jseparator

• JCheckBox • Jslider • JTabbedPane

• JRadioButton • JProgressBar • JColorChooser

• JList • JOptionPane • JToggleButton

• JComboBox • JFileChooser • ImageIcon


14
J a v a GUI Swing Elements
⦁ JLabel
• is a component for placing text in a container.

• used to place any text information on the screen.


• The JLabel serves as the replacement component for the AWT Label
but it can do m u c h more.

• The AWT Label is limited to a single line of text, the Swing JLabel
can have text, images, or both.

• The text can be a single line of text or HTML.

• In addition JLabel can support different enabled and disabled images


15
J a v a GUI Swing Elements
⦁ JLabel Constructors
public JLabel(String text, int horizontalAlignment)
public JLabel() JLabel label = new JLabel("Dog", JLabel.RIGHT);
JLabel label = new JLabel();
public JLabel(String text, Icon icon, int
public JLabel(Icon image) horizontalAlignment)
Icon icon = new ImageIcon("dog.jpg"); Icon icon = new ImageIcon("dog.jpg");
JLabel label = new JLabel("Dog", icon,
JLabel label = new JLabel(icon); JLabel.RIGHT);
public JLabel(Icon image, int horizontalAlignment)
Icon icon = new ImageIcon("dog.jpg");

JLabel label = new JLabel(icon, JLabel.RIGHT);


public JLabel(String text)
JLabel label = new JLabel("Dog");
18
J a v a GUI Swing Elements
⦁ JTextField
• Is the text component for a single line of input.
• used to get the input from the user in the form of text.
• When Enter key is pressed within the JTextField, it automatically
notifies any registered ActionListener implementations.

17
J a v a GUI Swing Elements
⦁ JTextField Constructor
⦁ public JTextField()
⦁ JTextField textField = new JTextField();
⦁ public JTextField(String text)
⦁ JTextField textField = new JTextField("Initial Text");
⦁ public JTextField(int columnWidth)
⦁ JTextField textField = new JTextField(14);
⦁ public JTextField(String text, int columnWidth)
⦁ JTextField textField = new JTextField("Initial Text", 14);
18
J a v a GUI Swing Elements
⦁ JTextField Events
• actionListeners: is used to declare and define listeners for
textfield objects.
• Actions for a textfield happens when the user types in the
textfield and press enter key.
• Like Button object, textfield actionListeners listens and take
actions by implementing actionPerformed method as shown
in the following code fragement.
• Syntax: ActionListener actionListener = new ActionListener(){
• public void actionPerformed(ActionEvent event){
• //the code goes here.
25 • }}
J a v a GUI Swing Elements
⦁ JTextField Properties
• setEditable(boolean bool): used to change the editability of a
textfield object.
• if bool is true then user can write into a textfield and edit its
content otherwise it’s false not to edit the content.
• Eg. userText.setEditable(false);
• setHorizontalAlignment(int): used to adjust the position of the
text in the textfield object.
• The int has three types of values: JTextField.LEFT,
JTextField.CENTER, JTextField.RIGHT.
Syntax: textField.setHorizontalAlignment(JTextField.RIGHT);
20
J a v a GUI Swing Elements
⦁ JTextField Example
addition.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s1=text1.getText();
String s2=text2.getText();
int a=Integer.parseInt(s1);
int b=Integer.parseInt(s2);
int c=0;
c=a+b;
String result=String.valueOf(c);
21
text3.setText(result); }});
J a v a GUI Swing Elements
⦁ J B u t to n
 used to create a labeled button that has platform independent
implementation.

 a component that can control the behavior of the Application.

 declaration for javax.swing.JButton;

 It supports text, images, and HTML-based labels

22
J a v a GUI Swing Elements
⦁ J B u t to n Constructors
public JButton() public JButton(Action action)
JButton button = new JButton(); Action action = ...;
public JButton(Icon image) JButton button = new JButton(action);
Icon icon = new ImageIcon("dog.jpg");
JButton button = new JButton(icon);
public JButton(String text)
JButton button = new JButton("Dog");

public JButton(String text, Icon icon)


Icon icon = new ImageIcon("dog.jpg");
JButton button = new JButton("Dog", icon);
23
Event Handling
• Event handling refers to the process of responding to users interactions with GUI
components.
• Involves the process of responding to an action or occurrence triggered by
a user, system, or other external source.
• The action or occurrence is called event , and the code that execute in
response to the even is called event handler.
• The java. aw t. event package provides many event classes and Listener
interfaces for event handling.
• Event Source :- the component that generates the event
• Event Listener:- it defines methods for handling events.

• Example : click on button, dragging mouse, enter text field, etc.

24
J a v a GUI Swing Elements
⦁ J B u t to n Events
⦁ The most helpful listener with the J B u t to n is the ActionListener.

that defines what happens when the button is clicked.


⦁ When th e button is selected, an ActionEvent is passed to each
listener.

21
J a v a GUI Swing Elements
⦁ J B u t to n Events Example
buttn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
txt1.setText("Mr. Hayelom");
txt2.setText(“Computer Science");
txt3.setText(“2 nd Year");
}});
buttn2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
txt1.setText(" ");
txt2.setText(" ");
txt3.setText(" ");
22
} });
J a v a GUI Swing Elements
⦁ JPasswordField
 Used for password entry and you cannot use cut or copy operations
within the component, but you can paste text into it.

 data written in the passwordfield is retrieved by getText() method

 javax.swing.JPasswordField class.
Example:

J Fra m e ddd = new JFrame(“PassFieldExample");


JPasswordField value = new JPasswordField(20);
27
Part III

Swing Components

29
J a v a GUI Swing Elements
⦁ J C h e c k B ox
• is used to provide more than one choices to the user.
• D isplays a check box icon next to the text label for a two-state
option.

• The Icon u ses an optional check mark to show the cu rrent state
of the object.

• J C h e c k B ox and JToggleButton components are identical.


• When multiple J C h e c k B ox components are within a ButtonGroup, they
behave like JRadioButton components
29
J a v a GUI Swing Elements
⦁ J C h e c k B ox Constructors
public JCheckBox()
J C h e c k B ox emptyBox = new JCheckBox();
This one creates an icon without label.
public JCheckBox(String text)
J C h e c k B ox dditBox = new JCheckBox(“DDIT");
This one creates an icon with a label/caption.
public JCheckBox(String text, boolean selected)
J C h e c k B ox dditBox = new JCheckBox(“DDIT”,true);
• This creates a check box with a label and selected by default.

30
J a v a GUI Swing Elements
• JToggleButton
• it is two-states button to switch on or off.
• a button that stays depressed when selected.
• It is identical with the J C h e c k B ox Components

JToggleButton tb=new JToggleButton(“ON");

• JFormattedTextField:
• Provides for the input of formatted text like
• numeric values, phone numbers,
• dates, or social security numbers.
31
J a v a GUI Swing Elements
⦁ JRadioButton
• a graphical component that can be in either on (true) or off (false)
state in a group. (selected or deselected)

• The user can only choose one option among all.


• U se when you want to create a mu tu a lly exclusive group of
toggleable components.

• With the predefined look and feel types, JRadi o B utton and
J C h e c k B ox components look different.
32
J a v a GUI Swing Elements
⦁ JRadioButton Constructors
public JRadioButton()
Eg. JRadioButton emptyButton = new JRadioButton();
public JRadioButton(String text)
Eg . JRadioButton fantaButton = new JRadioButton(“Fanta");
public JRadioButton(String text, Icon icon)
Icon fantaIcon = new ImageIcon(“fantaImage.jpg”);
JRadioButton fantaIconButton=new JRadioButton(“Fanta”, fantaIcon);
public JRadioButton(String text, boolean selected)
JRadioButton fantaSelectedButton = new JRadioButton(“Fanta”,true);

33
J a v a GUI Swing Elements
⦁ JToolTip
• display pop-up messages when the cursor rests over them.
• Tooltip text is normally one line long.

• Syntax to add tooltip text:

• component.setToolTipText(String text);

• E g . userText.setToolTipText(“Enter your username here.”);

34
J a v a GUI Swing Elements
• JProgressBar
• allows the user to visually see the progress of an activity.
• used to display the progress of the task
• JProgressBar Constructors
JPrograssBar() eg. JPrograssBar jb=new JProgressBar();
JPrograssBar(int min, int max) eg.JPrograssBar jb=new JProgressBar(0, 200);
JPrograssBar(int orient)
• JPrograssBar jb=new JProgressBar(Horizontal or vertical);
JPrograssBar(int orient, int min, int max)
• JPrograssBar jb=new JProgressBar(horizontal/ vertical, value, value);

35
J a v a GUI Swing Elements
• JTable
• used to display data in tabular form

• JTable Constructors
Jtable()
• JTable jt=new JTable();

JTable (object rows,object column)


• JTable jt=new JTable(data, column);
36
J a v a GUI Swing Elements
• JTree
• used to display the tree structured data or hierarchical data.
• J T ree is a complex com ponent. It h a s a 'root node' at the top
most which is a parent for all nodes in the tree.

• JTree Constructors
JTree()
• JTree jt=new JTree(style);
JTree (object [] value)

38
JTree (TreeNode root)
J a v a GUI Swing Elements
• JColorChooser
• used to create a color chooser dialog box so that user can select
any color.

• Constructors
JcolorChooser()

JColorChooser(color initialcolor)

Jcolor color=Jcolor(color,initialcolor);

38
J a v a GUI Swing Elements
• JTabbedPane
• used to switch between a group of components by clicking on a
tab with a given title or icon

• Constructors

JTabbedPane()

JTabbedPane(int tab placement)


JTabbedPane(int tab placement, int tab layout policy)

39
J a v a GUI Swing Elements
⦁ JList
• Used for selecting one or more items from a set of choices.
• You present the list of choices to the user, and the user can pick
one or several, depending on the selection mode of the
component.
• Three key elements and their implementations define the JList
structure:
• A data model for holding the JList data
• A cell renderer for drawing the elements of the JList
• A selection model for selecting elements of the JList

40
J a v a GUI Swing Elements
⦁ J L i s t Constructors
public JList()
Empty
Eg . JLi st list = new JList(); / / Creates an empty JList instance

Public JList(Object listData[])


• String regions []= {“Afar”,”Amhara”,”Gambela”,”Oromia”};
• JLi st regionList = new JList(regions);

41
J a v a GUI Swing Elements
⦁ J L i s t Properties
• selectedValue: It works only when a single item is selected in the list.
• Eg. regionList.setSelectedValue(“Afar”);
• Eg . regionList.getSelectedValue();
• selectedIndex: allows you deal with the index of an item.
• Two methods exist: setSelectedIndex(int) & getSelectedIndex();
• Eg. regionList.setSelectedIndex(1); //Selects “Amhara”
• Eg. regionList.getSelectedIndex(); //Returns index of selected item
• Eg. int region[] = {1,3};
• regionList.setSelectedIndexes(region); //Selects “Amhara” & “Oromia
42
J a v a GUI Swing Elements
⦁ J L i s t Properties
• visibleRowCount: allows you to deal with n um ber of rows of items
that can be visible at a time.

• E g . regionList.setVisibleRowCount(4);

• You must place the component within a JScrollPane


• JScrollPane offers the Jlist a vertical scrollbar

to move through all the available choices.

Otherwise only the top group of choices will be visible


43
J a v a GUI Swing Elements
• Scrolling J L i s t components and displaying them on containers:
• Create J L i s t component as usual

String regions[] = {“Tigray”,”Afar”,”Amhara”,”Oromia”,”Somali”,”SNNP”};

J L i s t regionList = new JList(regions);


• Create JScrollPane and provide the J L i s t as parameter

JScrollPane regionPane = new JScrollPane(regionList);

• Add the JScrollPane on to container like other components

frame.add(regionPane);
44
J a v a GUI Swing Elements
• JComboBox
• is a multiple-part component.
• Allows a user to choose from a predefined set of choices with the
help of a pull-down list.

• When the desired choice isn’t available, the J C o m b o B ox can use


a JTextField to enter a new choice.

• The text field for editing is disabled by default, permitting a


user to select from the set of predefined choices only
45
J a v a GUI Swing Elements
• JComboBox Constructors
public JComboBox()
JComboBox emp = new JComboBox();
– Creates an empty list JComboBox instance.

public JComboBox(Object listData[])


 String cities[] ={"Adama","Asosa","Bahirdar","Finfine",
“Gambella","Harar","Hawassa","Jigjiga", "Mekelle“,"Samara"};

JComboBox cityCombo = new JComboBox(cities);


– Creates a combo box with list of choices.
46
J a v a GUI Swing Elements
• JComboBox Properties
• maximumRowCount: allows you to control the m aximum
number of visible entries in the pop-up list.
• Syntax: comboBoxObject.setMaximumRowCount(int);
• E g . cityCombo.setMaximumRowCount(5);
• selectedItem: deals with the currently selected item.
• both getter and setter methods helping you to set a n ew item to
the combobox.
• Syntax: comboBoxObject.setSelectedItem(String );
• Syntax: comboBoxObject.getSelectedItem();

47
J a v a GUI Swing Elements
• JTextArea
• The text component for multiple-line input.

• Is a multi line region that displays text.

• It allows the editing of multiple line text.

• JTextArea doesn’t support scrolling itself


• You need to place each JTextArea within a JScrollPane to allow a
user to properly scroll through the contents of a JTextArea.

48
J a v a GUI Swing Elements
• JTextArea Constructors
JTextArea() Creates a text area that displays no
text initially.
JTextArea(String s) Creates a text area that displays
specified text initially.
JTextArea(int row, int cols) Creates a text area with the specified
number of rows and columns that
displays no text initially.
JTextArea(String s, int row, Creates a text area with the specified
int column) number of rows and columns that
displays specified text.
49
J a v a GUI Swing Elements
• JTextArea Methods
Methods Description
void setRows(int rows) It is used to set specified number of
rows.
void setColumns(int cols) It is used to set specified number of
columns.
void setFont(Font f) It is used to set the specified font.
void insert(String s, int position) It is used to insert the specified
text on the specified position.
void append(String s) It is used to append the given text
to the end of the document.
51
52
J a v a GUI Swing Elements
• JMenuBar
• is the top-level widget.

• It controls the layout of the main bar.

• is used to display menubar on the window or frame.

•It may have several menus.

Example: //Create the menu bar.

JMenuBar menuBar = new JMenuBar();

52
J a v a GUI Swing Elements
• JMenuBar
• Once you create the menu bar, you can add it to a window with
the setJMenuBar() method and appears at the top of the window

• You can also use the add() method of a Container to add a


J M e n u B a r to a window. And is arranged by the layout manager
of the Container.
JFrame f = new JFrame("Menu Example");
JMenuBar menuBar = new JMenuBar();
f.setJMenuBar(menuBar); // f.add(menuBar);
53
J a v a GUI Swing Elements
• JMenu
• is a pull down m enu component which is displayed from the
menu bar

• J M e n u s can be nested within a J M e n u to provide sub-menus.


• E a c h Menu is a collection of the widgets JMenuItem,
JRadioButtonMenuItem, JCheckBoxMenuItem and JSeparator.

Example: //Create the menu.

J M e n u menu = new JMenu(“File”);


54
J a v a GUI Swing Elements
• JMenu
• You need to add J Menu objects to a J M e n u B a r. Oth erwise, the
only thing displayed is the border with nothing in it.

• Example: add two J M e n u components into the menu bar


JMenuBar menuBar = new JMenuBar();
J M e n u menu1 = new JMenu(“File”);
J M e n u menu2 = new JMenu(“Edit”);
menuBar.add(menu1);
menuBar.add(menu2);

55
J a v a GUI Swing Elements
• JMenu
• By default, consecutively added menus are displayed from left to
right.

• add(Componen t component, int index) method, which allows


you to specify the position in which the new J M e n u is to appear.
JMenuBar menuBar = new JMenuBar();
J M e n u menu1 = new JMenu(“File”);
menuBar.add(menu1,0);
• To Remove Menu use: menuBar.remove(menu1);
56
J a v a GUI Swing Elements
• JMenuItem
• is the predefined component that a user selects on a menu bar.
• acts as a specialized button component similar to a J B u t to n .
• O n ce you have a J M e n u , you need to add J M e n u Item objects to
it; otherwise, the menu will not display any choices.

• You have to add a separator to J M e n u after adding a JMenuItem


JMenuItem jMenuItem = new JMenuItem();
• To add separator use: jMenuItem.addSeparator() Method
57
J a v a GUI Swing Elements
• JMenuItem Constructor
public JMenuItem()
• JMenuItem jMenuItem = new JMenuItem();

public JMenuItem(Icon icon)

• Icon atIcon = new ImageIcon("at.gif ");


• JMenuItem jMenuItem = new JMenuItem(atIcon);
public JMenuItem(String text)
• JMenuItem jMenuItem = new JMenuItem("Cut");

58
J a v a GUI Swing Elements
• JMenuItem Constructor
public JMenuItem(String text, Icon icon)
• Icon atIcon = new ImageIcon("at.gif ");
• JMenuItem jMenuItem = new JMenuItem("Options", atIcon);
public JMenuItem(String text , int mnemonic)
•JMenuItem jMenuItem = new JMenuItem("Cut",
KeyEvent.VK_T); // Alt - C
⦁ Mnemonic allows you to select the menu through keyboard navigation
59
J a v a GUI Swing Elements
• JMenuItem Properties
• accelerator: This property allows you to add a functionality that
can help you use the menu item from your keyboard.
• It uses a KeyStroke factory class that lets you create
instances based on key and modifier combinations.
• Here is how you can use this property:
• First create an instance of KeyStroke class and use the
setAccelarator(KeyStroke) method to set up an accelerator for
the menu item.
KeyStroke cutMenuItemStroke = KeyStroke.getKeyStroke("control X");
cutMenuItem.setAccelerator(cutMenuItemStroke);
60
J a v a GUI Swing Elements
• JMenuItem Events
• allow you to listen for the firing of ChangeEvent and ActionEvent
through the ChangeListener and ActionListener registration
methods of AbstractButton.

• The better listener to attach to a JMenuItem is the


ActionListener.

• It allows you to find out when a menu item is selected.

• MenuKeyEvent - represents an event occurred on a menu item.


61
J a v a GUI Swing Elements
• JMenuItem Events
• getSource(): return s the objec t where the event occurred. Not
very useful.
• getKeyChar(): returns the character represented by the key that
triggered event.
• getKeyCode(): return s the code value represented by the key
that triggered event.
• getKeyText(): returns the text name of a given key code value.
• getPath(): returns a list of menu objects representing a path in
the menu tree.
62
J a v a GUI Swing Elements
• Here is the general way you have to do when you work with J M e n u :
• Create a JMenuBar and add it to conatiner

• Create a J M e n u component and add it to the J M e n u B a r.

• For the selections available from the J M e n u , you create JMenuItem


components and add them to the J M e n u .
• To create subm enu s, you add a new J M enu to a J m e n u and place
JMenuItem options on the new menu.

• Th en, when a J M e n u is selected, the system displays its current set of


components within a JPopupMenu .

64 • JPopupMenu dynamically popped up at specific position


J a v a GUI Swing Elements
• JSeparator
• used to provide a general purpose component for implementing
divider lines.
• It is used to draw a line to separate widgets in a Layout.
• Jseparator Constructors
Jseparator()
JSeparator sep = new JSeparator();
Jseparator(int orientation)
JSeparator sep = new JSeparator(horizontal);
64
J a v a GUI Swing Elements
• JToolBar
• allows u s to group other components, usually buttons with icons
in a row or column.

• provides a com ponent which is u sefu l for displaying com m only


used actions or controls.

JToolBar tool = new JToolBar();

65
J a v a GUI Swing Elements
• JToolBar Constructors
Constructor Description
JToolBar() It creates a new tool bar; orientation
defaults to HORIZONTAL.
JToolBar(int orientation) It creates a new tool bar with the
specified orientation.
JToolBar(String name) It creates a new tool bar with the
specified name.
JToolBar(String name, int It creates a new tool bar with a
orientation) specified name and orientation
66
J a v a GUI Swing Elements
• JFileChooser
• represents a dialog window from which th e user c an select
file

JFileChooser fc=new JFileChooser();

• JFileChooser Constructors
• JFileChooser()

• JFileChooser(File currentDirectory)

• JFileChooser(String currentDirectoryPath)
67
J a v a GUI Swing Elements
• JOptionPane
• used to provide standard dialog boxes such as message dialog
box, confirm dialog box and input dialog box.

• These dialog boxes are used to display information or get


input from the user

• JOptionPane Constructors
• JOptionPane()
• JOptionPane(object, Message)
• JOptionPane(Object, Message, Message type)
68
Thank You
Next:Chapter 2

70

You might also like