SlideShare ist ein Scribd-Unternehmen logo
1 von 51
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
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" );
• private void
jButton1ActionPerformed(java.awt.event.Acti
onEvent evt) {
• JOptionPane.showMessageDialog(null, "Thank
you");// TODO add your handling code here:
• }
Overview of Swing Components
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.
• 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.
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
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);
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.
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

Weitere ähnliche Inhalte

Was ist angesagt?

Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solutionMazenetsolution
 
Java Swing JFC
Java Swing JFCJava Swing JFC
Java Swing JFCSunil OS
 
The AWT and Swing
The AWT and SwingThe AWT and Swing
The AWT and Swingadil raja
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1PRN USM
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Javakirupasuchi1996
 
tL19 awt
tL19 awttL19 awt
tL19 awtteach4uin
 
Java awt tutorial javatpoint
Java awt tutorial   javatpointJava awt tutorial   javatpoint
Java awt tutorial javatpointRicardo Garcia
 
Java Swing
Java SwingJava Swing
Java SwingShraddha
 
AWT Packages , Containers and Components
AWT Packages , Containers and ComponentsAWT Packages , Containers and Components
AWT Packages , Containers and ComponentsSohanur63
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Javayht4ever
 

Was ist angesagt? (20)

Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solution
 
java swing
java swingjava swing
java swing
 
Awt and swing in java
Awt and swing in javaAwt and swing in java
Awt and swing in java
 
Java Swing JFC
Java Swing JFCJava Swing JFC
Java Swing JFC
 
The AWT and Swing
The AWT and SwingThe AWT and Swing
The AWT and Swing
 
Java swing
Java swingJava swing
Java swing
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 
tL19 awt
tL19 awttL19 awt
tL19 awt
 
java2 swing
java2 swingjava2 swing
java2 swing
 
Java swing
Java swingJava swing
Java swing
 
Java swing
Java swingJava swing
Java swing
 
Gui
GuiGui
Gui
 
Java awt tutorial javatpoint
Java awt tutorial   javatpointJava awt tutorial   javatpoint
Java awt tutorial javatpoint
 
Swings
SwingsSwings
Swings
 
Java Swing
Java SwingJava Swing
Java Swing
 
swingbasics
swingbasicsswingbasics
swingbasics
 
AWT Packages , Containers and Components
AWT Packages , Containers and ComponentsAWT Packages , Containers and Components
AWT Packages , Containers and Components
 
28 awt
28 awt28 awt
28 awt
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
 

Andere mochten auch

Clases de java swing
Clases de java swingClases de java swing
Clases de java swingdaaaaniela99
 
Chapter 14
Chapter 14Chapter 14
Chapter 14Terry Yoast
 
Java swing
Java swingJava swing
Java swingTiago
 
Sdi & mdi
Sdi & mdiSdi & mdi
Sdi & mdiBABAVALI S
 
Introdução ao Java Swing (Interface)
Introdução ao Java Swing (Interface)Introdução ao Java Swing (Interface)
Introdução ao Java Swing (Interface)Sérgio Souza Costa
 
Java interface gráfica swing
Java   interface gráfica swingJava   interface gráfica swing
Java interface gráfica swingArmando Daniel
 
java swing
java swingjava swing
java swingvannarith
 
SWISS BULLION
SWISS BULLIONSWISS BULLION
SWISS BULLIONYesh Lazarte
 
Lki sistem perencanaan baru 2015
Lki sistem  perencanaan baru 2015Lki sistem  perencanaan baru 2015
Lki sistem perencanaan baru 2015lkibandung
 
Navegadores de internet
Navegadores de internetNavegadores de internet
Navegadores de internetcrecenciojacinto
 
MM PsychoTools Presentation
MM PsychoTools PresentationMM PsychoTools Presentation
MM PsychoTools Presentationkenneth mashele
 
Nahha Annual report2015
Nahha Annual report2015Nahha Annual report2015
Nahha Annual report2015iHawaiidigital
 
Francis sewe onyango
Francis sewe onyangoFrancis sewe onyango
Francis sewe onyangoFranc Sewe
 
SWISS BULLION
SWISS BULLIONSWISS BULLION
SWISS BULLIONYesh Lazarte
 
Updated Tables as of Aug.22, 2015
Updated Tables as of Aug.22, 2015Updated Tables as of Aug.22, 2015
Updated Tables as of Aug.22, 2015Yesh Lazarte
 

Andere mochten auch (18)

Clases de java swing
Clases de java swingClases de java swing
Clases de java swing
 
Interfaces en Java
Interfaces en JavaInterfaces en Java
Interfaces en Java
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Java swing
Java swingJava swing
Java swing
 
Sdi & mdi
Sdi & mdiSdi & mdi
Sdi & mdi
 
Introdução ao Java Swing (Interface)
Introdução ao Java Swing (Interface)Introdução ao Java Swing (Interface)
Introdução ao Java Swing (Interface)
 
Java interface gráfica swing
Java   interface gráfica swingJava   interface gráfica swing
Java interface gráfica swing
 
java swing tutorial for beginners(java programming tutorials)
java swing tutorial for beginners(java programming tutorials)java swing tutorial for beginners(java programming tutorials)
java swing tutorial for beginners(java programming tutorials)
 
java swing
java swingjava swing
java swing
 
SWISS BULLION
SWISS BULLIONSWISS BULLION
SWISS BULLION
 
Lki sistem perencanaan baru 2015
Lki sistem  perencanaan baru 2015Lki sistem  perencanaan baru 2015
Lki sistem perencanaan baru 2015
 
Navegadores de internet
Navegadores de internetNavegadores de internet
Navegadores de internet
 
MM PsychoTools Presentation
MM PsychoTools PresentationMM PsychoTools Presentation
MM PsychoTools Presentation
 
Nahha Annual report2015
Nahha Annual report2015Nahha Annual report2015
Nahha Annual report2015
 
Francis sewe onyango
Francis sewe onyangoFrancis sewe onyango
Francis sewe onyango
 
SWISS BULLION
SWISS BULLIONSWISS BULLION
SWISS BULLION
 
Updated Tables as of Aug.22, 2015
Updated Tables as of Aug.22, 2015Updated Tables as of Aug.22, 2015
Updated Tables as of Aug.22, 2015
 
Abortion
AbortionAbortion
Abortion
 

Ă„hnlich wie Complete java swing

Chap 1 - Introduction GUI.pptx
Chap 1 - Introduction GUI.pptxChap 1 - Introduction GUI.pptx
Chap 1 - Introduction GUI.pptxTadeseBeyene
 
Java Swing Handson Session (1).ppt
Java Swing Handson Session (1).pptJava Swing Handson Session (1).ppt
Java Swing Handson Session (1).pptssuser076380
 
Chapter iv(modern gui)
Chapter iv(modern gui)Chapter iv(modern gui)
Chapter iv(modern gui)Chhom Karath
 
Java OOP Programming language (Part 7) - Swing
Java OOP Programming language (Part 7) - SwingJava OOP Programming language (Part 7) - Swing
Java OOP Programming language (Part 7) - SwingOUM SAOKOSAL
 
GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)rishi ram khanal
 
11basic Swing
11basic Swing11basic Swing
11basic SwingAdil Jafri
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applicationskjkleindorfer
 
SWING USING JAVA WITH VARIOUS COMPONENTS
SWING USING  JAVA WITH VARIOUS COMPONENTSSWING USING  JAVA WITH VARIOUS COMPONENTS
SWING USING JAVA WITH VARIOUS COMPONENTSbharathiv53
 
Z blue introduction to gui (39023299)
Z blue   introduction to gui (39023299)Z blue   introduction to gui (39023299)
Z blue introduction to gui (39023299)Narayana Swamy
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)Bilal Amjad
 
object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examplesAbdii Rashid
 
The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorialsumitjoshi01
 

Ă„hnlich wie Complete java swing (20)

Swing basics
Swing basicsSwing basics
Swing basics
 
Chap 1 - Introduction GUI.pptx
Chap 1 - Introduction GUI.pptxChap 1 - Introduction GUI.pptx
Chap 1 - Introduction GUI.pptx
 
Java Swing Handson Session (1).ppt
Java Swing Handson Session (1).pptJava Swing Handson Session (1).ppt
Java Swing Handson Session (1).ppt
 
Chapter iv(modern gui)
Chapter iv(modern gui)Chapter iv(modern gui)
Chapter iv(modern gui)
 
Java OOP Programming language (Part 7) - Swing
Java OOP Programming language (Part 7) - SwingJava OOP Programming language (Part 7) - Swing
Java OOP Programming language (Part 7) - Swing
 
03_GUI.ppt
03_GUI.ppt03_GUI.ppt
03_GUI.ppt
 
GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)
 
13457272.ppt
13457272.ppt13457272.ppt
13457272.ppt
 
11basic Swing
11basic Swing11basic Swing
11basic Swing
 
Logic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing ApplicationsLogic and Coding of Java Interfaces & Swing Applications
Logic and Coding of Java Interfaces & Swing Applications
 
SWING USING JAVA WITH VARIOUS COMPONENTS
SWING USING  JAVA WITH VARIOUS COMPONENTSSWING USING  JAVA WITH VARIOUS COMPONENTS
SWING USING JAVA WITH VARIOUS COMPONENTS
 
Basic swing
Basic swingBasic swing
Basic swing
 
Z blue introduction to gui (39023299)
Z blue   introduction to gui (39023299)Z blue   introduction to gui (39023299)
Z blue introduction to gui (39023299)
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)
 
14a-gui.ppt
14a-gui.ppt14a-gui.ppt
14a-gui.ppt
 
object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
 
The java swing_tutorial
The java swing_tutorialThe java swing_tutorial
The java swing_tutorial
 
The java rogramming swing _tutorial for beinners(java programming language)
The java rogramming swing _tutorial for beinners(java programming language)The java rogramming swing _tutorial for beinners(java programming language)
The java rogramming swing _tutorial for beinners(java programming language)
 
swings.pptx
swings.pptxswings.pptx
swings.pptx
 
17625-1.pptx
17625-1.pptx17625-1.pptx
17625-1.pptx
 

Mehr von jehan1987

Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)jehan1987
 
Artifitial intelligence (ai) all in one
Artifitial intelligence (ai) all in oneArtifitial intelligence (ai) all in one
Artifitial intelligence (ai) all in onejehan1987
 
Java interfaces
Java interfacesJava interfaces
Java interfacesjehan1987
 
Java Thread & Multithreading
Java Thread & MultithreadingJava Thread & Multithreading
Java Thread & Multithreadingjehan1987
 
Object oriented programming in C++
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++jehan1987
 
Data structure and algorithm All in One
Data structure and algorithm All in OneData structure and algorithm All in One
Data structure and algorithm All in Onejehan1987
 
Assessment of project management practices in pakistani software industry
Assessment of project management practices in pakistani software industryAssessment of project management practices in pakistani software industry
Assessment of project management practices in pakistani software industryjehan1987
 

Mehr von jehan1987 (7)

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

KĂĽrzlich hochgeladen

Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdfCaalaaAbdulkerim
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESNarmatha D
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 

KĂĽrzlich hochgeladen (20)

Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdf
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIES
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 

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
  • 3.
  • 4.
  • 5.
  • 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" );
  • 8.
  • 9.
  • 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
  • 12.
  • 13.
  • 14.
  • 15.
  • 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.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 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.
  • 31.
  • 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.
  • 37.
  • 38.
  • 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);
  • 41.
  • 42.
  • 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.
  • 44.
  • 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: • }