SlideShare a Scribd company logo
1 of 4
Download to read offline
/* This program create a Java Frame with 5 rows of button with captioned image on each button
When user clicks on any of the button it shows the name of image that is used Label for Title of
the Java Frame is created as My Translator
Event handling is used with the help of actionlistner interface */
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Demo extends JFrame implements ActionListener
{
JFrame f;
JButton btn1,btn2,btn3,btn4,btn5;
Demo(){
f=new JFrame("My Translator"); //creating frame object
btn1=new JButton(new ImageIcon("rsc//a.jpg")); //creating button with image as caption
btn2=new JButton(new ImageIcon("rsc//b.jpg"));
btn3=new JButton(new ImageIcon("rsc//c.jpg"));
btn4=new JButton(new ImageIcon("rsc//d.jpg"));
btn5=new JButton(new ImageIcon("rsc//e.jpg"));
//adding button to actionlistener for even handling
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
btn4.addActionListener(this);
btn5.addActionListener(this);
//adding button to frame
f.add(btn1);f.add(btn2);f.add(btn3);f.add(btn4);f.add(btn5);
f.setLayout(new GridLayout(5,1));
//setting grid layout of 5 rows and 1 columns
f.setSize(300,300);
f.setVisible(true);
//Close the execution of Java Program if user close the screen
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae)
{
//managing event of click on button when a user click on any button it show image name that
is used to show on button
if(ae.getSource()==btn1)
JOptionPane.showMessageDialog( null,"A.JPG" );
if(ae.getSource()==btn2)
JOptionPane.showMessageDialog( null,"B.JPG" );
if(ae.getSource()==btn3)
JOptionPane.showMessageDialog( null,"C.JPG" );
if(ae.getSource()==btn4)
JOptionPane.showMessageDialog( null,"D.JPG" );
if(ae.getSource()==btn5)
JOptionPane.showMessageDialog( null,"E.JPG" );
}
public static void main(String[] args) {
new Demo();
}
}
Solution
/* This program create a Java Frame with 5 rows of button with captioned image on each button
When user clicks on any of the button it shows the name of image that is used Label for Title of
the Java Frame is created as My Translator
Event handling is used with the help of actionlistner interface */
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Demo extends JFrame implements ActionListener
{
JFrame f;
JButton btn1,btn2,btn3,btn4,btn5;
Demo(){
f=new JFrame("My Translator"); //creating frame object
btn1=new JButton(new ImageIcon("rsc//a.jpg")); //creating button with image as caption
btn2=new JButton(new ImageIcon("rsc//b.jpg"));
btn3=new JButton(new ImageIcon("rsc//c.jpg"));
btn4=new JButton(new ImageIcon("rsc//d.jpg"));
btn5=new JButton(new ImageIcon("rsc//e.jpg"));
//adding button to actionlistener for even handling
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
btn4.addActionListener(this);
btn5.addActionListener(this);
//adding button to frame
f.add(btn1);f.add(btn2);f.add(btn3);f.add(btn4);f.add(btn5);
f.setLayout(new GridLayout(5,1));
//setting grid layout of 5 rows and 1 columns
f.setSize(300,300);
f.setVisible(true);
//Close the execution of Java Program if user close the screen
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae)
{
//managing event of click on button when a user click on any button it show image name that
is used to show on button
if(ae.getSource()==btn1)
JOptionPane.showMessageDialog( null,"A.JPG" );
if(ae.getSource()==btn2)
JOptionPane.showMessageDialog( null,"B.JPG" );
if(ae.getSource()==btn3)
JOptionPane.showMessageDialog( null,"C.JPG" );
if(ae.getSource()==btn4)
JOptionPane.showMessageDialog( null,"D.JPG" );
if(ae.getSource()==btn5)
JOptionPane.showMessageDialog( null,"E.JPG" );
}
public static void main(String[] args) {
new Demo();
}
}

More Related Content

Similar to This program create a Java Frame with 5 rows of button with capti.pdf

Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892renuka gavli
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in javaAdil Mehmoood
 
event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.pptusama537223
 
Flash auto play image gallery
Flash auto play image galleryFlash auto play image gallery
Flash auto play image galleryBoy Jeorge
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfudit652068
 
Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1Muhammad Shebl Farag
 
Working with the Calculator program Once imported run the.pdf
Working with the Calculator program Once imported  run the.pdfWorking with the Calculator program Once imported  run the.pdf
Working with the Calculator program Once imported run the.pdficonsystemsslm
 
Assignment InstructionsInstructions Make sure you go t
Assignment InstructionsInstructions Make sure you go tAssignment InstructionsInstructions Make sure you go t
Assignment InstructionsInstructions Make sure you go twiddowsonerica
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in javaGoogle
 
Java Program Photo Viewer1. Write an app called viewer that will .pdf
Java Program Photo Viewer1. Write an app called viewer that will .pdfJava Program Photo Viewer1. Write an app called viewer that will .pdf
Java Program Photo Viewer1. Write an app called viewer that will .pdfbhim1213
 
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdfoptokunal1
 

Similar to This program create a Java Frame with 5 rows of button with capti.pdf (20)

Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892Swingpre 150616004959-lva1-app6892
Swingpre 150616004959-lva1-app6892
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
 
Program imageviewer
Program imageviewerProgram imageviewer
Program imageviewer
 
event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.ppt
 
Flash auto play image gallery
Flash auto play image galleryFlash auto play image gallery
Flash auto play image gallery
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Lecture 8.pdf
Lecture 8.pdfLecture 8.pdf
Lecture 8.pdf
 
ch20.pptx
ch20.pptxch20.pptx
ch20.pptx
 
GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
 
Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 
java2 swing
java2 swingjava2 swing
java2 swing
 
Working with the Calculator program Once imported run the.pdf
Working with the Calculator program Once imported  run the.pdfWorking with the Calculator program Once imported  run the.pdf
Working with the Calculator program Once imported run the.pdf
 
Assignment InstructionsInstructions Make sure you go t
Assignment InstructionsInstructions Make sure you go tAssignment InstructionsInstructions Make sure you go t
Assignment InstructionsInstructions Make sure you go t
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Java Program Photo Viewer1. Write an app called viewer that will .pdf
Java Program Photo Viewer1. Write an app called viewer that will .pdfJava Program Photo Viewer1. Write an app called viewer that will .pdf
Java Program Photo Viewer1. Write an app called viewer that will .pdf
 
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
 
Java Assignment Help
Java Assignment HelpJava Assignment Help
Java Assignment Help
 
GUI programming
GUI programmingGUI programming
GUI programming
 

More from annamalaicells

Volume = Integrate(0,2)[y]^2Volume = Integrate(0,2) Sin^2x^2.pdf
Volume = Integrate(0,2)[y]^2Volume = Integrate(0,2) Sin^2x^2.pdfVolume = Integrate(0,2)[y]^2Volume = Integrate(0,2) Sin^2x^2.pdf
Volume = Integrate(0,2)[y]^2Volume = Integrate(0,2) Sin^2x^2.pdfannamalaicells
 
validSolutionvalid.pdf
validSolutionvalid.pdfvalidSolutionvalid.pdf
validSolutionvalid.pdfannamalaicells
 
The transportation planning is considering a large denstial things l.pdf
The transportation planning is considering a large denstial things l.pdfThe transportation planning is considering a large denstial things l.pdf
The transportation planning is considering a large denstial things l.pdfannamalaicells
 
the feature that distinguish animals from organisms in other multice.pdf
the feature that distinguish animals from organisms in other multice.pdfthe feature that distinguish animals from organisms in other multice.pdf
the feature that distinguish animals from organisms in other multice.pdfannamalaicells
 
The above two expressions are work.SolutionThe above two expre.pdf
The above two expressions are work.SolutionThe above two expre.pdfThe above two expressions are work.SolutionThe above two expre.pdf
The above two expressions are work.SolutionThe above two expre.pdfannamalaicells
 
The Roman numeral is used in the Stock system of .pdf
                     The Roman numeral is used in the Stock system of .pdf                     The Roman numeral is used in the Stock system of .pdf
The Roman numeral is used in the Stock system of .pdfannamalaicells
 
The methylene protons in cyclopentadiene are acid.pdf
                     The methylene protons in cyclopentadiene are acid.pdf                     The methylene protons in cyclopentadiene are acid.pdf
The methylene protons in cyclopentadiene are acid.pdfannamalaicells
 
The answer is A When light elements fuse, they g.pdf
                     The answer is A  When light elements fuse, they g.pdf                     The answer is A  When light elements fuse, they g.pdf
The answer is A When light elements fuse, they g.pdfannamalaicells
 
The bond between C and C is a covalent bond but w.pdf
                     The bond between C and C is a covalent bond but w.pdf                     The bond between C and C is a covalent bond but w.pdf
The bond between C and C is a covalent bond but w.pdfannamalaicells
 
moles = molarity x volume volume of KCl = molesm.pdf
                     moles = molarity x volume volume of KCl = molesm.pdf                     moles = molarity x volume volume of KCl = molesm.pdf
moles = molarity x volume volume of KCl = molesm.pdfannamalaicells
 
Methyl group is electron releasing in nature ; it.pdf
                     Methyl group is electron releasing in nature ; it.pdf                     Methyl group is electron releasing in nature ; it.pdf
Methyl group is electron releasing in nature ; it.pdfannamalaicells
 
Hydronium ion concentration = S then S^2 = [4.07.pdf
                     Hydronium ion concentration = S then S^2 = [4.07.pdf                     Hydronium ion concentration = S then S^2 = [4.07.pdf
Hydronium ion concentration = S then S^2 = [4.07.pdfannamalaicells
 
Due to hydrogen bonding Quinizarin is a orange-re.pdf
                     Due to hydrogen bonding Quinizarin is a orange-re.pdf                     Due to hydrogen bonding Quinizarin is a orange-re.pdf
Due to hydrogen bonding Quinizarin is a orange-re.pdfannamalaicells
 
covalent radius increases from top to bottom and .pdf
                     covalent radius increases from top to bottom and .pdf                     covalent radius increases from top to bottom and .pdf
covalent radius increases from top to bottom and .pdfannamalaicells
 
Common Polar Solvents - water, methyl alcohol Co.pdf
                     Common Polar Solvents - water, methyl alcohol  Co.pdf                     Common Polar Solvents - water, methyl alcohol  Co.pdf
Common Polar Solvents - water, methyl alcohol Co.pdfannamalaicells
 
R is NOT reflexive since (c,c) doesnt belong to RR is symmetric si.pdf
R is NOT reflexive since (c,c) doesnt belong to RR is symmetric si.pdfR is NOT reflexive since (c,c) doesnt belong to RR is symmetric si.pdf
R is NOT reflexive since (c,c) doesnt belong to RR is symmetric si.pdfannamalaicells
 
Nasal cavity. Its mucus moistens the incoming air and traps dust. It.pdf
Nasal cavity. Its mucus moistens the incoming air and traps dust. It.pdfNasal cavity. Its mucus moistens the incoming air and traps dust. It.pdf
Nasal cavity. Its mucus moistens the incoming air and traps dust. It.pdfannamalaicells
 
Ican always help you )SolutionIcan always help you ).pdf
Ican always help you )SolutionIcan always help you ).pdfIcan always help you )SolutionIcan always help you ).pdf
Ican always help you )SolutionIcan always help you ).pdfannamalaicells
 
Geometry is one of the earliest branches of Mathematics to be discus.pdf
Geometry is one of the earliest branches of Mathematics to be discus.pdfGeometry is one of the earliest branches of Mathematics to be discus.pdf
Geometry is one of the earliest branches of Mathematics to be discus.pdfannamalaicells
 

More from annamalaicells (20)

Volume = Integrate(0,2)[y]^2Volume = Integrate(0,2) Sin^2x^2.pdf
Volume = Integrate(0,2)[y]^2Volume = Integrate(0,2) Sin^2x^2.pdfVolume = Integrate(0,2)[y]^2Volume = Integrate(0,2) Sin^2x^2.pdf
Volume = Integrate(0,2)[y]^2Volume = Integrate(0,2) Sin^2x^2.pdf
 
validSolutionvalid.pdf
validSolutionvalid.pdfvalidSolutionvalid.pdf
validSolutionvalid.pdf
 
The transportation planning is considering a large denstial things l.pdf
The transportation planning is considering a large denstial things l.pdfThe transportation planning is considering a large denstial things l.pdf
The transportation planning is considering a large denstial things l.pdf
 
the feature that distinguish animals from organisms in other multice.pdf
the feature that distinguish animals from organisms in other multice.pdfthe feature that distinguish animals from organisms in other multice.pdf
the feature that distinguish animals from organisms in other multice.pdf
 
The above two expressions are work.SolutionThe above two expre.pdf
The above two expressions are work.SolutionThe above two expre.pdfThe above two expressions are work.SolutionThe above two expre.pdf
The above two expressions are work.SolutionThe above two expre.pdf
 
The Roman numeral is used in the Stock system of .pdf
                     The Roman numeral is used in the Stock system of .pdf                     The Roman numeral is used in the Stock system of .pdf
The Roman numeral is used in the Stock system of .pdf
 
The methylene protons in cyclopentadiene are acid.pdf
                     The methylene protons in cyclopentadiene are acid.pdf                     The methylene protons in cyclopentadiene are acid.pdf
The methylene protons in cyclopentadiene are acid.pdf
 
The answer is A When light elements fuse, they g.pdf
                     The answer is A  When light elements fuse, they g.pdf                     The answer is A  When light elements fuse, they g.pdf
The answer is A When light elements fuse, they g.pdf
 
The bond between C and C is a covalent bond but w.pdf
                     The bond between C and C is a covalent bond but w.pdf                     The bond between C and C is a covalent bond but w.pdf
The bond between C and C is a covalent bond but w.pdf
 
none Sol.pdf
                     none                                      Sol.pdf                     none                                      Sol.pdf
none Sol.pdf
 
moles = molarity x volume volume of KCl = molesm.pdf
                     moles = molarity x volume volume of KCl = molesm.pdf                     moles = molarity x volume volume of KCl = molesm.pdf
moles = molarity x volume volume of KCl = molesm.pdf
 
Methyl group is electron releasing in nature ; it.pdf
                     Methyl group is electron releasing in nature ; it.pdf                     Methyl group is electron releasing in nature ; it.pdf
Methyl group is electron releasing in nature ; it.pdf
 
Hydronium ion concentration = S then S^2 = [4.07.pdf
                     Hydronium ion concentration = S then S^2 = [4.07.pdf                     Hydronium ion concentration = S then S^2 = [4.07.pdf
Hydronium ion concentration = S then S^2 = [4.07.pdf
 
Due to hydrogen bonding Quinizarin is a orange-re.pdf
                     Due to hydrogen bonding Quinizarin is a orange-re.pdf                     Due to hydrogen bonding Quinizarin is a orange-re.pdf
Due to hydrogen bonding Quinizarin is a orange-re.pdf
 
covalent radius increases from top to bottom and .pdf
                     covalent radius increases from top to bottom and .pdf                     covalent radius increases from top to bottom and .pdf
covalent radius increases from top to bottom and .pdf
 
Common Polar Solvents - water, methyl alcohol Co.pdf
                     Common Polar Solvents - water, methyl alcohol  Co.pdf                     Common Polar Solvents - water, methyl alcohol  Co.pdf
Common Polar Solvents - water, methyl alcohol Co.pdf
 
R is NOT reflexive since (c,c) doesnt belong to RR is symmetric si.pdf
R is NOT reflexive since (c,c) doesnt belong to RR is symmetric si.pdfR is NOT reflexive since (c,c) doesnt belong to RR is symmetric si.pdf
R is NOT reflexive since (c,c) doesnt belong to RR is symmetric si.pdf
 
Nasal cavity. Its mucus moistens the incoming air and traps dust. It.pdf
Nasal cavity. Its mucus moistens the incoming air and traps dust. It.pdfNasal cavity. Its mucus moistens the incoming air and traps dust. It.pdf
Nasal cavity. Its mucus moistens the incoming air and traps dust. It.pdf
 
Ican always help you )SolutionIcan always help you ).pdf
Ican always help you )SolutionIcan always help you ).pdfIcan always help you )SolutionIcan always help you ).pdf
Ican always help you )SolutionIcan always help you ).pdf
 
Geometry is one of the earliest branches of Mathematics to be discus.pdf
Geometry is one of the earliest branches of Mathematics to be discus.pdfGeometry is one of the earliest branches of Mathematics to be discus.pdf
Geometry is one of the earliest branches of Mathematics to be discus.pdf
 

Recently uploaded

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...Nguyen Thanh Tu Collection
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsISCOPE Publication
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 

Recently uploaded (20)

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS Publications
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 

This program create a Java Frame with 5 rows of button with capti.pdf

  • 1. /* This program create a Java Frame with 5 rows of button with captioned image on each button When user clicks on any of the button it shows the name of image that is used Label for Title of the Java Frame is created as My Translator Event handling is used with the help of actionlistner interface */ import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Demo extends JFrame implements ActionListener { JFrame f; JButton btn1,btn2,btn3,btn4,btn5; Demo(){ f=new JFrame("My Translator"); //creating frame object btn1=new JButton(new ImageIcon("rsc//a.jpg")); //creating button with image as caption btn2=new JButton(new ImageIcon("rsc//b.jpg")); btn3=new JButton(new ImageIcon("rsc//c.jpg")); btn4=new JButton(new ImageIcon("rsc//d.jpg")); btn5=new JButton(new ImageIcon("rsc//e.jpg")); //adding button to actionlistener for even handling btn1.addActionListener(this); btn2.addActionListener(this); btn3.addActionListener(this); btn4.addActionListener(this); btn5.addActionListener(this); //adding button to frame f.add(btn1);f.add(btn2);f.add(btn3);f.add(btn4);f.add(btn5); f.setLayout(new GridLayout(5,1)); //setting grid layout of 5 rows and 1 columns
  • 2. f.setSize(300,300); f.setVisible(true); //Close the execution of Java Program if user close the screen f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent ae) { //managing event of click on button when a user click on any button it show image name that is used to show on button if(ae.getSource()==btn1) JOptionPane.showMessageDialog( null,"A.JPG" ); if(ae.getSource()==btn2) JOptionPane.showMessageDialog( null,"B.JPG" ); if(ae.getSource()==btn3) JOptionPane.showMessageDialog( null,"C.JPG" ); if(ae.getSource()==btn4) JOptionPane.showMessageDialog( null,"D.JPG" ); if(ae.getSource()==btn5) JOptionPane.showMessageDialog( null,"E.JPG" ); } public static void main(String[] args) { new Demo(); } } Solution /* This program create a Java Frame with 5 rows of button with captioned image on each button When user clicks on any of the button it shows the name of image that is used Label for Title of the Java Frame is created as My Translator Event handling is used with the help of actionlistner interface */ import java.awt.*; import javax.swing.*; import java.awt.event.*;
  • 3. public class Demo extends JFrame implements ActionListener { JFrame f; JButton btn1,btn2,btn3,btn4,btn5; Demo(){ f=new JFrame("My Translator"); //creating frame object btn1=new JButton(new ImageIcon("rsc//a.jpg")); //creating button with image as caption btn2=new JButton(new ImageIcon("rsc//b.jpg")); btn3=new JButton(new ImageIcon("rsc//c.jpg")); btn4=new JButton(new ImageIcon("rsc//d.jpg")); btn5=new JButton(new ImageIcon("rsc//e.jpg")); //adding button to actionlistener for even handling btn1.addActionListener(this); btn2.addActionListener(this); btn3.addActionListener(this); btn4.addActionListener(this); btn5.addActionListener(this); //adding button to frame f.add(btn1);f.add(btn2);f.add(btn3);f.add(btn4);f.add(btn5); f.setLayout(new GridLayout(5,1)); //setting grid layout of 5 rows and 1 columns f.setSize(300,300); f.setVisible(true); //Close the execution of Java Program if user close the screen f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent ae) { //managing event of click on button when a user click on any button it show image name that is used to show on button if(ae.getSource()==btn1)
  • 4. JOptionPane.showMessageDialog( null,"A.JPG" ); if(ae.getSource()==btn2) JOptionPane.showMessageDialog( null,"B.JPG" ); if(ae.getSource()==btn3) JOptionPane.showMessageDialog( null,"C.JPG" ); if(ae.getSource()==btn4) JOptionPane.showMessageDialog( null,"D.JPG" ); if(ae.getSource()==btn5) JOptionPane.showMessageDialog( null,"E.JPG" ); } public static void main(String[] args) { new Demo(); } }