SlideShare a Scribd company logo
Showing the use of Panel and Event handling in Java
The class Assign1 is accessing Jpanel class and using ActionListener
interface to handle the events.
/*
* Name:
*/
importjavax.swing.*;
importjava.awt.event.*;
importjava.awt.*;
public class Assign1 extends JPanel implements ActionListener {
privateJTextField field1;
privateJTextField field2;
privateJTextField field3;
privateJButtonmergeButton;
public Assign1() {
JPaneltopPanel = new JPanel();
// create the panel to have two text fields
// as the input and one text field as the output
// when the button is clicked, the two input texts
// are merged together and displayed in the output field
JLabel label1 = new JLabel("String 1: ");
JLabel label2 = new JLabel("String 2: ");
JLabel label3 = new JLabel("Result: ");
this.field1 = new JTextField();
this.field2 = new JTextField();
this.field3 = new JTextField();
this.mergeButton = new JButton("Merge Strings");
this.field3.setEditable(false);
topPanel.setLayout(new GridLayout(3, 2));
topPanel.add(label1);
topPanel.add(field1);
topPanel.add(label2);
topPanel.add(field2);
topPanel.add(label3);
topPanel.add(field3);
topPanel.setPreferredSize(new Dimension(400, 90));
this.setLayout(new BorderLayout());
this.add(topPanel, BorderLayout.CENTER);
this.add(mergeButton, BorderLayout.SOUTH);
// add button event listener
this.mergeButton.addActionListener(this);
}
@Override
public void actionPerformed(ActionEventae) {
// merge two strings in the input fields
String text1 = this.field1.getText().trim();
String text2 = this.field2.getText().trim();
StringBuilder result = new StringBuilder();
int i = 0;
while (i < text1.length() && i < text2.length()) {
// add one from each string
result.append(text1.charAt(i));
result.append(text2.charAt(i));
i ++;
}
// add the remaining part
if (i < text1.length()) {
result.append(text1.substring(i));
}
if (i < text2.length()) {
result.append(text2.substring(i));
}
// display the result
this.field3.setText(result.toString());
}
public static void main(String[] args) {
// create a JFrame to display the panel
JFrame frame = new JFrame();
frame.setContentPane(new Assign1());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}

More Related Content

What's hot

Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindiappsdevelopment
 
Adding a action listener to button
Adding a action listener to buttonAdding a action listener to button
Adding a action listener to button
yugandhar vadlamudi
 
25 awt
25 awt25 awt
25 awt
degestive
 
GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)
rishi ram khanal
 
Ejercicio sql server vs visual .net
Ejercicio sql server vs visual .netEjercicio sql server vs visual .net
Ejercicio sql server vs visual .net
Ayuda Universidad
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
kirupasuchi1996
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solution
Mazenetsolution
 
Java awt tutorial javatpoint
Java awt tutorial   javatpointJava awt tutorial   javatpoint
Java awt tutorial javatpoint
Ricardo Garcia
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
arnold 7490
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
babak danyal
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
PRN USM
 
Ingles 2do parcial
Ingles   2do parcialIngles   2do parcial
Ingles 2do parcial
Harry Ostaiza
 
Vs c# lecture3
Vs c# lecture3Vs c# lecture3
Vs c# lecture3
Saman M. Almufti
 
State of the state
State of the stateState of the state
State of the state
Anton Korzunov
 
GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
Jussi Pohjolainen
 
Part 8 add,update,delete records using records operation buttons in vb.net
Part 8 add,update,delete records using records operation buttons in vb.netPart 8 add,update,delete records using records operation buttons in vb.net
Part 8 add,update,delete records using records operation buttons in vb.net
Girija Muscut
 
Balance de ingresos y egresos diarios de una persona
Balance de ingresos y egresos diarios de una personaBalance de ingresos y egresos diarios de una persona
Balance de ingresos y egresos diarios de una persona
David Xtremo
 

What's hot (17)

Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programming
 
Adding a action listener to button
Adding a action listener to buttonAdding a action listener to button
Adding a action listener to button
 
25 awt
25 awt25 awt
25 awt
 
GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)
 
Ejercicio sql server vs visual .net
Ejercicio sql server vs visual .netEjercicio sql server vs visual .net
Ejercicio sql server vs visual .net
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solution
 
Java awt tutorial javatpoint
Java awt tutorial   javatpointJava awt tutorial   javatpoint
Java awt tutorial javatpoint
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
 
Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
 
Ingles 2do parcial
Ingles   2do parcialIngles   2do parcial
Ingles 2do parcial
 
Vs c# lecture3
Vs c# lecture3Vs c# lecture3
Vs c# lecture3
 
State of the state
State of the stateState of the state
State of the state
 
GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
 
Part 8 add,update,delete records using records operation buttons in vb.net
Part 8 add,update,delete records using records operation buttons in vb.netPart 8 add,update,delete records using records operation buttons in vb.net
Part 8 add,update,delete records using records operation buttons in vb.net
 
Balance de ingresos y egresos diarios de una persona
Balance de ingresos y egresos diarios de una personaBalance de ingresos y egresos diarios de una persona
Balance de ingresos y egresos diarios de una persona
 

Viewers also liked

Java Assignment Help
Java Assignment HelpJava Assignment Help
Java Assignment Help
Programming Homeworks Help
 
Mantenimiento Preventivo
Mantenimiento PreventivoMantenimiento Preventivo
Mantenimiento Preventivo
aprotsa
 
Citacoes 150605162441-lva1-app6891
Citacoes 150605162441-lva1-app6891Citacoes 150605162441-lva1-app6891
Citacoes 150605162441-lva1-app6891
Juliano Alves
 
Math help
Math helpMath help
Math help
Sophia Mars
 
Software
SoftwareSoftware
Software
aprotsa
 
Charting-the-Seas_Electronic-Copy
Charting-the-Seas_Electronic-CopyCharting-the-Seas_Electronic-Copy
Charting-the-Seas_Electronic-Copy
Tyler Pry
 
C# Programming Help
C# Programming HelpC# Programming Help
C# Programming Help
Programming Homeworks Help
 
Docente nuevo paradigma 1
Docente nuevo paradigma 1Docente nuevo paradigma 1
Docente nuevo paradigma 1
Vilma St. Omer mujer celt
 
Hawk_s_Eye
Hawk_s_EyeHawk_s_Eye
Hawk_s_Eye
vivek bhusa
 
Intro del programa
Intro del programaIntro del programa
Intro del programa
Lourdesdejesus001
 
Conference Materials Indonesia perspective
Conference Materials Indonesia perspectiveConference Materials Indonesia perspective
Conference Materials Indonesia perspective
Hansel Kalama
 
Plataformas tecnologicas para la teleformacion
Plataformas tecnologicas para la teleformacionPlataformas tecnologicas para la teleformacion
Plataformas tecnologicas para la teleformacion
Lourdesdejesus001
 
ใบงานสำรวจตนเอง M6 แคท
ใบงานสำรวจตนเอง M6 แคทใบงานสำรวจตนเอง M6 แคท
ใบงานสำรวจตนเอง M6 แคท
meenkmn
 
Impact of the Presence of an Audit Committee on the Stock Market Performance ...
Impact of the Presence of an Audit Committee on the Stock Market Performance ...Impact of the Presence of an Audit Committee on the Stock Market Performance ...
Impact of the Presence of an Audit Committee on the Stock Market Performance ...
iapgroup
 
College essays
College essaysCollege essays
College essays
Sophia Mars
 
Client testimonials
Client testimonialsClient testimonials
Client testimonials
Sophia Mars
 

Viewers also liked (16)

Java Assignment Help
Java Assignment HelpJava Assignment Help
Java Assignment Help
 
Mantenimiento Preventivo
Mantenimiento PreventivoMantenimiento Preventivo
Mantenimiento Preventivo
 
Citacoes 150605162441-lva1-app6891
Citacoes 150605162441-lva1-app6891Citacoes 150605162441-lva1-app6891
Citacoes 150605162441-lva1-app6891
 
Math help
Math helpMath help
Math help
 
Software
SoftwareSoftware
Software
 
Charting-the-Seas_Electronic-Copy
Charting-the-Seas_Electronic-CopyCharting-the-Seas_Electronic-Copy
Charting-the-Seas_Electronic-Copy
 
C# Programming Help
C# Programming HelpC# Programming Help
C# Programming Help
 
Docente nuevo paradigma 1
Docente nuevo paradigma 1Docente nuevo paradigma 1
Docente nuevo paradigma 1
 
Hawk_s_Eye
Hawk_s_EyeHawk_s_Eye
Hawk_s_Eye
 
Intro del programa
Intro del programaIntro del programa
Intro del programa
 
Conference Materials Indonesia perspective
Conference Materials Indonesia perspectiveConference Materials Indonesia perspective
Conference Materials Indonesia perspective
 
Plataformas tecnologicas para la teleformacion
Plataformas tecnologicas para la teleformacionPlataformas tecnologicas para la teleformacion
Plataformas tecnologicas para la teleformacion
 
ใบงานสำรวจตนเอง M6 แคท
ใบงานสำรวจตนเอง M6 แคทใบงานสำรวจตนเอง M6 แคท
ใบงานสำรวจตนเอง M6 แคท
 
Impact of the Presence of an Audit Committee on the Stock Market Performance ...
Impact of the Presence of an Audit Committee on the Stock Market Performance ...Impact of the Presence of an Audit Committee on the Stock Market Performance ...
Impact of the Presence of an Audit Committee on the Stock Market Performance ...
 
College essays
College essaysCollege essays
College essays
 
Client testimonials
Client testimonialsClient testimonials
Client testimonials
 

Similar to Java Assignment Help

event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.ppt
usama537223
 
Ejemplos Interfaces Usuario 3
Ejemplos Interfaces Usuario 3Ejemplos Interfaces Usuario 3
Ejemplos Interfaces Usuario 3
martha leon
 
Class login
Class loginClass login
Class login
mdunge
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Google
 
Swing
SwingSwing
Swing
Nataraj Dg
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
Kuldeep Jain
 
ANSimport java.awt.event.;import javax.swing.; import java..pdf
ANSimport java.awt.event.;import javax.swing.; import java..pdfANSimport java.awt.event.;import javax.swing.; import java..pdf
ANSimport java.awt.event.;import javax.swing.; import java..pdf
anupambedcovers
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
sotlsoc
 
This program create a Java Frame with 5 rows of button with capti.pdf
 This program create a Java Frame with 5 rows of button with capti.pdf This program create a Java Frame with 5 rows of button with capti.pdf
This program create a Java Frame with 5 rows of button with capti.pdf
annamalaicells
 
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
udit652068
 
I hope the below code is helpful to you, please give me rewards.im.pdf
I hope the below code is helpful to you, please give me rewards.im.pdfI hope the below code is helpful to you, please give me rewards.im.pdf
I hope the below code is helpful to you, please give me rewards.im.pdf
apexelectronices01
 
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
widdowsonerica
 
Swing
SwingSwing
Write a program whose source file is named UnitProgl.java that do.pdf
Write a program whose source file is named UnitProgl.java that do.pdfWrite a program whose source file is named UnitProgl.java that do.pdf
Write a program whose source file is named UnitProgl.java that do.pdf
arihantcomputersddn
 
program for JRiddle.javapackage riddle;import javax.swing.; i.pdf
program for JRiddle.javapackage riddle;import javax.swing.; i.pdfprogram for JRiddle.javapackage riddle;import javax.swing.; i.pdf
program for JRiddle.javapackage riddle;import javax.swing.; i.pdf
annapurnnatextailes
 
ch20.pptx
ch20.pptxch20.pptx
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
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
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
Good657694
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
shanmuga rajan
 

Similar to Java Assignment Help (20)

event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.ppt
 
Ejemplos Interfaces Usuario 3
Ejemplos Interfaces Usuario 3Ejemplos Interfaces Usuario 3
Ejemplos Interfaces Usuario 3
 
Class login
Class loginClass login
Class login
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Swing
SwingSwing
Swing
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
ANSimport java.awt.event.;import javax.swing.; import java..pdf
ANSimport java.awt.event.;import javax.swing.; import java..pdfANSimport java.awt.event.;import javax.swing.; import java..pdf
ANSimport java.awt.event.;import javax.swing.; import java..pdf
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
This program create a Java Frame with 5 rows of button with capti.pdf
 This program create a Java Frame with 5 rows of button with capti.pdf This program create a Java Frame with 5 rows of button with capti.pdf
This program create a Java Frame with 5 rows of button with capti.pdf
 
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
 
I hope the below code is helpful to you, please give me rewards.im.pdf
I hope the below code is helpful to you, please give me rewards.im.pdfI hope the below code is helpful to you, please give me rewards.im.pdf
I hope the below code is helpful to you, please give me rewards.im.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
 
Swing
SwingSwing
Swing
 
Write a program whose source file is named UnitProgl.java that do.pdf
Write a program whose source file is named UnitProgl.java that do.pdfWrite a program whose source file is named UnitProgl.java that do.pdf
Write a program whose source file is named UnitProgl.java that do.pdf
 
program for JRiddle.javapackage riddle;import javax.swing.; i.pdf
program for JRiddle.javapackage riddle;import javax.swing.; i.pdfprogram for JRiddle.javapackage riddle;import javax.swing.; i.pdf
program for JRiddle.javapackage riddle;import javax.swing.; i.pdf
 
ch20.pptx
ch20.pptxch20.pptx
ch20.pptx
 
Java awt
Java awtJava awt
Java awt
 
Z blue introduction to gui (39023299)
Z blue   introduction to gui (39023299)Z blue   introduction to gui (39023299)
Z blue introduction to gui (39023299)
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 

Recently uploaded

What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 

Recently uploaded (20)

What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 

Java Assignment Help

  • 1.
  • 2. Showing the use of Panel and Event handling in Java The class Assign1 is accessing Jpanel class and using ActionListener interface to handle the events. /* * Name: */ importjavax.swing.*; importjava.awt.event.*; importjava.awt.*; public class Assign1 extends JPanel implements ActionListener { privateJTextField field1; privateJTextField field2; privateJTextField field3; privateJButtonmergeButton; public Assign1() { JPaneltopPanel = new JPanel(); // create the panel to have two text fields // as the input and one text field as the output // when the button is clicked, the two input texts // are merged together and displayed in the output field JLabel label1 = new JLabel("String 1: "); JLabel label2 = new JLabel("String 2: "); JLabel label3 = new JLabel("Result: "); this.field1 = new JTextField(); this.field2 = new JTextField(); this.field3 = new JTextField(); this.mergeButton = new JButton("Merge Strings"); this.field3.setEditable(false); topPanel.setLayout(new GridLayout(3, 2)); topPanel.add(label1); topPanel.add(field1); topPanel.add(label2); topPanel.add(field2); topPanel.add(label3); topPanel.add(field3); topPanel.setPreferredSize(new Dimension(400, 90)); this.setLayout(new BorderLayout()); this.add(topPanel, BorderLayout.CENTER); this.add(mergeButton, BorderLayout.SOUTH); // add button event listener this.mergeButton.addActionListener(this);
  • 3. } @Override public void actionPerformed(ActionEventae) { // merge two strings in the input fields String text1 = this.field1.getText().trim(); String text2 = this.field2.getText().trim(); StringBuilder result = new StringBuilder(); int i = 0; while (i < text1.length() && i < text2.length()) { // add one from each string result.append(text1.charAt(i)); result.append(text2.charAt(i)); i ++; } // add the remaining part if (i < text1.length()) { result.append(text1.substring(i)); } if (i < text2.length()) { result.append(text2.substring(i)); } // display the result this.field3.setText(result.toString()); } public static void main(String[] args) { // create a JFrame to display the panel JFrame frame = new JFrame(); frame.setContentPane(new Assign1()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }