SlideShare a Scribd company logo
GUI PROGRAMMING
A REVIEW
NET BEANS IDE
 It is used to create java applications using the efficient GUI builder.
 IDE is an acronym for Integrated Development Environment which is a work
environment that integrates all tools necessary forApplication
Development and makes them available as part of one environment.
 GUI is an acronym forGraphical User Interface which is an interface that
allows us to interact with the various components through visual elements
including pictures, graphical icons, symbols and visual indicators
COMPONENTS OF NET BEANS
COMPONENTS
TITLE BAR MENU BAR TOOL BAR GUI BUILDER PALATTE
INSPECTOR
WINDOW
PROPERTIES
WINDOW
CODE EDITOR
WINDOW
It is an area
to place
components
on the form
visually.
There are
two views of
the GUI
builder- the
DesignView
and the
SourceView.
It
contains
controls
or
compone
nts used
to create
GUI
applicatio
ns.
It is used to
display
hierarchical
relationship
among all
the
controls
placed on
the current
form.
It is used
to
view/edit
properties
of
currently
selected
control on
the form.
It is the
area
where
we write
code.
PROJECT
WINDOW
INSPECTOR
WINDOW
PALATTE
PROPERTIE
SWINDOWDESIGNAREA
NET BEANS GUI INTERFACE
PROJECT, FORM AND
COMPONENTS
 Each application is treated as
a Project in NetBeans.
 Each project can have one or
multiple forms.
 Each form can have one or
more components.
PROJECT
FORM1
COMPONENTS
FORM3
COMPONENTS
FORM4
COMPONENTS
FORM2
COMPONENTS
COMPONENTS/CONTROLS
CONTROLS
PARENT/CONTAINER
CONTROL
CHILD CONTROL
They act as background for other
controls. For eg. Frame. When we
delete/move a parent control, all its
child controls get deleted/moved.
Controls placed inside a
container control are called
child control. For eg. Button,
text field, label etc.
Some of these
components may be
visible and some
invisible.The visible
components are all
shown under the
FrameComponent
and the non-visible
components are part
of Other components
in the Inspectors
window.
DESIGNING AN APPLICATION
1. Create a new project.
2. Add a new jFrame form.
3. Add the components on this jFrame
.
4. Associate the code with the
component by double clicking the
component.
5. Add the source code.
6. Test the form by pressing shift+F6.
STEP 1
STEP 2
DESIGNING AN APPLICATION Contd…
OBJECTS
PROPERTIES METHODS
GETTERS SETTERS
EVENTS
Properties specify
the appearance of
an object on the
form. For eg. Font,
background etc.
These methods extract some
information from the object
and return it to the program.
They start with the word get.
For eg. getText(), isEditable()
etc.
These methods set some
properties of the object so
that the object's appearance
changes.They start with the
word set. For eg. setText(),
setForground(), etc.
These are the actions
performed on controls. For
eg.mouseClick, keyPressed
etc.When the user performs
any action on a control, an
event happens and that event
invokes the corresponding part
of the code and the application
behaves accordingly.
All the components including jFrame are
considered as objects in java.
Each object has some properties, methods,
and events associated with it.
CREATING A PROJECT
To create a new application project called “Students":
1. Choose File > New Project. Alternately, click the New
Project icon in the toolbar.
2. From the Categories pane select Java and in the Projects
pane, choose Java Application. Click Next.
3. Enter a name (in this case students) in the Project Name
field and specify the project location by clicking on the
Browse button. By default the project is saved in the
NetBeans Projects folder in My Documents.
4. Ensure that the Set as Main Project checkbox is selected
and clear the Create Main Class field.
5. Click Finish.
JFRAME FORM
Forms are used to accept data (input) from users and
respond to actions like clicking on a button.
ADDING FRAME:To create a JFrame Form container:
1. In the Projects window, right-click the Book node and
choose New > Jframe Form.
2. Enter Form Example 1 as the Class Name.This will be
the name of your form.
3. Enter Book as the package.This should be the name
given while creating the Project.
4. Click Finish
OPTION PANE
Option Pane is used when we want to request information from the user, display information
to the user or a combination of both. It requires the following import statement at the top of
the program.
import javax.swing.JOptionPane;
OR
import javax.swing.*;
METHOD DESCRIPTION EXAMPLE
showMessageDialog() Shows a one-button, modal dialog box that
gives the user some information.
JOptionPane.showMessageDialog(t
his,“Lets learn Java”);
showConfirmDialog() Shows a three-button modal dialog that asks
the user a question. User can respond by
pressing any of the suitable buttons.
Confirm=
JOptionPane.showConfirmDialog(nu
ll,"quit?")
showInputDialog() Shows a modal dialog that prompts the user for
input. It prompts the user with a text box in
which the user can enter the relevant input.
name=
JOptionPane.showInputDialog(this,“
ENTER ROLL NUMBER:");
Steps for developing a Simple application
Step 1: Create a new Project
Step 2: Add a JFrame form
Step 3: Add the desired component from the Palette window using drag
and drop feature
Step 4: Associate code with the component by double clicking the
component.
Step 5: Add the source code.
Step 6:Test the form by pressing Shift+F6.
DEVELOPING A SIMPLE APPLICATION
BUTTON CONTROL
A button is a component that the user presses or pushes to trigger a specific
action.When the user clicks on the button at runtime, the code associated
with the click action gets executed.
PROPERTY DESCRIPTION
BACKGROUND Sets background color
FOREGROUND Sets foreground color
FONT Sets font of text on button
TEXT Sets the text displayed on
button
METHODS DESCRIPTION EXAMPLE
setEnabled() Enables/disables the button JButton1.setEnabled(false); jbutton1.setEnabled(true);
setVisible() Visible/invisible the button JButton1.setVisible(false); jbutton1.setVisible(true);
BUTTON CONTROL AND JOPTION PANE
EXAMPLE
LABEL CONTROL
Label provides text instructions or information. It displays a single line of
read-only text, an image or both text and image.
PROPERTY DESCRIPTION
BACKGROUND Sets background color
FOREGROUND Sets foreground color
FONT Sets font of text on button
TEXT Sets the text displayed on
button
METHODS DESCRIPTION EXAMPLE
isEnabled() Returns true if label is enabled else false Boolean b= jLabel1.isEnabled();
setVisible() Visible/invisible the button jLabel1.setVisible(false); jLabel1.setVisible(true);
setText() Sets the text on label at run time JLable1.setText(“Enter name”);
LABEL AND BUTTON CONTROL EXAMPLE
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jLabel1.setForeground(Color.red);
}
private void
jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jLabel1.setForeground(Color.green);
}
private void
jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
jLabel1.setForeground(Color.blue);
}
Q. WAP to create a form having a label and three buttons. If the red button is pressed the
text in the label should change to red colour and so on.
TEXT FIELD CONTROL
Text Field allows editing/displaying of a single line of text. For eg. Name, Phone
number etc.
PROPERTY DESCRIPTION
BACKGROUND Sets background color
FOREGROUND Sets foreground color
FONT Sets font of text on button
TEXT Sets the text displayed on button
METHODS DESCRIPTION EXAMPLE
isEnabled() Returns true if text field is enabled else false boolean b= jTextfield1.isEnabled();
setVisible() Visible/invisible the button jTextfield1.setVisible(false);
setText() Sets the text on text field at run time jTextfield1.setText(“WELCOME”);
getText() Gets the text from the text field string str = jTextfield1.getText();
isEditable() Returns true if the component is editable else false. boolean b= jTextfield1.isEditable();
setEditable() true if text in the text field is editable else false. JTextfield1.setEditable(true);
LABEL ANDTEXT FIELD CONTROL
EXAMPLE
PASSWORD CONTROL
It is used to enter confidential input like passwords which are single line. It suppress the display
of input and each character entered can be replaced by an echo character. By default, the echo
character is the asterisk, *.
PROPERTY DESCRIPTION
BACKGROUND Sets background color
FOREGROUND Sets foreground color
FONT Sets font of text on button
TEXT Sets the text displayed on button
echoChar Sets the character that will be
displayed instead of text.
PASSWORD CONTROL EXAMPLE
RADIO BUTTON CONTROL
Radio button is used when user has to select one option out of many mutually
exclusive options given. For eg. Gender(male or female),
PROPERTY DESCRIPTION
buttonGroup Specifies the name of the group of button to which
the jRadioButton belongs.
Selected Sets the button as selected, if set to true, default is
false.
METHODS DESCRIPTION EXAMPLE
isSelected() Returns true if radio button is checked else false boolean b= jRadiobutton1.isSelected();
setSelected() Checks(true) or unchecks the radio button. jRadiobutton1.setSelected(false);
setText() Sets the text on radio button at run time jRadiobutton1.setText(“WELCOME”);
RADIO BUTTON CONTROL EXAMPLE
TEXT AREA CONTROL
Text area allows editing/displaying of a multi line text. It automatically adds
vertical or horizontal scroll bars as and when required during run time. For eg.
Comments, address etc.
PROPERTY DESCRIPTION
lineWrap Indicates whether line of text should wrap in case it exceeds allocated
width.(Default is false)
wrapStyleWord Sends word to next line in case lineWrap is true else it results in
breaking of a word, when lines are wrapped.
rows/columns Sets number of rows/columns preferred for display.
text Sets the text displayed on button
METHODS DESCRIPTION EXAMPLE
isEnabled() Returns true if text field is enabled else false boolean b= jTextarea1.isEnabled();
setText() Sets the text on text field at run time jTextarea1.setText(“WELCOME”);
getText() Gets the text from the text field string str = jTextarea1.getText();
isEditable() Returns true if the component is editable else false. boolean b= jTextarea1.isEditable();
append() Adds text at the end JTextarea1.append(“we are studying JAVA”);
CHECK BOX CONTROL
Check box is used when multiple options are given to the user and the user
can select zero or more out of the given options.
PROPERTY DESCRIPTION
buttonGroup Specifies the name of the group of button to which
the check box belongs.
Selected Sets the check box as selected, if set to true, default
is false.
METHODS DESCRIPTION EXAMPLE
isSelected() Returns true if check box is checked else false boolean b= jCheckbox1.isSelected();
setSelected() Checks(true) or unchecks the check box. jCheckbox1.setSelected(false);
setText() Sets the text on check box at run time jCheckbox1.setText(“WELCOME”);
CHECK BOX ANDTEXT AREA CONTROL
EXAMPLE
LIST CONTROL
 A list is a scrollable set of items, used
to get one or more options out of
several given options which may or
may not be mutually exclusive.
 Lists are preferred over checkboxes
when there are large number of
options.
 In such case using Check Boxes may
take up a lot of space on the form and
it may also be inconvenient for the
user to select the desired options.
LIST CONTROL Contd…….
PROPERTY DESCRIPTION
model Contains the values to be displayed in the list.
selectedIndex Contains the index value of selected option of the control.
SelectionMode Describes the mode for selecting values.
- SINGLE (List box allows single selection only)
- SINGLE_INTERVAL (List box allows single continuous
selection of options using shift key of keyboard)
- MULTIPLE_INTERVAL (List box allows multiple
selections of options using ctrl key of keyboard)
METHODS DESCRIPTION EXAMPLE
getSelectedV
alue()
Returns the selected value when only a single
item is selected, if multiple items are selected
then returns first selected value. Returns null in
case no item selected.
jList1.getSelectedValue();
isSelectedInd
ex()
Returns true if specified index is selected. Boolean b= jList1.isSelectedindex();
LIST CONTROL EXAMPLE
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
jTextField1.setText(" "+jList1.getSelectedValue());
jTextField2.setText(" "+jList1.getSelectedIndex());
}
QWAP to create the following form. On click of the button the index number
and river name selected from the list should be displayed in the respective
text fields.
NOTE:The index numbers start from zero.
COMBO BOX CONTROL
 A combo box is a drop down box of
items, used to get one option out of
several given mutually exclusive
options.
 Combo box are preferred over radio
button when there are large number of
options.
 In such case using radio buttons may
take up a lot of space on the form and it
may also be inconvenient for the user to
select the desired options.
COMBO BOX CONTROL
Contd…….
PROPERTY DESCRIPTION
model Contains the values to be displayed.
selectedIndex/selectedItem Contains the index value/selected item of selected option of the control.
METHODS DESCRIPTION EXAMPLE
getSelectedItem() Returns the selected value. jCombobox1.getSelectedItem();
getSelectedIndex() Returns the selected index Boolean b= jCombobox1.getSelectedindex();
setModel() Sets the data model that the combo box
uses to get its list of elements.
jCombobox1.setModel(ComboBoxModel
aModel);
COMBO BOX CONTROL EXAMPLE
private void
jButton1ActionPerformed(java.awt.event.ActionEvent
evt) {
jTextField1.setText(""+jComboBox1.getSelectedItem());
}
QWAP to create the following form. On click of the button river selected from
the combo box should be displayed in the text field.
CODE OUTPUT SCREEN

More Related Content

PPT
Web controls
PDF
Basics of JavaScript
PPTX
Windowforms controls c#
PDF
WT(WEB TECHNOLOGY) previous year question papers
PPT
Java awt
PPT
Eclipse introduction IDE PRESENTATION
PPTX
Lesson 6 php if...else...elseif statements
PPT
Java: GUI
Web controls
Basics of JavaScript
Windowforms controls c#
WT(WEB TECHNOLOGY) previous year question papers
Java awt
Eclipse introduction IDE PRESENTATION
Lesson 6 php if...else...elseif statements
Java: GUI

What's hot (20)

PPT
DOT Net overview
PPT
Introduction to JavaScript
PPT
Php Using Arrays
PPT
Swing and AWT in java
PPTX
Introduction to php
PDF
Asp.net state management
PPTX
introduction to visual basic PPT.pptx
PPT
Php forms
PPTX
Graphical User Interface (GUI)
PPTX
Bash Shell Scripting
PPT
Java Networking
PPT
PPTX
Common language runtime clr
PDF
SQL - RDBMS Concepts
PPT
Server Controls of ASP.Net
PDF
Php tutorial(w3schools)
PPTX
Android activity lifecycle
DOT Net overview
Introduction to JavaScript
Php Using Arrays
Swing and AWT in java
Introduction to php
Asp.net state management
introduction to visual basic PPT.pptx
Php forms
Graphical User Interface (GUI)
Bash Shell Scripting
Java Networking
Common language runtime clr
SQL - RDBMS Concepts
Server Controls of ASP.Net
Php tutorial(w3schools)
Android activity lifecycle
Ad

Viewers also liked (10)

PPT
GUI Programming In Java
PDF
CBSE XII Communication And Network Concepts
PPT
BASIC CONCEPTS OF COMPUTER NETWORKS
PDF
Net Beans
PDF
Chapter8 my sql revision tour
PDF
C++ revision tour
PPTX
Introduction to java netbeans
PPSX
Basic of Java Netbeans
PPT
Networking ppt
PPTX
Introduction to computer network
GUI Programming In Java
CBSE XII Communication And Network Concepts
BASIC CONCEPTS OF COMPUTER NETWORKS
Net Beans
Chapter8 my sql revision tour
C++ revision tour
Introduction to java netbeans
Basic of Java Netbeans
Networking ppt
Introduction to computer network
Ad

Similar to GUI programming (20)

PPTX
Gui programming a review - mixed content
PPTX
Chap 1 - Introduction GUI.pptx
PPT
Chapter 5 GUI for introduction of java and gui .ppt
PPT
events,key,life cycle-abstract window tool kit,abstract class
PDF
GUI.pdf
PPT
awt.ppt java windows programming lecture
PPT
awdrdtfffyfyfyfyfyfyfyfyfyfyfyfyyfyt.ppt
PPT
fdtrdrtttxxxtrtrctctrttrdredrerrrrrrawt.ppt
PPT
1.Abstract windowing toolkit.ppt of AJP sub
PPT
introduction to JAVA awt programmin .ppt
PPTX
PPT
Unit 1- awt(Abstract Window Toolkit) .ppt
PPTX
AWT stands for Abstract Window Toolkit. AWT is collection of classes and int...
PPTX
Online birth certificate system and computer engineering
PPTX
Unit – I-AWT-updated.pptx
PPTX
Graphical User Interface (Gui)
PPT
03_GUI.ppt
PDF
Notes netbeans
PDF
AWT (Abstract Window Toolkit) Controls.pdf
PDF
Ingles 2do parcial
Gui programming a review - mixed content
Chap 1 - Introduction GUI.pptx
Chapter 5 GUI for introduction of java and gui .ppt
events,key,life cycle-abstract window tool kit,abstract class
GUI.pdf
awt.ppt java windows programming lecture
awdrdtfffyfyfyfyfyfyfyfyfyfyfyfyyfyt.ppt
fdtrdrtttxxxtrtrctctrttrdredrerrrrrrawt.ppt
1.Abstract windowing toolkit.ppt of AJP sub
introduction to JAVA awt programmin .ppt
Unit 1- awt(Abstract Window Toolkit) .ppt
AWT stands for Abstract Window Toolkit. AWT is collection of classes and int...
Online birth certificate system and computer engineering
Unit – I-AWT-updated.pptx
Graphical User Interface (Gui)
03_GUI.ppt
Notes netbeans
AWT (Abstract Window Toolkit) Controls.pdf
Ingles 2do parcial

More from Vineeta Garg (10)

PPTX
Pointers in c++
PPTX
Stacks in c++
PPTX
Queues in C++
PPTX
Classes and objects1
PPTX
Constructors and destructors
PPTX
Structured query language functions
PPTX
Structured query language constraints
PPTX
PPTX
Inheritance in c++
PPTX
Data file handling in c++
Pointers in c++
Stacks in c++
Queues in C++
Classes and objects1
Constructors and destructors
Structured query language functions
Structured query language constraints
Inheritance in c++
Data file handling in c++

Recently uploaded (20)

PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Pharma ospi slides which help in ospi learning
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Complications of Minimal Access Surgery at WLH
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
master seminar digital applications in india
PDF
Classroom Observation Tools for Teachers
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Final Presentation General Medicine 03-08-2024.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Pharma ospi slides which help in ospi learning
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Anesthesia in Laparoscopic Surgery in India
STATICS OF THE RIGID BODIES Hibbelers.pdf
A systematic review of self-coping strategies used by university students to ...
Complications of Minimal Access Surgery at WLH
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
master seminar digital applications in india
Classroom Observation Tools for Teachers
Chinmaya Tiranga quiz Grand Finale.pdf

GUI programming

  • 2. NET BEANS IDE  It is used to create java applications using the efficient GUI builder.  IDE is an acronym for Integrated Development Environment which is a work environment that integrates all tools necessary forApplication Development and makes them available as part of one environment.  GUI is an acronym forGraphical User Interface which is an interface that allows us to interact with the various components through visual elements including pictures, graphical icons, symbols and visual indicators
  • 3. COMPONENTS OF NET BEANS COMPONENTS TITLE BAR MENU BAR TOOL BAR GUI BUILDER PALATTE INSPECTOR WINDOW PROPERTIES WINDOW CODE EDITOR WINDOW It is an area to place components on the form visually. There are two views of the GUI builder- the DesignView and the SourceView. It contains controls or compone nts used to create GUI applicatio ns. It is used to display hierarchical relationship among all the controls placed on the current form. It is used to view/edit properties of currently selected control on the form. It is the area where we write code.
  • 5. PROJECT, FORM AND COMPONENTS  Each application is treated as a Project in NetBeans.  Each project can have one or multiple forms.  Each form can have one or more components. PROJECT FORM1 COMPONENTS FORM3 COMPONENTS FORM4 COMPONENTS FORM2 COMPONENTS
  • 6. COMPONENTS/CONTROLS CONTROLS PARENT/CONTAINER CONTROL CHILD CONTROL They act as background for other controls. For eg. Frame. When we delete/move a parent control, all its child controls get deleted/moved. Controls placed inside a container control are called child control. For eg. Button, text field, label etc. Some of these components may be visible and some invisible.The visible components are all shown under the FrameComponent and the non-visible components are part of Other components in the Inspectors window.
  • 7. DESIGNING AN APPLICATION 1. Create a new project. 2. Add a new jFrame form. 3. Add the components on this jFrame . 4. Associate the code with the component by double clicking the component. 5. Add the source code. 6. Test the form by pressing shift+F6. STEP 1 STEP 2
  • 8. DESIGNING AN APPLICATION Contd… OBJECTS PROPERTIES METHODS GETTERS SETTERS EVENTS Properties specify the appearance of an object on the form. For eg. Font, background etc. These methods extract some information from the object and return it to the program. They start with the word get. For eg. getText(), isEditable() etc. These methods set some properties of the object so that the object's appearance changes.They start with the word set. For eg. setText(), setForground(), etc. These are the actions performed on controls. For eg.mouseClick, keyPressed etc.When the user performs any action on a control, an event happens and that event invokes the corresponding part of the code and the application behaves accordingly. All the components including jFrame are considered as objects in java. Each object has some properties, methods, and events associated with it.
  • 9. CREATING A PROJECT To create a new application project called “Students": 1. Choose File > New Project. Alternately, click the New Project icon in the toolbar. 2. From the Categories pane select Java and in the Projects pane, choose Java Application. Click Next. 3. Enter a name (in this case students) in the Project Name field and specify the project location by clicking on the Browse button. By default the project is saved in the NetBeans Projects folder in My Documents. 4. Ensure that the Set as Main Project checkbox is selected and clear the Create Main Class field. 5. Click Finish.
  • 10. JFRAME FORM Forms are used to accept data (input) from users and respond to actions like clicking on a button. ADDING FRAME:To create a JFrame Form container: 1. In the Projects window, right-click the Book node and choose New > Jframe Form. 2. Enter Form Example 1 as the Class Name.This will be the name of your form. 3. Enter Book as the package.This should be the name given while creating the Project. 4. Click Finish
  • 11. OPTION PANE Option Pane is used when we want to request information from the user, display information to the user or a combination of both. It requires the following import statement at the top of the program. import javax.swing.JOptionPane; OR import javax.swing.*; METHOD DESCRIPTION EXAMPLE showMessageDialog() Shows a one-button, modal dialog box that gives the user some information. JOptionPane.showMessageDialog(t his,“Lets learn Java”); showConfirmDialog() Shows a three-button modal dialog that asks the user a question. User can respond by pressing any of the suitable buttons. Confirm= JOptionPane.showConfirmDialog(nu ll,"quit?") showInputDialog() Shows a modal dialog that prompts the user for input. It prompts the user with a text box in which the user can enter the relevant input. name= JOptionPane.showInputDialog(this,“ ENTER ROLL NUMBER:");
  • 12. Steps for developing a Simple application Step 1: Create a new Project Step 2: Add a JFrame form Step 3: Add the desired component from the Palette window using drag and drop feature Step 4: Associate code with the component by double clicking the component. Step 5: Add the source code. Step 6:Test the form by pressing Shift+F6. DEVELOPING A SIMPLE APPLICATION
  • 13. BUTTON CONTROL A button is a component that the user presses or pushes to trigger a specific action.When the user clicks on the button at runtime, the code associated with the click action gets executed. PROPERTY DESCRIPTION BACKGROUND Sets background color FOREGROUND Sets foreground color FONT Sets font of text on button TEXT Sets the text displayed on button METHODS DESCRIPTION EXAMPLE setEnabled() Enables/disables the button JButton1.setEnabled(false); jbutton1.setEnabled(true); setVisible() Visible/invisible the button JButton1.setVisible(false); jbutton1.setVisible(true);
  • 14. BUTTON CONTROL AND JOPTION PANE EXAMPLE
  • 15. LABEL CONTROL Label provides text instructions or information. It displays a single line of read-only text, an image or both text and image. PROPERTY DESCRIPTION BACKGROUND Sets background color FOREGROUND Sets foreground color FONT Sets font of text on button TEXT Sets the text displayed on button METHODS DESCRIPTION EXAMPLE isEnabled() Returns true if label is enabled else false Boolean b= jLabel1.isEnabled(); setVisible() Visible/invisible the button jLabel1.setVisible(false); jLabel1.setVisible(true); setText() Sets the text on label at run time JLable1.setText(“Enter name”);
  • 16. LABEL AND BUTTON CONTROL EXAMPLE private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { jLabel1.setForeground(Color.red); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { jLabel1.setForeground(Color.green); } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { jLabel1.setForeground(Color.blue); } Q. WAP to create a form having a label and three buttons. If the red button is pressed the text in the label should change to red colour and so on.
  • 17. TEXT FIELD CONTROL Text Field allows editing/displaying of a single line of text. For eg. Name, Phone number etc. PROPERTY DESCRIPTION BACKGROUND Sets background color FOREGROUND Sets foreground color FONT Sets font of text on button TEXT Sets the text displayed on button METHODS DESCRIPTION EXAMPLE isEnabled() Returns true if text field is enabled else false boolean b= jTextfield1.isEnabled(); setVisible() Visible/invisible the button jTextfield1.setVisible(false); setText() Sets the text on text field at run time jTextfield1.setText(“WELCOME”); getText() Gets the text from the text field string str = jTextfield1.getText(); isEditable() Returns true if the component is editable else false. boolean b= jTextfield1.isEditable(); setEditable() true if text in the text field is editable else false. JTextfield1.setEditable(true);
  • 18. LABEL ANDTEXT FIELD CONTROL EXAMPLE
  • 19. PASSWORD CONTROL It is used to enter confidential input like passwords which are single line. It suppress the display of input and each character entered can be replaced by an echo character. By default, the echo character is the asterisk, *. PROPERTY DESCRIPTION BACKGROUND Sets background color FOREGROUND Sets foreground color FONT Sets font of text on button TEXT Sets the text displayed on button echoChar Sets the character that will be displayed instead of text.
  • 21. RADIO BUTTON CONTROL Radio button is used when user has to select one option out of many mutually exclusive options given. For eg. Gender(male or female), PROPERTY DESCRIPTION buttonGroup Specifies the name of the group of button to which the jRadioButton belongs. Selected Sets the button as selected, if set to true, default is false. METHODS DESCRIPTION EXAMPLE isSelected() Returns true if radio button is checked else false boolean b= jRadiobutton1.isSelected(); setSelected() Checks(true) or unchecks the radio button. jRadiobutton1.setSelected(false); setText() Sets the text on radio button at run time jRadiobutton1.setText(“WELCOME”);
  • 23. TEXT AREA CONTROL Text area allows editing/displaying of a multi line text. It automatically adds vertical or horizontal scroll bars as and when required during run time. For eg. Comments, address etc. PROPERTY DESCRIPTION lineWrap Indicates whether line of text should wrap in case it exceeds allocated width.(Default is false) wrapStyleWord Sends word to next line in case lineWrap is true else it results in breaking of a word, when lines are wrapped. rows/columns Sets number of rows/columns preferred for display. text Sets the text displayed on button METHODS DESCRIPTION EXAMPLE isEnabled() Returns true if text field is enabled else false boolean b= jTextarea1.isEnabled(); setText() Sets the text on text field at run time jTextarea1.setText(“WELCOME”); getText() Gets the text from the text field string str = jTextarea1.getText(); isEditable() Returns true if the component is editable else false. boolean b= jTextarea1.isEditable(); append() Adds text at the end JTextarea1.append(“we are studying JAVA”);
  • 24. CHECK BOX CONTROL Check box is used when multiple options are given to the user and the user can select zero or more out of the given options. PROPERTY DESCRIPTION buttonGroup Specifies the name of the group of button to which the check box belongs. Selected Sets the check box as selected, if set to true, default is false. METHODS DESCRIPTION EXAMPLE isSelected() Returns true if check box is checked else false boolean b= jCheckbox1.isSelected(); setSelected() Checks(true) or unchecks the check box. jCheckbox1.setSelected(false); setText() Sets the text on check box at run time jCheckbox1.setText(“WELCOME”);
  • 25. CHECK BOX ANDTEXT AREA CONTROL EXAMPLE
  • 26. LIST CONTROL  A list is a scrollable set of items, used to get one or more options out of several given options which may or may not be mutually exclusive.  Lists are preferred over checkboxes when there are large number of options.  In such case using Check Boxes may take up a lot of space on the form and it may also be inconvenient for the user to select the desired options.
  • 27. LIST CONTROL Contd……. PROPERTY DESCRIPTION model Contains the values to be displayed in the list. selectedIndex Contains the index value of selected option of the control. SelectionMode Describes the mode for selecting values. - SINGLE (List box allows single selection only) - SINGLE_INTERVAL (List box allows single continuous selection of options using shift key of keyboard) - MULTIPLE_INTERVAL (List box allows multiple selections of options using ctrl key of keyboard) METHODS DESCRIPTION EXAMPLE getSelectedV alue() Returns the selected value when only a single item is selected, if multiple items are selected then returns first selected value. Returns null in case no item selected. jList1.getSelectedValue(); isSelectedInd ex() Returns true if specified index is selected. Boolean b= jList1.isSelectedindex();
  • 28. LIST CONTROL EXAMPLE private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { jTextField1.setText(" "+jList1.getSelectedValue()); jTextField2.setText(" "+jList1.getSelectedIndex()); } QWAP to create the following form. On click of the button the index number and river name selected from the list should be displayed in the respective text fields. NOTE:The index numbers start from zero.
  • 29. COMBO BOX CONTROL  A combo box is a drop down box of items, used to get one option out of several given mutually exclusive options.  Combo box are preferred over radio button when there are large number of options.  In such case using radio buttons may take up a lot of space on the form and it may also be inconvenient for the user to select the desired options.
  • 30. COMBO BOX CONTROL Contd……. PROPERTY DESCRIPTION model Contains the values to be displayed. selectedIndex/selectedItem Contains the index value/selected item of selected option of the control. METHODS DESCRIPTION EXAMPLE getSelectedItem() Returns the selected value. jCombobox1.getSelectedItem(); getSelectedIndex() Returns the selected index Boolean b= jCombobox1.getSelectedindex(); setModel() Sets the data model that the combo box uses to get its list of elements. jCombobox1.setModel(ComboBoxModel aModel);
  • 31. COMBO BOX CONTROL EXAMPLE private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { jTextField1.setText(""+jComboBox1.getSelectedItem()); } QWAP to create the following form. On click of the button river selected from the combo box should be displayed in the text field. CODE OUTPUT SCREEN