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

Chapter 1 Advanced Programming Part II

The document discusses Java GUI and Swing elements. It begins with an introduction to Java GUI and the differences between AWT and Swing. It then covers various Swing elements like JLabel, JButton and their constructors. It also discusses containers, layout managers and event handling in Java GUI.

Uploaded by

Yoomif Tube
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Chapter 1 Advanced Programming Part II

The document discusses Java GUI and Swing elements. It begins with an introduction to Java GUI and the differences between AWT and Swing. It then covers various Swing elements like JLabel, JButton and their constructors. It also discusses containers, layout managers and event handling in Java GUI.

Uploaded by

Yoomif Tube
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 71

Chapter One

Introduction to Java
(Review)
Part II
Mulugeta G.
Java GUI (Graphical User Interface)
 Java GUI
• A visual interface to a program that are built from GUI
components (buttons, menus, labels etc).
• A GUI component is an object with which the user interacts
via the mouse or keyboard.
• The classes that are used to create GUI components are
part of the java.awt or javax.swing package.
• Both these packages provide rich set of user interface

2
components.
Java GUI (Graphical User Interface)
 AWT (Abstract Window Toolkit)
• is an API to develop GUI 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 Components such as Frame, Label, Button, TextField,
ComboBox, Radiobox, Textbox etc.
• As Java technologies became more popular, users realized AWT

3 was extremely slow and unreliable.


Java GUI (Graphical User Interface)
 AWT (Abstract Window Toolkit)
• The AWT provides nine basic non-container component and three
container classes.
• Java AWT Hierarchy

4
Java GUI (Graphical User Interface)
 Swing

• a next-generation GUI 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, has
grown to a more complete and complex set of around 50 Swing

5 component.
Java GUI (Graphical User Interface)
 Swing

• Swing components are the newest GUI 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 JButton, JTextField,
JTextArea, JRadioButton, Jcheckbox etc.
6
Java GUI (Graphical User Interface)

Swing VS AWT

• OS independent • OS 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 OS
• rich set of object • less as compared to swing

7
Java 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:
Java GUI (Graphical User Interface)
 Container

• a component that can contain another components like buttons,


Textfields, labels etc.
• Sub classes of Container are called as Container.
For example: Panel, Frame and Window.
• Container can add only a Component to itself.
• A default layout is present in each container which can be
overridden using setLayout method.

9
Java 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
Java 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
Java 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
Java 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
Java Layouts Managers
 Nested Layouts
 A JPanel is both a JContainer and a Component
 Because it’s a container, you can put other components into it
 Because it’s a component, you can put it into other containers
 Simplest GUIs are built by creating several JPanels, arranging
them, and putting components (possibly other JPanels) into them
 A good approach is to draw (on paper) the arrangement you want,
then finding an arrangement of JPanels and their layout
managers that accomplishes this
14
Event Handling
• Changing the state of an object is known as an event.
• 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.awt.event package provides many event classes and Listener
interfaces for event handling.
• Steps for java event handling
• Define the event source
• Register an event listener
• Implement the event listener
• Handle the event

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


15
Java 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
16
Java 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 much 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
17
Java 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(Icon image) public JLabel(String text, Icon icon, int
horizontalAlignment)
Icon icon = new ImageIcon("dog.jpg"); Icon icon = new ImageIcon("dog.jpg");
JLabel label = new JLabel(icon); JLabel label = new JLabel("Dog", 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)

18
JLabel label = new JLabel("Dog");
Java GUI Swing Elements
 JButton

 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

19
Java GUI Swing Elements
 JButton 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);
20
Java GUI Swing Elements
 JButton Events
 Event-handling capabilities are inherited from AbstractButton.
 The most helpful listener with the JButton is the ActionListener.
 When the JButton component is selected, all registered
ActionListener objects are notified.
 When the button is selected, an ActionEvent is passed to each
listener.
 This event passes along the actionCommand property of the
21 button to help identify which button was selected.
Java GUI Swing Elements
 JButton Events Example
buttn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
txt1.setText("Mr. Hayelom");
txt2.setText(“Computer Science");
txt3.setText(“2nd Year");
} });
buttn2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
txt1.setText(" ");
txt2.setText(" ");
txt3.setText(" ");
22
} });
Java 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.

23
Java 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);
24
Java 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
• }}
Java 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);
26
Java 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);
27
text3.setText(result); } });
Java 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:

JFrame ddd = new JFrame(“PassFieldExample");


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

Swing Components

29
Java GUI Swing Elements
 JCheckBox

• is used to provide more than one choices to the user.


• Displays a check box icon next to the text label for a two-state
option.
• The Icon uses an optional check mark to show the current state
of the object.
• JCheckBox and JToggleButton components are identical.
• When multiple JCheckBox components are within a ButtonGroup, they
behave like JRadioButton components
30
Java GUI Swing Elements
 JCheckBox Constructors
public JCheckBox()
JCheckBox emptyBox = new JCheckBox();
This one creates an icon without label.
public JCheckBox(String text)
JCheckBox dditBox = new JCheckBox(“DDIT");
This one creates an icon with a label/caption.
public JCheckBox(String text, boolean selected)
JCheckBox dditBox = new JCheckBox(“DDIT”,true);
• This creates a check box with a label and selected by default.

31
Java 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 JCheckBox Components
JToggleButton tb=new JToggleButton(“ON");

• JFormattedTextField:
• Provides for the input of formatted text like
• numeric values, phone numbers,
• dates, or social security numbers.
32
Java 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.
• Use when you want to create a mutually exclusive group of
toggleable components.
• With the predefined look and feel types, JRadioButton and
JCheckBox components look different.
33
Java 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);
34
Java 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);
• Eg. userText.setToolTipText(“Enter your username here.”);

35
Java 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);
36
Java 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);
37
Java GUI Swing Elements
• JTree
• used to display the tree structured data or hierarchical data.
• JTree is a complex component. It has 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)


Java 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);

39
Java 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)

40
Java 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

41
Java GUI Swing Elements
 JList Constructors
public JList()
Empty
Eg. JList list = new JList(); // Creates an empty JList instance

Public JList(Object listData[])


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

42
Java GUI Swing Elements
 JList 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
43
Java GUI Swing Elements
 JList Properties
• visibleRowCount: allows you to deal with number of rows of items
that can be visible at a time.
• Eg. 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
44
Java GUI Swing Elements
• Scrolling JList components and displaying them on containers:
• Create JList component as usual
String regions[] = {“Tigray”,”Afar”,”Amhara”,”Oromia”,”Somali”,”SNNP”};

JList regionList = new JList(regions);


• Create JScrollPane and provide the JList as parameter

JScrollPane regionPane = new JScrollPane(regionList);


• Add the JScrollPane on to container like other components

frame.add(regionPane);
45
Java 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 JComboBox 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
46
Java 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.
47
Java GUI Swing Elements
• JComboBox Properties
• maximumRowCount: allows you to control the maximum
number of visible entries in the pop-up list.
• Syntax: comboBoxObject.setMaximumRowCount(int);
• Eg. cityCombo.setMaximumRowCount(5);
• selectedItem: deals with the currently selected item.
• both getter and setter methods helping you to set a new item to
the combobox.
• Syntax: comboBoxObject.setSelectedItem(String );
• Syntax: comboBoxObject.getSelectedItem();

48
Java 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.

49
Java 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.

50
Java 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
Part IV

Swing Components

52
53
Java 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();

54
Java 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
JMenuBar 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);
55
Java GUI Swing Elements
• JMenu
• is a pull down menu component which is displayed from the
menu bar

• JMenus can be nested within a JMenu to provide sub-menus.

• Each Menu is a collection of the widgets JMenuItem,


JRadioButtonMenuItem, JCheckBoxMenuItem and JSeparator.

Example: //Create the menu.

JMenu menu = new JMenu(“File”);


56
Java GUI Swing Elements
• JMenu
• You need to add JMenu objects to a JMenuBar. Otherwise, the
only thing displayed is the border with nothing in it.
• Example: add two JMenu components into the menu bar
JMenuBar menuBar = new JMenuBar();
JMenu menu1 = new JMenu(“File”);
JMenu menu2 = new JMenu(“Edit”);
menuBar.add(menu1);
menuBar.add(menu2);

57
Java GUI Swing Elements
• JMenu
• By default, consecutively added menus are displayed from left to
right.
• add(Component component, int index) method, which allows
you to specify the position in which the new JMenu is to appear.
JMenuBar menuBar = new JMenuBar();
JMenu menu1 = new JMenu(“File”);
menuBar.add(menu1,0);
• To Remove Menu use: menuBar.remove(menu1);
58
Java 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 JButton.
• Once you have a JMenu, you need to add JMenuItem objects to
it; otherwise, the menu will not display any choices.
• You have to add a separator to JMenu after adding a JMenuItem
JMenuItem jMenuItem = new JMenuItem();
• To add separator use: jMenuItem.addSeparator() Method
59
Java 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");

60
Java 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
61
Java 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);
62
Java 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.
63
Java GUI Swing Elements
• JMenuItem Events
• getSource(): returns the object where the event occurred. Not
very useful.
• getKeyChar(): returns the character represented by the key that
triggered event.
• getKeyCode(): returns 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.
64
Java GUI Swing Elements
• Here is the general way you have to do when you work with JMenu:
• Create a JMenuBar and add it to conatiner
• Create a JMenu component and add it to the JMenuBar.
• For the selections available from the JMenu, you create JMenuItem
components and add them to the JMenu.
• To create submenus, you add a new JMenu to a Jmenu and place
JMenuItem options on the new menu.
• Then, when a JMenu is selected, the system displays its current set of
components within a JPopupMenu.
65 • JPopupMenu dynamically popped up at specific position
Java 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);
66
Java GUI Swing Elements
• JToolBar
• allows us to group other components, usually buttons with icons
in a row or column.
• provides a component which is useful for displaying commonly
used actions or controls.

JToolBar tool = new JToolBar();

67
Java 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
68
Java GUI Swing Elements
• JFileChooser
• represents a dialog window from which the user can select
file
JFileChooser fc=new JFileChooser();

• JFileChooser Constructors
• JFileChooser()

• JFileChooser(File currentDirectory)

• JFileChooser(String currentDirectoryPath)
69
Java 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)
70
Thank You
Next: Chapter 2

71

You might also like