SlideShare a Scribd company logo
Java Swings
• A graphical user interface (GUI) presents a user-
friendly mechanism for interacting with an
application. These are sometimes called controls
or widgets—short for window gadgets. A GUI
component is an object with which the user
interacts via the mouse, the keyboard or another
form of input, such as voice recognition.
• Java’s so-called Swing GUI components from the
javax.swing package. We cover other
Complete java swing
Complete java swing
Complete java swing
Simple GUI-Based Input/Output with
JOptionPane
• Most applications you use on a daily basis use windows or
dialog boxes (also called dialogs) to interact with the user.
For example, an e-mail program allows you to type and
read messages in a window the program provides. Dialog
boxes are windows in which programs display important
messages to the user or obtain information from the user.
Java’s JOptionPane class (package javax.swing) provides
prebuilt dialog boxes for both input and output. These are
displayed by invoking static JOptionPane methods. Program
presents a simple addition application that uses two input
dialogs to obtain integers from the user and a message
dialog to display the sum of the integers the user enters.
• // Addition.java
• // Addition program that uses JOptionPane for input and output.
• import javax.swing.JOptionPane; // program uses JOptionPane
• public class Addition
• {
• public static void main( String[] args )
• {
• // obtain user input from JOptionPane input dialogs
• String firstNumber =
• JOptionPane.showInputDialog( "Enter first integer" );
• String secondNumber =
• JOptionPane.showInputDialog( "Enter second integer" );
Complete java swing
Complete java swing
• private void
jButton1ActionPerformed(java.awt.event.Acti
onEvent evt) {
• JOptionPane.showMessageDialog(null, "Thank
you");// TODO add your handling code here:
• }
Overview of Swing Components
Complete java swing
Complete java swing
Complete java swing
Complete java swing
Non-AWT Upgraded Components
• In addition to offering replacements for all the
basic AWT components, the Swing component
• set includes twice as many new components.
Complete java swing
Complete java swing
Complete java swing
Complete java swing
Complete java swing
• package hello;
• import javax.swing.*;
• class jpswrd
• {
• public void Testing()
• {
• JPasswordField pwd = new JPasswordField(10);
• int action = JOptionPane.showConfirmDialog(null, pwd,"Enter
Password",JOptionPane.OK_CANCEL_OPTION);
• if(action < 0)JOptionPane.showMessageDialog(null,"Cancel, X or escape key selected");
• else JOptionPane.showMessageDialog(null,"Your password is "+new
String(pwd.getPassword()));
• System.exit(0);
• }
• public static void main(String args[])
• {jpswrd p= new jpswrd();
• p.Testing();}
• }
output
• setEchoChar('+');
• Set character for password field.
JFrame
• A Frame is a top-level window with a title and
a border.
• Frame that adds support for the Swing
component architecture.
JFrame Features
 It’s a window with title, border, (optional)
menu bar and user-specified components.
.It can be moved, resized, iconified.
.It is not a subclass of JComponent.
.Delegates responsibility of managing user-
specified components to a content pane, an
instance of JPanel.
Centering JFrame’s
• By default, a Jframe is displayed in the upper-
left corner of the screen. To display a frame
at a specified location, you can use the
setLocation(x, y) method in the JFrame class.
This method places the upper-left corner of a
frame at location (x, y).
Class constructors
• JFrame()
Constructs a new frame that is initially
invisible.
• JFrame(String title)
Creates a new, initially invisible Frame with
the specified title.
JButton
• A button is a component the user clicks to
trigger a specific action. A Java application
can use several types of buttons, including
command buttons, checkboxes, toggle
buttons and radio buttons.
• all the button types are subclasses of
AbstractButton (package javax.swing), which
declares the common features of Swing
buttons.
Complete java swing
Buttons That Maintain State
• The Swing GUI components contain three
types of state buttons—JToggleButton,
• JCheckBox and JRadioButton—that have
on/off or true/false values. Classes
JCheckBox and JRadioButton are subclasses
of JToggleButton
JLabel
• A JLabel displays read-only text, an image, or
both text and an image.
JFileChooser
Allows the the user to choose a file
• import javax.swing.JFileChooser;
• public class swing_examples {
• public static void main(String args[])
• {
• JFileChooser fc = new JFileChooser();
• int returnVal = fc.showOpenDialog(null);
• if(returnVal == JFileChooser.APPROVE_OPTION)
• System.out.println("File: " + fc.getSelectedFile());
• }
• }
JCheckBox Class
• The class JCheckBox is an implementation of a
check box - an item that can be selected or
deselected, and which displays its state to the
user.
Class constructors
of JcheckBox
Complete java swing
Complete java swing
output
/*code for checkbox that display bold text*/
• font=new Font("",Font.BOLD,14);
• jTextField1.setFont(font);
• /*code for checkbox that display italic text*/
• font=new Font("",Font.ITALIC,14);
• jTextField1.setFont(font);
Complete java swing
Complete java swing
JRadio Button
• The class JRadioButton is an implementation
of a radio button - an item that can be
selected or deselected, and which displays its
state to the user.
Complete java swing
Mathematical Operations using Radio
Buttons
• private void
jButton1ActionPerformed(java.awt.event.Acti
onEvent evt) {
• jTextField1.setText("");
• jTextField2.setText("");
• jTextField3.setText("");
Addition RadioButton
• private void
jRadioButton1ActionPerformed(java.awt.event.A
ctionEvent evt) {
• int num1,num2,result;
• num1=Integer.parseInt(jTextField1.getText());
• num2=Integer.parseInt(jTextField2.getText());
• result=num1+num2;
• jTextField3.setText(String.valueOf(result));
Multiplication RadioButton
• private void
jRadioButton2ActionPerformed(java.awt.event.A
ctionEvent evt) {
• int num1,num2,result;
• num1=Integer.parseInt(jTextField1.getText());
• num2=Integer.parseInt(jTextField2.getText());
• result=num1*num2;
• jTextField3.setText(String.valueOf(result)); //
TODO add your handling code here:
• }
Subtraction RadioButton
• private void
jRadioButton3ActionPerformed(java.awt.event.A
ctionEvent evt) {
• int num1,num2,result;
• num1=Integer.parseInt(jTextField1.getText());
• num2=Integer.parseInt(jTextField2.getText());
• result=num1-num2;
• jTextField3.setText(String.valueOf(result)); //
TODO add your handling code here:
• }
Complete java swing
Complete java swing
Complete java swing

More Related Content

PPT
Java swing
PPTX
Chapter 1 swings
PDF
04b swing tutorial
PPTX
Swings in java
PPT
Basic using of Swing in Java
PPT
Java: GUI
PPT
Swing and AWT in java
Java swing
Chapter 1 swings
04b swing tutorial
Swings in java
Basic using of Swing in Java
Java: GUI
Swing and AWT in java

What's hot (20)

PPTX
Java- GUI- Mazenet solution
PPT
java swing
PPT
Awt and swing in java
PPT
Java Swing JFC
PDF
The AWT and Swing
PPT
Java swing
PPT
Graphical User Interface (GUI) - 1
PPTX
GUI components in Java
PPTX
tL19 awt
PPT
java2 swing
PPTX
Java swing
PPTX
Java swing
PDF
PDF
Java awt tutorial javatpoint
PPTX
PPT
Java Swing
PDF
swingbasics
PPTX
AWT Packages , Containers and Components
PPT
28 awt
PPT
GUI Programming In Java
Java- GUI- Mazenet solution
java swing
Awt and swing in java
Java Swing JFC
The AWT and Swing
Java swing
Graphical User Interface (GUI) - 1
GUI components in Java
tL19 awt
java2 swing
Java swing
Java swing
Java awt tutorial javatpoint
Java Swing
swingbasics
AWT Packages , Containers and Components
28 awt
GUI Programming In Java
Ad

Viewers also liked (18)

PPT
Clases de java swing
PPTX
Interfaces en Java
PPT
Chapter 14
PDF
Java swing
PPTX
Sdi & mdi
PDF
Introdução ao Java Swing (Interface)
PDF
Java interface gráfica swing
PDF
java swing tutorial for beginners(java programming tutorials)
PPT
java swing
PPTX
SWISS BULLION
DOC
Lki sistem perencanaan baru 2015
PPTX
Navegadores de internet
PPTX
MM PsychoTools Presentation
PDF
Nahha Annual report2015
PDF
Francis sewe onyango
PPTX
SWISS BULLION
PPTX
Updated Tables as of Aug.22, 2015
PPTX
Clases de java swing
Interfaces en Java
Chapter 14
Java swing
Sdi & mdi
Introdução ao Java Swing (Interface)
Java interface gráfica swing
java swing tutorial for beginners(java programming tutorials)
java swing
SWISS BULLION
Lki sistem perencanaan baru 2015
Navegadores de internet
MM PsychoTools Presentation
Nahha Annual report2015
Francis sewe onyango
SWISS BULLION
Updated Tables as of Aug.22, 2015
Ad

Similar to Complete java swing (20)

PPT
Swing basics
PPTX
Chap 1 - Introduction GUI.pptx
PPT
introduction to JAVA awt programmin .ppt
PPT
1.Abstract windowing toolkit.ppt of AJP sub
PPT
awt.ppt java windows programming lecture
PPT
fdtrdrtttxxxtrtrctctrttrdredrerrrrrrawt.ppt
PPT
awdrdtfffyfyfyfyfyfyfyfyfyfyfyfyyfyt.ppt
PPT
Unit 1- awt(Abstract Window Toolkit) .ppt
PPT
Java Swing Handson Session (1).ppt
PPTX
Chapter iv(modern gui)
PPT
2.swing.ppt advance java programming 3rd year
PDF
Java OOP Programming language (Part 7) - Swing
PPT
03_GUI.ppt
PPTX
GUI (graphical user interface)
PPT
13457272.ppt
PPT
Chapter 5 GUI for introduction of java and gui .ppt
PPTX
Java Swing Presentation made by aarav patel
PDF
11basic Swing
PPTX
Logic and Coding of Java Interfaces & Swing Applications
PPTX
SWING USING JAVA WITH VARIOUS COMPONENTS
Swing basics
Chap 1 - Introduction GUI.pptx
introduction to JAVA awt programmin .ppt
1.Abstract windowing toolkit.ppt of AJP sub
awt.ppt java windows programming lecture
fdtrdrtttxxxtrtrctctrttrdredrerrrrrrawt.ppt
awdrdtfffyfyfyfyfyfyfyfyfyfyfyfyyfyt.ppt
Unit 1- awt(Abstract Window Toolkit) .ppt
Java Swing Handson Session (1).ppt
Chapter iv(modern gui)
2.swing.ppt advance java programming 3rd year
Java OOP Programming language (Part 7) - Swing
03_GUI.ppt
GUI (graphical user interface)
13457272.ppt
Chapter 5 GUI for introduction of java and gui .ppt
Java Swing Presentation made by aarav patel
11basic Swing
Logic and Coding of Java Interfaces & Swing Applications
SWING USING JAVA WITH VARIOUS COMPONENTS

More from jehan1987 (7)

PPTX
Algorithm analysis (All in one)
PPTX
Artifitial intelligence (ai) all in one
PPTX
Java interfaces
PPTX
Java Thread & Multithreading
PPTX
Object oriented programming in C++
PPTX
Data structure and algorithm All in One
PPTX
Assessment of project management practices in pakistani software industry
Algorithm analysis (All in one)
Artifitial intelligence (ai) all in one
Java interfaces
Java Thread & Multithreading
Object oriented programming in C++
Data structure and algorithm All in One
Assessment of project management practices in pakistani software industry

Recently uploaded (20)

PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
Project quality management in manufacturing
PDF
PPT on Performance Review to get promotions
PPTX
web development for engineering and engineering
PPTX
additive manufacturing of ss316l using mig welding
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Well-logging-methods_new................
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Construction Project Organization Group 2.pptx
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Project quality management in manufacturing
PPT on Performance Review to get promotions
web development for engineering and engineering
additive manufacturing of ss316l using mig welding
R24 SURVEYING LAB MANUAL for civil enggi
Lecture Notes Electrical Wiring System Components
Foundation to blockchain - A guide to Blockchain Tech
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Embodied AI: Ushering in the Next Era of Intelligent Systems
Well-logging-methods_new................
UNIT 4 Total Quality Management .pptx
Sustainable Sites - Green Building Construction
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Construction Project Organization Group 2.pptx
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Model Code of Practice - Construction Work - 21102022 .pdf

Complete java swing

  • 2. • A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application. These are sometimes called controls or widgets—short for window gadgets. A GUI component is an object with which the user interacts via the mouse, the keyboard or another form of input, such as voice recognition. • Java’s so-called Swing GUI components from the javax.swing package. We cover other
  • 6. Simple GUI-Based Input/Output with JOptionPane • Most applications you use on a daily basis use windows or dialog boxes (also called dialogs) to interact with the user. For example, an e-mail program allows you to type and read messages in a window the program provides. Dialog boxes are windows in which programs display important messages to the user or obtain information from the user. Java’s JOptionPane class (package javax.swing) provides prebuilt dialog boxes for both input and output. These are displayed by invoking static JOptionPane methods. Program presents a simple addition application that uses two input dialogs to obtain integers from the user and a message dialog to display the sum of the integers the user enters.
  • 7. • // Addition.java • // Addition program that uses JOptionPane for input and output. • import javax.swing.JOptionPane; // program uses JOptionPane • public class Addition • { • public static void main( String[] args ) • { • // obtain user input from JOptionPane input dialogs • String firstNumber = • JOptionPane.showInputDialog( "Enter first integer" ); • String secondNumber = • JOptionPane.showInputDialog( "Enter second integer" );
  • 10. • private void jButton1ActionPerformed(java.awt.event.Acti onEvent evt) { • JOptionPane.showMessageDialog(null, "Thank you");// TODO add your handling code here: • }
  • 11. Overview of Swing Components
  • 16. Non-AWT Upgraded Components • In addition to offering replacements for all the basic AWT components, the Swing component • set includes twice as many new components.
  • 22. • package hello; • import javax.swing.*; • class jpswrd • { • public void Testing() • { • JPasswordField pwd = new JPasswordField(10); • int action = JOptionPane.showConfirmDialog(null, pwd,"Enter Password",JOptionPane.OK_CANCEL_OPTION); • if(action < 0)JOptionPane.showMessageDialog(null,"Cancel, X or escape key selected"); • else JOptionPane.showMessageDialog(null,"Your password is "+new String(pwd.getPassword())); • System.exit(0); • } • public static void main(String args[]) • {jpswrd p= new jpswrd(); • p.Testing();} • }
  • 24. • setEchoChar('+'); • Set character for password field.
  • 25. JFrame • A Frame is a top-level window with a title and a border. • Frame that adds support for the Swing component architecture.
  • 26. JFrame Features  It’s a window with title, border, (optional) menu bar and user-specified components. .It can be moved, resized, iconified. .It is not a subclass of JComponent. .Delegates responsibility of managing user- specified components to a content pane, an instance of JPanel.
  • 27. Centering JFrame’s • By default, a Jframe is displayed in the upper- left corner of the screen. To display a frame at a specified location, you can use the setLocation(x, y) method in the JFrame class. This method places the upper-left corner of a frame at location (x, y).
  • 28. Class constructors • JFrame() Constructs a new frame that is initially invisible. • JFrame(String title) Creates a new, initially invisible Frame with the specified title.
  • 29. JButton • A button is a component the user clicks to trigger a specific action. A Java application can use several types of buttons, including command buttons, checkboxes, toggle buttons and radio buttons.
  • 30. • all the button types are subclasses of AbstractButton (package javax.swing), which declares the common features of Swing buttons.
  • 32. Buttons That Maintain State • The Swing GUI components contain three types of state buttons—JToggleButton, • JCheckBox and JRadioButton—that have on/off or true/false values. Classes JCheckBox and JRadioButton are subclasses of JToggleButton
  • 33. JLabel • A JLabel displays read-only text, an image, or both text and an image.
  • 34. JFileChooser Allows the the user to choose a file • import javax.swing.JFileChooser; • public class swing_examples { • public static void main(String args[]) • { • JFileChooser fc = new JFileChooser(); • int returnVal = fc.showOpenDialog(null); • if(returnVal == JFileChooser.APPROVE_OPTION) • System.out.println("File: " + fc.getSelectedFile()); • } • }
  • 35. JCheckBox Class • The class JCheckBox is an implementation of a check box - an item that can be selected or deselected, and which displays its state to the user.
  • 40. /*code for checkbox that display bold text*/ • font=new Font("",Font.BOLD,14); • jTextField1.setFont(font); • /*code for checkbox that display italic text*/ • font=new Font("",Font.ITALIC,14); • jTextField1.setFont(font);
  • 43. JRadio Button • The class JRadioButton is an implementation of a radio button - an item that can be selected or deselected, and which displays its state to the user.
  • 45. Mathematical Operations using Radio Buttons • private void jButton1ActionPerformed(java.awt.event.Acti onEvent evt) { • jTextField1.setText(""); • jTextField2.setText(""); • jTextField3.setText("");
  • 46. Addition RadioButton • private void jRadioButton1ActionPerformed(java.awt.event.A ctionEvent evt) { • int num1,num2,result; • num1=Integer.parseInt(jTextField1.getText()); • num2=Integer.parseInt(jTextField2.getText()); • result=num1+num2; • jTextField3.setText(String.valueOf(result));
  • 47. Multiplication RadioButton • private void jRadioButton2ActionPerformed(java.awt.event.A ctionEvent evt) { • int num1,num2,result; • num1=Integer.parseInt(jTextField1.getText()); • num2=Integer.parseInt(jTextField2.getText()); • result=num1*num2; • jTextField3.setText(String.valueOf(result)); // TODO add your handling code here: • }
  • 48. Subtraction RadioButton • private void jRadioButton3ActionPerformed(java.awt.event.A ctionEvent evt) { • int num1,num2,result; • num1=Integer.parseInt(jTextField1.getText()); • num2=Integer.parseInt(jTextField2.getText()); • result=num1-num2; • jTextField3.setText(String.valueOf(result)); // TODO add your handling code here: • }