SlideShare a Scribd company logo
1 of 5
Download to read offline
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
 
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 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
 
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
 

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

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
 
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
 
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
 
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
 

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

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
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
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
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
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
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
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
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
 

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); } }