SlideShare a Scribd company logo
1 of 3
Download to read offline
GridFiller Applet
Write an applet that displays a 4 x 4 grid. When the user clicks on a square in the grid, the applet
should draw a filled circle in it. If the square already has a circle, clicking on it should cause the
circle to disappear.
Solution
import javax.swing.JApplet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JPanel;
public class GridFiller extends JApplet
{
public void init()
{
GridFiller gridFiller = new GridFiller();
setContentPane(gridFiller);
}
class GridFiller extends JPanel implements MouseListener
{
int gridRow;
int gridCol;
GridFiller()
{
gridRow = -1;
addMouseListener(this);
}
public void paintComponent(Graphics g)
{
int row;
int col;
int x,y;
for (row=0; row<4; row++)
{
for (col=0; col<4; col++)
{
x = col * 50;
y = col * 50;
if ((row % 2) == (col % 2))
g.setColor(Color.blue);
else
g.setColor(Color.white);
g.fillRect(x, y, 50, 50);
}
}
if (gridRow >= 0)
{
g.setColor(Color.red);
x = gridCol * 50;
y = gridRow * 50;
g.fillOval(x, y, 50, 50);
}
}
public void mousePressed (MouseEvent evt)
{
int col = evt.getX() / 50;
int row = evt.getY() / 50;
if (gridRow == row && gridCol == col)
gridRow = -1;
else
{
gridRow = row;
gridCol = col;
}
repaint();
}
public void mouseReleased(MouseEvent evt){}
public void mouseClicked(MouseEvent evt){}
public void mouseEntered(MouseEvent evt){}
public void mouseExited(MouseEvent evt){}
}
}

More Related Content

Similar to GridFiller AppletWrite an applet that displays a 4 x 4 grid. When .pdf

14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded GraphicsAdil Jafri
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfJUSTSTYLISH3B2MOHALI
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة التاسعة
شرح مقرر البرمجة 2   لغة جافا - الوحدة التاسعةشرح مقرر البرمجة 2   لغة جافا - الوحدة التاسعة
شرح مقرر البرمجة 2 لغة جافا - الوحدة التاسعةجامعة القدس المفتوحة
 
U5 JAVA.pptx
U5 JAVA.pptxU5 JAVA.pptx
U5 JAVA.pptxmadan r
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfanjandavid
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdffeelinggifts
 
Graphics programming in Java
Graphics programming in JavaGraphics programming in Java
Graphics programming in JavaTushar B Kute
 
Programa en java circulos
Programa en java circulosPrograma en java circulos
Programa en java circulosAnel Sosa
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Korhan Bircan
 
The Noland national flag is a square showing the following pattern. .docx
 The Noland national flag is a square showing the following pattern.  .docx The Noland national flag is a square showing the following pattern.  .docx
The Noland national flag is a square showing the following pattern. .docxKomlin1
 
Infinum Android Talks #15 - Garfield Android Studio Plugin - Be Smart, Be Lazy
Infinum Android Talks #15 - Garfield Android Studio Plugin - Be Smart, Be LazyInfinum Android Talks #15 - Garfield Android Studio Plugin - Be Smart, Be Lazy
Infinum Android Talks #15 - Garfield Android Studio Plugin - Be Smart, Be LazyInfinum
 
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfImport java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfapexcomputer54
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1PRN USM
 

Similar to GridFiller AppletWrite an applet that displays a 4 x 4 grid. When .pdf (20)

14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded Graphics
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة التاسعة
شرح مقرر البرمجة 2   لغة جافا - الوحدة التاسعةشرح مقرر البرمجة 2   لغة جافا - الوحدة التاسعة
شرح مقرر البرمجة 2 لغة جافا - الوحدة التاسعة
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
 
Applications
ApplicationsApplications
Applications
 
U5 JAVA.pptx
U5 JAVA.pptxU5 JAVA.pptx
U5 JAVA.pptx
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdf
 
JAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdfJAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdf
 
java Applet Introduction
java Applet Introductionjava Applet Introduction
java Applet Introduction
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdf
 
Graphics programming in Java
Graphics programming in JavaGraphics programming in Java
Graphics programming in Java
 
Java oops features
Java oops featuresJava oops features
Java oops features
 
Programa en java circulos
Programa en java circulosPrograma en java circulos
Programa en java circulos
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)
 
662305 LAB12
662305 LAB12662305 LAB12
662305 LAB12
 
The Noland national flag is a square showing the following pattern. .docx
 The Noland national flag is a square showing the following pattern.  .docx The Noland national flag is a square showing the following pattern.  .docx
The Noland national flag is a square showing the following pattern. .docx
 
Infinum Android Talks #15 - Garfield Android Studio Plugin - Be Smart, Be Lazy
Infinum Android Talks #15 - Garfield Android Studio Plugin - Be Smart, Be LazyInfinum Android Talks #15 - Garfield Android Studio Plugin - Be Smart, Be Lazy
Infinum Android Talks #15 - Garfield Android Studio Plugin - Be Smart, Be Lazy
 
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdfImport java.awt.; Import acm.program.; Import acm.graphics.;.pdf
Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
 

More from alokkesh1

Describe the transformation that has taken place with the function.pdf
Describe the transformation that has taken place with the function.pdfDescribe the transformation that has taken place with the function.pdf
Describe the transformation that has taken place with the function.pdfalokkesh1
 
Each student at State University has a student I.D. number consisting.pdf
Each student at State University has a student I.D. number consisting.pdfEach student at State University has a student I.D. number consisting.pdf
Each student at State University has a student I.D. number consisting.pdfalokkesh1
 
Describe personality traits and their implications in leadership..pdf
Describe personality traits and their implications in leadership..pdfDescribe personality traits and their implications in leadership..pdf
Describe personality traits and their implications in leadership..pdfalokkesh1
 
Analyze Which of the following isare found in ALL species of fungi.pdf
Analyze Which of the following isare found in ALL species of fungi.pdfAnalyze Which of the following isare found in ALL species of fungi.pdf
Analyze Which of the following isare found in ALL species of fungi.pdfalokkesh1
 
An industry analysis by Porters Five Forces reveals that the soft dr.pdf
An industry analysis by Porters Five Forces reveals that the soft dr.pdfAn industry analysis by Porters Five Forces reveals that the soft dr.pdf
An industry analysis by Porters Five Forces reveals that the soft dr.pdfalokkesh1
 
ABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdf
ABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdfABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdf
ABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdfalokkesh1
 
Why are general capital assets reported on the statement of net asse.pdf
Why are general capital assets reported on the statement of net asse.pdfWhy are general capital assets reported on the statement of net asse.pdf
Why are general capital assets reported on the statement of net asse.pdfalokkesh1
 
Which of the following sets of biomes is placed in order from lowest.pdf
Which of the following sets of biomes is placed in order from lowest.pdfWhich of the following sets of biomes is placed in order from lowest.pdf
Which of the following sets of biomes is placed in order from lowest.pdfalokkesh1
 
When a planetary nebula forms around a star you see gas emitting ligh.pdf
When a planetary nebula forms around a star you see gas emitting ligh.pdfWhen a planetary nebula forms around a star you see gas emitting ligh.pdf
When a planetary nebula forms around a star you see gas emitting ligh.pdfalokkesh1
 
Which of the following is consistent with a history of positibe sele.pdf
Which of the following is consistent with a history of positibe sele.pdfWhich of the following is consistent with a history of positibe sele.pdf
Which of the following is consistent with a history of positibe sele.pdfalokkesh1
 
What is the difference between protein-based and polysaccharide-based.pdf
What is the difference between protein-based and polysaccharide-based.pdfWhat is the difference between protein-based and polysaccharide-based.pdf
What is the difference between protein-based and polysaccharide-based.pdfalokkesh1
 
What is Flexibility of Command Usage.SolutionOne of the advant.pdf
What is Flexibility of Command Usage.SolutionOne of the advant.pdfWhat is Flexibility of Command Usage.SolutionOne of the advant.pdf
What is Flexibility of Command Usage.SolutionOne of the advant.pdfalokkesh1
 
What data type is the value 25.25Solution25.25 is floating po.pdf
What data type is the value 25.25Solution25.25 is floating po.pdfWhat data type is the value 25.25Solution25.25 is floating po.pdf
What data type is the value 25.25Solution25.25 is floating po.pdfalokkesh1
 
What are the reasons for joining management development programs Wh.pdf
What are the reasons for joining management development programs Wh.pdfWhat are the reasons for joining management development programs Wh.pdf
What are the reasons for joining management development programs Wh.pdfalokkesh1
 
Using C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdfUsing C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdfalokkesh1
 
true or false A primary sources tend to be firsthand observations of.pdf
true or false A primary sources tend to be firsthand observations of.pdftrue or false A primary sources tend to be firsthand observations of.pdf
true or false A primary sources tend to be firsthand observations of.pdfalokkesh1
 
To what extent can MarxistStructuralist perspectives provide valuab.pdf
To what extent can MarxistStructuralist perspectives provide valuab.pdfTo what extent can MarxistStructuralist perspectives provide valuab.pdf
To what extent can MarxistStructuralist perspectives provide valuab.pdfalokkesh1
 
This Question 1 pt Resources are 0 A, the inputs used to make good a.pdf
This Question 1 pt Resources are 0 A, the inputs used to make good a.pdfThis Question 1 pt Resources are 0 A, the inputs used to make good a.pdf
This Question 1 pt Resources are 0 A, the inputs used to make good a.pdfalokkesh1
 
There are n couples invited to a banquet. Suppose there are some numb.pdf
There are n couples invited to a banquet. Suppose there are some numb.pdfThere are n couples invited to a banquet. Suppose there are some numb.pdf
There are n couples invited to a banquet. Suppose there are some numb.pdfalokkesh1
 
The Northwest Ordinance inclmsted all of the following EXCEPT a. Nom.pdf
The Northwest Ordinance inclmsted all of the following EXCEPT a. Nom.pdfThe Northwest Ordinance inclmsted all of the following EXCEPT a. Nom.pdf
The Northwest Ordinance inclmsted all of the following EXCEPT a. Nom.pdfalokkesh1
 

More from alokkesh1 (20)

Describe the transformation that has taken place with the function.pdf
Describe the transformation that has taken place with the function.pdfDescribe the transformation that has taken place with the function.pdf
Describe the transformation that has taken place with the function.pdf
 
Each student at State University has a student I.D. number consisting.pdf
Each student at State University has a student I.D. number consisting.pdfEach student at State University has a student I.D. number consisting.pdf
Each student at State University has a student I.D. number consisting.pdf
 
Describe personality traits and their implications in leadership..pdf
Describe personality traits and their implications in leadership..pdfDescribe personality traits and their implications in leadership..pdf
Describe personality traits and their implications in leadership..pdf
 
Analyze Which of the following isare found in ALL species of fungi.pdf
Analyze Which of the following isare found in ALL species of fungi.pdfAnalyze Which of the following isare found in ALL species of fungi.pdf
Analyze Which of the following isare found in ALL species of fungi.pdf
 
An industry analysis by Porters Five Forces reveals that the soft dr.pdf
An industry analysis by Porters Five Forces reveals that the soft dr.pdfAn industry analysis by Porters Five Forces reveals that the soft dr.pdf
An industry analysis by Porters Five Forces reveals that the soft dr.pdf
 
ABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdf
ABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdfABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdf
ABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdf
 
Why are general capital assets reported on the statement of net asse.pdf
Why are general capital assets reported on the statement of net asse.pdfWhy are general capital assets reported on the statement of net asse.pdf
Why are general capital assets reported on the statement of net asse.pdf
 
Which of the following sets of biomes is placed in order from lowest.pdf
Which of the following sets of biomes is placed in order from lowest.pdfWhich of the following sets of biomes is placed in order from lowest.pdf
Which of the following sets of biomes is placed in order from lowest.pdf
 
When a planetary nebula forms around a star you see gas emitting ligh.pdf
When a planetary nebula forms around a star you see gas emitting ligh.pdfWhen a planetary nebula forms around a star you see gas emitting ligh.pdf
When a planetary nebula forms around a star you see gas emitting ligh.pdf
 
Which of the following is consistent with a history of positibe sele.pdf
Which of the following is consistent with a history of positibe sele.pdfWhich of the following is consistent with a history of positibe sele.pdf
Which of the following is consistent with a history of positibe sele.pdf
 
What is the difference between protein-based and polysaccharide-based.pdf
What is the difference between protein-based and polysaccharide-based.pdfWhat is the difference between protein-based and polysaccharide-based.pdf
What is the difference between protein-based and polysaccharide-based.pdf
 
What is Flexibility of Command Usage.SolutionOne of the advant.pdf
What is Flexibility of Command Usage.SolutionOne of the advant.pdfWhat is Flexibility of Command Usage.SolutionOne of the advant.pdf
What is Flexibility of Command Usage.SolutionOne of the advant.pdf
 
What data type is the value 25.25Solution25.25 is floating po.pdf
What data type is the value 25.25Solution25.25 is floating po.pdfWhat data type is the value 25.25Solution25.25 is floating po.pdf
What data type is the value 25.25Solution25.25 is floating po.pdf
 
What are the reasons for joining management development programs Wh.pdf
What are the reasons for joining management development programs Wh.pdfWhat are the reasons for joining management development programs Wh.pdf
What are the reasons for joining management development programs Wh.pdf
 
Using C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdfUsing C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdf
 
true or false A primary sources tend to be firsthand observations of.pdf
true or false A primary sources tend to be firsthand observations of.pdftrue or false A primary sources tend to be firsthand observations of.pdf
true or false A primary sources tend to be firsthand observations of.pdf
 
To what extent can MarxistStructuralist perspectives provide valuab.pdf
To what extent can MarxistStructuralist perspectives provide valuab.pdfTo what extent can MarxistStructuralist perspectives provide valuab.pdf
To what extent can MarxistStructuralist perspectives provide valuab.pdf
 
This Question 1 pt Resources are 0 A, the inputs used to make good a.pdf
This Question 1 pt Resources are 0 A, the inputs used to make good a.pdfThis Question 1 pt Resources are 0 A, the inputs used to make good a.pdf
This Question 1 pt Resources are 0 A, the inputs used to make good a.pdf
 
There are n couples invited to a banquet. Suppose there are some numb.pdf
There are n couples invited to a banquet. Suppose there are some numb.pdfThere are n couples invited to a banquet. Suppose there are some numb.pdf
There are n couples invited to a banquet. Suppose there are some numb.pdf
 
The Northwest Ordinance inclmsted all of the following EXCEPT a. Nom.pdf
The Northwest Ordinance inclmsted all of the following EXCEPT a. Nom.pdfThe Northwest Ordinance inclmsted all of the following EXCEPT a. Nom.pdf
The Northwest Ordinance inclmsted all of the following EXCEPT a. Nom.pdf
 

Recently uploaded

diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
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 strategiesAmanpreetKaur157993
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
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 HinduismDabee Kamal
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
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.pptNishitharanjan Rout
 

Recently uploaded (20)

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"
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
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
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
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
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
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
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
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
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
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
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
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
 

GridFiller AppletWrite an applet that displays a 4 x 4 grid. When .pdf

  • 1. GridFiller Applet Write an applet that displays a 4 x 4 grid. When the user clicks on a square in the grid, the applet should draw a filled circle in it. If the square already has a circle, clicking on it should cause the circle to disappear. Solution import javax.swing.JApplet; import java.awt.Color; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JPanel; public class GridFiller extends JApplet { public void init() { GridFiller gridFiller = new GridFiller(); setContentPane(gridFiller); } class GridFiller extends JPanel implements MouseListener { int gridRow; int gridCol; GridFiller() { gridRow = -1; addMouseListener(this); } public void paintComponent(Graphics g) { int row; int col; int x,y; for (row=0; row<4; row++)
  • 2. { for (col=0; col<4; col++) { x = col * 50; y = col * 50; if ((row % 2) == (col % 2)) g.setColor(Color.blue); else g.setColor(Color.white); g.fillRect(x, y, 50, 50); } } if (gridRow >= 0) { g.setColor(Color.red); x = gridCol * 50; y = gridRow * 50; g.fillOval(x, y, 50, 50); } } public void mousePressed (MouseEvent evt) { int col = evt.getX() / 50; int row = evt.getY() / 50; if (gridRow == row && gridCol == col) gridRow = -1; else { gridRow = row; gridCol = col; } repaint(); } public void mouseReleased(MouseEvent evt){} public void mouseClicked(MouseEvent evt){} public void mouseEntered(MouseEvent evt){}