SlideShare a Scribd company logo
Write a program whose source file is named "UnitProgl.java" that does the following: Creates
a frame with a GridLayout Manager Creates two panels and adds them to the frame, stacked one
over the other. In each panel creates three buttons, side by side. The buttons should be labeled
"Button 1", "Button 2", "Button 3", "Button 4", "Button 5" and "Button 6". Displays this
GUI when run. The only buttons that actually works will be the buttons on the window title bar:
minimize, maximize and the exit button in the upper right hand corner of the programs window.
Part 2 - Event Driven Programming Write a program whose source file is named
"UnitProg2.java". Do the following: Start by copying the program code from part 1 and
modifying it. This program will have a GUI that looks just like the previous one. The goal is to
make the JButtons work. Add code to handle the events when the user presses any of the six
buttons on the GUI. When the user presses a button simply write out to the console "The user
pressed Button X", where "X" is the number of the button. For example, when "Button 2" is
pressed the message written to the console should be "The user pressed Button 2.".
Solution
UnitProg1.java
import java.awt.*;
import javax.swing.*;
public class UnitProg1 {
private JFrame mainFrame;
private JPanel controlPanel;
private JPanel controlPanel1;
public UnitProg1(){
prepareGUI();
}
public static void main(String[] args){
UnitProg1 prog1 = new UnitProg1();
}
private void prepareGUI(){
mainFrame = new JFrame("UnitProg1");
mainFrame.setSize(400,400);
mainFrame.setLayout(new GridLayout(2,1));
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel1=new JPanel(new FlowLayout());
JButton button1=new JButton("Button1");
JButton button2=new JButton("Button2");
JButton button3=new JButton("Button3");
JButton button4=new JButton("Button4");
JButton button5=new JButton("Button5");
JButton button6=new JButton("Button6");
controlPanel.add(button1, controlPanel);
controlPanel.add(button2, controlPanel);
controlPanel.add(button3, controlPanel);
controlPanel1.add(button4, controlPanel1);
controlPanel1.add(button5, controlPanel1);
controlPanel1.add(button6, controlPanel1);
mainFrame.add(controlPanel);
mainFrame.add(controlPanel1);
mainFrame.setVisible(true);
}
}
UnitProg2.java
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;
public class UnitProg2 {
private JFrame mainFrame;
private JPanel controlPanel;
private JPanel controlPanel1;
public UnitProg2(){
prepareGUI();
}
public static void main(String[] args){
UnitProg2 prog2 = new UnitProg2();
}
private void prepareGUI(){
mainFrame = new JFrame("UnitProg2");
mainFrame.setSize(400,400);
mainFrame.setLayout(new GridLayout(2, 1));
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel1=new JPanel(new FlowLayout());
JButton button1=new JButton("Button1");
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("The user pressed Button 1");
}
});
JButton button2=new JButton("Button2");
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("The user pressed Button 2");
}
});
JButton button3=new JButton("Button3");
button3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("The user pressed Button 3");
}
});
JButton button4=new JButton("Button4");
button4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("The user pressed Button 4");
}
});
JButton button5=new JButton("Button5");
button5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("The user pressed Button 5");
}
});
JButton button6=new JButton("Button6");
button6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.out.println("The user pressed Button 6");
}
});
controlPanel.add(button1, controlPanel);
controlPanel.add(button2, controlPanel);
controlPanel.add(button3, controlPanel);
controlPanel1.add(button4, controlPanel1);
controlPanel1.add(button5, controlPanel1);
controlPanel1.add(button6, controlPanel1);
mainFrame.add(controlPanel);
mainFrame.add(controlPanel1);
mainFrame.setVisible(true);
}
}

More Related Content

Similar to Write a program whose source file is named UnitProgl.java that do.pdf

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
Muhammad Shebl Farag
 
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
optokunal1
 
14a-gui.ppt
14a-gui.ppt14a-gui.ppt
14a-gui.ppt
DrDGayathriDevi
 
ch20.pptx
ch20.pptxch20.pptx
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
 
Swing
SwingSwing
Swing
Nataraj Dg
 
intro_gui
intro_guiintro_gui
intro_gui
filipb2
 
Programming Without Coding Technology (PWCT) - Simple GUI Application
Programming Without Coding Technology (PWCT) - Simple GUI ApplicationProgramming Without Coding Technology (PWCT) - Simple GUI Application
Programming Without Coding Technology (PWCT) - Simple GUI Application
Mahmoud Samir Fayed
 
03_GUI.ppt
03_GUI.ppt03_GUI.ppt
03_GUI.ppt
DrDGayathriDevi
 
Introduction
IntroductionIntroduction
I need help creating a java gui that draws lines, shapes, characters.pdf
I need help creating a java gui that draws lines, shapes, characters.pdfI need help creating a java gui that draws lines, shapes, characters.pdf
I need help creating a java gui that draws lines, shapes, characters.pdf
ezhilvizhiyan
 
step by step to write a gnome-shell extension
step by step to write a gnome-shell extension step by step to write a gnome-shell extension
step by step to write a gnome-shell extension
Yuren Ju
 
Program klik sederhana
Program klik sederhanaProgram klik sederhana
Program klik sederhana
Henfry Kai
 
Ingles 2do parcial
Ingles   2do parcialIngles   2do parcial
Ingles 2do parcial
Harry Ostaiza
 
The Ring programming language version 1.7 book - Part 76 of 196
The Ring programming language version 1.7 book - Part 76 of 196The Ring programming language version 1.7 book - Part 76 of 196
The Ring programming language version 1.7 book - Part 76 of 196
Mahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Spinner control
Programming Without Coding Technology (PWCT) - Spinner controlProgramming Without Coding Technology (PWCT) - Spinner control
Programming Without Coding Technology (PWCT) - Spinner control
Mahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Image control
Programming Without Coding Technology (PWCT) - Image controlProgramming Without Coding Technology (PWCT) - Image control
Programming Without Coding Technology (PWCT) - Image control
Mahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Progressbar control
Programming Without Coding Technology (PWCT) - Progressbar controlProgramming Without Coding Technology (PWCT) - Progressbar control
Programming Without Coding Technology (PWCT) - Progressbar control
Mahmoud Samir Fayed
 
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
 
Programming Without Coding Technology (PWCT) - Grid control
Programming Without Coding Technology (PWCT) - Grid controlProgramming Without Coding Technology (PWCT) - Grid control
Programming Without Coding Technology (PWCT) - Grid control
Mahmoud Samir Fayed
 

Similar to Write a program whose source file is named UnitProgl.java that do.pdf (20)

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
 
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
 
14a-gui.ppt
14a-gui.ppt14a-gui.ppt
14a-gui.ppt
 
ch20.pptx
ch20.pptxch20.pptx
ch20.pptx
 
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
 
Swing
SwingSwing
Swing
 
intro_gui
intro_guiintro_gui
intro_gui
 
Programming Without Coding Technology (PWCT) - Simple GUI Application
Programming Without Coding Technology (PWCT) - Simple GUI ApplicationProgramming Without Coding Technology (PWCT) - Simple GUI Application
Programming Without Coding Technology (PWCT) - Simple GUI Application
 
03_GUI.ppt
03_GUI.ppt03_GUI.ppt
03_GUI.ppt
 
Introduction
IntroductionIntroduction
Introduction
 
I need help creating a java gui that draws lines, shapes, characters.pdf
I need help creating a java gui that draws lines, shapes, characters.pdfI need help creating a java gui that draws lines, shapes, characters.pdf
I need help creating a java gui that draws lines, shapes, characters.pdf
 
step by step to write a gnome-shell extension
step by step to write a gnome-shell extension step by step to write a gnome-shell extension
step by step to write a gnome-shell extension
 
Program klik sederhana
Program klik sederhanaProgram klik sederhana
Program klik sederhana
 
Ingles 2do parcial
Ingles   2do parcialIngles   2do parcial
Ingles 2do parcial
 
The Ring programming language version 1.7 book - Part 76 of 196
The Ring programming language version 1.7 book - Part 76 of 196The Ring programming language version 1.7 book - Part 76 of 196
The Ring programming language version 1.7 book - Part 76 of 196
 
Programming Without Coding Technology (PWCT) - Spinner control
Programming Without Coding Technology (PWCT) - Spinner controlProgramming Without Coding Technology (PWCT) - Spinner control
Programming Without Coding Technology (PWCT) - Spinner control
 
Programming Without Coding Technology (PWCT) - Image control
Programming Without Coding Technology (PWCT) - Image controlProgramming Without Coding Technology (PWCT) - Image control
Programming Without Coding Technology (PWCT) - Image control
 
Programming Without Coding Technology (PWCT) - Progressbar control
Programming Without Coding Technology (PWCT) - Progressbar controlProgramming Without Coding Technology (PWCT) - Progressbar control
Programming Without Coding Technology (PWCT) - Progressbar control
 
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
 
Programming Without Coding Technology (PWCT) - Grid control
Programming Without Coding Technology (PWCT) - Grid controlProgramming Without Coding Technology (PWCT) - Grid control
Programming Without Coding Technology (PWCT) - Grid control
 

More from arihantcomputersddn

write an assemblyprogram that uses indirect addressing to switch the.pdf
write an assemblyprogram that uses indirect addressing to switch the.pdfwrite an assemblyprogram that uses indirect addressing to switch the.pdf
write an assemblyprogram that uses indirect addressing to switch the.pdf
arihantcomputersddn
 
Why is there no blood supply that extends into the epidermis Than.pdf
Why is there no blood supply that extends into the epidermis Than.pdfWhy is there no blood supply that extends into the epidermis Than.pdf
Why is there no blood supply that extends into the epidermis Than.pdf
arihantcomputersddn
 
Which of the following protocols was developed in the mid-1970s for .pdf
Which of the following protocols was developed in the mid-1970s for .pdfWhich of the following protocols was developed in the mid-1970s for .pdf
Which of the following protocols was developed in the mid-1970s for .pdf
arihantcomputersddn
 
Which of the following is an weak implementation of EAPA. EAP-FAS.pdf
Which of the following is an weak implementation of EAPA. EAP-FAS.pdfWhich of the following is an weak implementation of EAPA. EAP-FAS.pdf
Which of the following is an weak implementation of EAPA. EAP-FAS.pdf
arihantcomputersddn
 
Where are chaperones found periplasm, cytoplasm, or cell membrane (.pdf
Where are chaperones found periplasm, cytoplasm, or cell membrane (.pdfWhere are chaperones found periplasm, cytoplasm, or cell membrane (.pdf
Where are chaperones found periplasm, cytoplasm, or cell membrane (.pdf
arihantcomputersddn
 
Talks about McDonaldization What do you think of this concept Do yo.pdf
Talks about McDonaldization What do you think of this concept Do yo.pdfTalks about McDonaldization What do you think of this concept Do yo.pdf
Talks about McDonaldization What do you think of this concept Do yo.pdf
arihantcomputersddn
 
What kind of state information is maintained by an FTP serverSo.pdf
What kind of state information is maintained by an FTP serverSo.pdfWhat kind of state information is maintained by an FTP serverSo.pdf
What kind of state information is maintained by an FTP serverSo.pdf
arihantcomputersddn
 
When H_p is equal to r2, the stable equilibrium is K2 and referred .pdf
When H_p is equal to r2, the stable equilibrium is K2 and referred .pdfWhen H_p is equal to r2, the stable equilibrium is K2 and referred .pdf
When H_p is equal to r2, the stable equilibrium is K2 and referred .pdf
arihantcomputersddn
 
The standard deviation of all possible values is called thea. stan.pdf
The standard deviation of all possible values is called thea. stan.pdfThe standard deviation of all possible values is called thea. stan.pdf
The standard deviation of all possible values is called thea. stan.pdf
arihantcomputersddn
 
The difference between bipolar I disorder and bipolar II disorder is.pdf
The difference between bipolar I disorder and bipolar II disorder is.pdfThe difference between bipolar I disorder and bipolar II disorder is.pdf
The difference between bipolar I disorder and bipolar II disorder is.pdf
arihantcomputersddn
 
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdfsolve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
arihantcomputersddn
 
Question 6 A wastewater sample was collected after screening and grit.pdf
Question 6 A wastewater sample was collected after screening and grit.pdfQuestion 6 A wastewater sample was collected after screening and grit.pdf
Question 6 A wastewater sample was collected after screening and grit.pdf
arihantcomputersddn
 
1. Cathy has just given birth to a little girl. When the nurse tried.pdf
1. Cathy has just given birth to a little girl. When the nurse tried.pdf1. Cathy has just given birth to a little girl. When the nurse tried.pdf
1. Cathy has just given birth to a little girl. When the nurse tried.pdf
arihantcomputersddn
 
QUESTION 1-construction financeWhich one has not correctly describ.pdf
QUESTION 1-construction financeWhich one has not correctly describ.pdfQUESTION 1-construction financeWhich one has not correctly describ.pdf
QUESTION 1-construction financeWhich one has not correctly describ.pdf
arihantcomputersddn
 
Problem #4 (20 points) a.A bus route having seven scheduled stops h.pdf
Problem #4 (20 points) a.A bus route having seven scheduled stops h.pdfProblem #4 (20 points) a.A bus route having seven scheduled stops h.pdf
Problem #4 (20 points) a.A bus route having seven scheduled stops h.pdf
arihantcomputersddn
 
please read carefully before answering. Thank you. Choose at least.pdf
please read carefully before answering. Thank you. Choose at least.pdfplease read carefully before answering. Thank you. Choose at least.pdf
please read carefully before answering. Thank you. Choose at least.pdf
arihantcomputersddn
 
As your reward for saving the Kingdom of Bigfunnia from the evil mon.pdf
As your reward for saving the Kingdom of Bigfunnia from the evil mon.pdfAs your reward for saving the Kingdom of Bigfunnia from the evil mon.pdf
As your reward for saving the Kingdom of Bigfunnia from the evil mon.pdf
arihantcomputersddn
 
Name 3 openings that are transmitted through the levator ani musc.pdf
Name 3 openings that are transmitted through the levator ani musc.pdfName 3 openings that are transmitted through the levator ani musc.pdf
Name 3 openings that are transmitted through the levator ani musc.pdf
arihantcomputersddn
 
Answer the following questions about molecule movement across a membr.pdf
Answer the following questions about molecule movement across a membr.pdfAnswer the following questions about molecule movement across a membr.pdf
Answer the following questions about molecule movement across a membr.pdf
arihantcomputersddn
 
In how many ways, three indistinguishable Owls, one Parrot and one Sp.pdf
In how many ways, three indistinguishable Owls, one Parrot and one Sp.pdfIn how many ways, three indistinguishable Owls, one Parrot and one Sp.pdf
In how many ways, three indistinguishable Owls, one Parrot and one Sp.pdf
arihantcomputersddn
 

More from arihantcomputersddn (20)

write an assemblyprogram that uses indirect addressing to switch the.pdf
write an assemblyprogram that uses indirect addressing to switch the.pdfwrite an assemblyprogram that uses indirect addressing to switch the.pdf
write an assemblyprogram that uses indirect addressing to switch the.pdf
 
Why is there no blood supply that extends into the epidermis Than.pdf
Why is there no blood supply that extends into the epidermis Than.pdfWhy is there no blood supply that extends into the epidermis Than.pdf
Why is there no blood supply that extends into the epidermis Than.pdf
 
Which of the following protocols was developed in the mid-1970s for .pdf
Which of the following protocols was developed in the mid-1970s for .pdfWhich of the following protocols was developed in the mid-1970s for .pdf
Which of the following protocols was developed in the mid-1970s for .pdf
 
Which of the following is an weak implementation of EAPA. EAP-FAS.pdf
Which of the following is an weak implementation of EAPA. EAP-FAS.pdfWhich of the following is an weak implementation of EAPA. EAP-FAS.pdf
Which of the following is an weak implementation of EAPA. EAP-FAS.pdf
 
Where are chaperones found periplasm, cytoplasm, or cell membrane (.pdf
Where are chaperones found periplasm, cytoplasm, or cell membrane (.pdfWhere are chaperones found periplasm, cytoplasm, or cell membrane (.pdf
Where are chaperones found periplasm, cytoplasm, or cell membrane (.pdf
 
Talks about McDonaldization What do you think of this concept Do yo.pdf
Talks about McDonaldization What do you think of this concept Do yo.pdfTalks about McDonaldization What do you think of this concept Do yo.pdf
Talks about McDonaldization What do you think of this concept Do yo.pdf
 
What kind of state information is maintained by an FTP serverSo.pdf
What kind of state information is maintained by an FTP serverSo.pdfWhat kind of state information is maintained by an FTP serverSo.pdf
What kind of state information is maintained by an FTP serverSo.pdf
 
When H_p is equal to r2, the stable equilibrium is K2 and referred .pdf
When H_p is equal to r2, the stable equilibrium is K2 and referred .pdfWhen H_p is equal to r2, the stable equilibrium is K2 and referred .pdf
When H_p is equal to r2, the stable equilibrium is K2 and referred .pdf
 
The standard deviation of all possible values is called thea. stan.pdf
The standard deviation of all possible values is called thea. stan.pdfThe standard deviation of all possible values is called thea. stan.pdf
The standard deviation of all possible values is called thea. stan.pdf
 
The difference between bipolar I disorder and bipolar II disorder is.pdf
The difference between bipolar I disorder and bipolar II disorder is.pdfThe difference between bipolar I disorder and bipolar II disorder is.pdf
The difference between bipolar I disorder and bipolar II disorder is.pdf
 
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdfsolve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
 
Question 6 A wastewater sample was collected after screening and grit.pdf
Question 6 A wastewater sample was collected after screening and grit.pdfQuestion 6 A wastewater sample was collected after screening and grit.pdf
Question 6 A wastewater sample was collected after screening and grit.pdf
 
1. Cathy has just given birth to a little girl. When the nurse tried.pdf
1. Cathy has just given birth to a little girl. When the nurse tried.pdf1. Cathy has just given birth to a little girl. When the nurse tried.pdf
1. Cathy has just given birth to a little girl. When the nurse tried.pdf
 
QUESTION 1-construction financeWhich one has not correctly describ.pdf
QUESTION 1-construction financeWhich one has not correctly describ.pdfQUESTION 1-construction financeWhich one has not correctly describ.pdf
QUESTION 1-construction financeWhich one has not correctly describ.pdf
 
Problem #4 (20 points) a.A bus route having seven scheduled stops h.pdf
Problem #4 (20 points) a.A bus route having seven scheduled stops h.pdfProblem #4 (20 points) a.A bus route having seven scheduled stops h.pdf
Problem #4 (20 points) a.A bus route having seven scheduled stops h.pdf
 
please read carefully before answering. Thank you. Choose at least.pdf
please read carefully before answering. Thank you. Choose at least.pdfplease read carefully before answering. Thank you. Choose at least.pdf
please read carefully before answering. Thank you. Choose at least.pdf
 
As your reward for saving the Kingdom of Bigfunnia from the evil mon.pdf
As your reward for saving the Kingdom of Bigfunnia from the evil mon.pdfAs your reward for saving the Kingdom of Bigfunnia from the evil mon.pdf
As your reward for saving the Kingdom of Bigfunnia from the evil mon.pdf
 
Name 3 openings that are transmitted through the levator ani musc.pdf
Name 3 openings that are transmitted through the levator ani musc.pdfName 3 openings that are transmitted through the levator ani musc.pdf
Name 3 openings that are transmitted through the levator ani musc.pdf
 
Answer the following questions about molecule movement across a membr.pdf
Answer the following questions about molecule movement across a membr.pdfAnswer the following questions about molecule movement across a membr.pdf
Answer the following questions about molecule movement across a membr.pdf
 
In how many ways, three indistinguishable Owls, one Parrot and one Sp.pdf
In how many ways, three indistinguishable Owls, one Parrot and one Sp.pdfIn how many ways, three indistinguishable Owls, one Parrot and one Sp.pdf
In how many ways, three indistinguishable Owls, one Parrot and one Sp.pdf
 

Recently uploaded

The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
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
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
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
 
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
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
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
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
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
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
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
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 

Recently uploaded (20)

The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
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
 
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
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
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
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
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
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
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
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 

Write a program whose source file is named UnitProgl.java that do.pdf

  • 1. Write a program whose source file is named "UnitProgl.java" that does the following: Creates a frame with a GridLayout Manager Creates two panels and adds them to the frame, stacked one over the other. In each panel creates three buttons, side by side. The buttons should be labeled "Button 1", "Button 2", "Button 3", "Button 4", "Button 5" and "Button 6". Displays this GUI when run. The only buttons that actually works will be the buttons on the window title bar: minimize, maximize and the exit button in the upper right hand corner of the programs window. Part 2 - Event Driven Programming Write a program whose source file is named "UnitProg2.java". Do the following: Start by copying the program code from part 1 and modifying it. This program will have a GUI that looks just like the previous one. The goal is to make the JButtons work. Add code to handle the events when the user presses any of the six buttons on the GUI. When the user presses a button simply write out to the console "The user pressed Button X", where "X" is the number of the button. For example, when "Button 2" is pressed the message written to the console should be "The user pressed Button 2.". Solution UnitProg1.java import java.awt.*; import javax.swing.*; public class UnitProg1 { private JFrame mainFrame; private JPanel controlPanel; private JPanel controlPanel1; public UnitProg1(){ prepareGUI(); } public static void main(String[] args){ UnitProg1 prog1 = new UnitProg1(); } private void prepareGUI(){ mainFrame = new JFrame("UnitProg1");
  • 2. mainFrame.setSize(400,400); mainFrame.setLayout(new GridLayout(2,1)); controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout()); controlPanel1=new JPanel(new FlowLayout()); JButton button1=new JButton("Button1"); JButton button2=new JButton("Button2"); JButton button3=new JButton("Button3"); JButton button4=new JButton("Button4"); JButton button5=new JButton("Button5"); JButton button6=new JButton("Button6"); controlPanel.add(button1, controlPanel); controlPanel.add(button2, controlPanel); controlPanel.add(button3, controlPanel); controlPanel1.add(button4, controlPanel1); controlPanel1.add(button5, controlPanel1); controlPanel1.add(button6, controlPanel1); mainFrame.add(controlPanel); mainFrame.add(controlPanel1); mainFrame.setVisible(true); } } UnitProg2.java import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.*; public class UnitProg2 { private JFrame mainFrame; private JPanel controlPanel;
  • 3. private JPanel controlPanel1; public UnitProg2(){ prepareGUI(); } public static void main(String[] args){ UnitProg2 prog2 = new UnitProg2(); } private void prepareGUI(){ mainFrame = new JFrame("UnitProg2"); mainFrame.setSize(400,400); mainFrame.setLayout(new GridLayout(2, 1)); controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout()); controlPanel1=new JPanel(new FlowLayout()); JButton button1=new JButton("Button1"); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("The user pressed Button 1"); } }); JButton button2=new JButton("Button2"); button2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("The user pressed Button 2"); } }); JButton button3=new JButton("Button3"); button3.addActionListener(new ActionListener() {
  • 4. @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("The user pressed Button 3"); } }); JButton button4=new JButton("Button4"); button4.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("The user pressed Button 4"); } }); JButton button5=new JButton("Button5"); button5.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("The user pressed Button 5"); } }); JButton button6=new JButton("Button6"); button6.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("The user pressed Button 6"); } }); controlPanel.add(button1, controlPanel); controlPanel.add(button2, controlPanel);
  • 5. controlPanel.add(button3, controlPanel); controlPanel1.add(button4, controlPanel1); controlPanel1.add(button5, controlPanel1); controlPanel1.add(button6, controlPanel1); mainFrame.add(controlPanel); mainFrame.add(controlPanel1); mainFrame.setVisible(true); } }