SlideShare a Scribd company logo
1 of 5
Download to read offline
Task: Write a Java program to implement a simple graphics editor that can be used to draw a
Pythagoras. The editor has a pull-down menu on top of the screen, with 2 buttons: "Pythagoras"
and "Quit". 1) When the user selects "Pythagoras", he/she can draw a tree of Pythagoras on
the screen. 2) The editor terminates/quits execution if the user selects "Quit" from the pulldown
menu. 3) The editor has a horizontal and a vertical sliding bar that when slided, moves the tree
on the canvas accordingly.
Solution
HOpe this will help--
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class MenuExp extends JFrame {
public MenuExp() {
setTitle("Menu Example");
setSize(150, 150);
JSlider framesPerSecond = new JSlider(JSlider.VERTICAL,FPS_MIN, FPS_MAX,
FPS_INIT);
framesPerSecond.addChangeListener(this);
JSlider framesPerSecond1= new JSlider(JSlider.HORIZONTAL,FPS_MIN, FPS_MAX,
FPS_INIT);
framesPerSecond1.addChangeListener(this);
// Creates a menubar for a JFrame
JMenuBar menuBar = new JMenuBar();
// Add the menubar to the frame
setJMenuBar(menuBar);
// Define and add two drop down menu to the menubar
JMenu fileMenu = new JMenu("Process");
menuBar.add(fileMenu);
// Create and add simple menu item to one of the drop down menu
JMenuItem newAction = new JMenuItem("Pythagoras");
JMenuItem openAction = new JMenuItem("Quit");
fileMenu.add(newAction);
fileMenu.add(openAction);
newAction.addActionListner(new PythagorusListener());
openAction.addActionListner(new CloseListener());
// Add a listener to the New menu item. actionPerformed() method will
// invoked, if user triggred this menu item
newAction.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("You have clicked on the new action");
}
});
}
public static void main(String[] args) {
MenuExp me = new MenuExp();
me.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
me.setVisible(true);
}
}
public class CloseListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
//DO SOMETHING
System.exit(0);
}
}
public class PythagorusListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
setSize(900, 900);
setTitle("Pythagoras tree");
add(new Draw(n));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
class Draw extends JComponent {
private int height = 800;
private int width = 800;
private int steps;
public Draw(int n) {
steps = n;
Dimension d = new Dimension(width, height);
setMinimumSize(d);
setPreferredSize(d);
setMaximumSize(d);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
g.setColor(Color.black);
int x1, x2, x3, y1, y2, y3;
int base = width/7;
x1 = (width/2)-(base/2);
x2 = (width/2)+(base/2);
x3 = width/2;
y1 = (height-(height/15))-base;
y2 = height-(height/15);
y3 = (height-(height/15))-(base+(base/2));
//paint
g.drawPolygon(new int[]{x1, x1, x2, x2, x1}, new int[]{y1, y2, y2, y1, y1}, 5);
int n1 = steps;
if(--n1 > 0){
g.drawPolygon(new int[] {x1, x3, x2}, new int[] {y1, y3, y1}, 3);
paintMore(n1, g, x1, x3, x2, y1, y3, y1);
paintMore(n1, g, x2, x3, x1, y1, y3, y1);
}
}
public void paintMore(int n1, Graphics g, double x1_1, double x2_1, double x3_1, double
y1_1, double y2_1, double y3_1){
double x1, x2, x3, y1, y2, y3;
//counting
x1 = x1_1 + (x2_1-x3_1);
x2 = x2_1 + (x2_1-x3_1);
x3 = ((x2_1 + (x2_1-x3_1)) + ((x2_1-x3_1)/2)) + ((x1_1-x2_1)/2);
y1 = y1_1 + (y2_1-y3_1);
y2 = y2_1 + (y2_1-y3_1);
y3 = ((y1_1 + (y2_1-y3_1)) + ((y2_1-y1_1)/2)) + ((y2_1-y3_1)/2);
//paint
g.setColor(Color.green);
g.drawPolygon(new int[] {(int)x1, (int)x2, (int)x2_1, (int)x1},
new int[] {(int)y1, (int)y2, (int)y2_1, (int)y1}, 4);
g.drawLine((int)x1, (int)y1, (int)x1_1, (int)y1_1);
g.drawLine((int)x2_1, (int)y2_1, (int)x2, (int)y2);
g.drawLine((int)x1, (int)y1, (int)x2, (int)y2);
if(--n1 > 0){
g.drawLine((int)x1, (int)y1, (int)x3, (int)y3);
g.drawLine((int)x2, (int)y2, (int)x3, (int)y3);
paintMore(n1, g, x1, x3, x2, y1, y3, y2);
paintMore(n1, g, x2, x3, x1, y2, y3, y1);
}
}
}

More Related Content

Similar to Task Write a Java program to implement a simple graphics editor tha.pdf

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
 
Android Studio (Java)The SimplePaint app (full code given below).docx
Android Studio (Java)The SimplePaint app (full code given below).docxAndroid Studio (Java)The SimplePaint app (full code given below).docx
Android Studio (Java)The SimplePaint app (full code given below).docxamrit47
 
Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1Getting started with GUI programming in Java_1
Getting started with GUI programming in Java_1Muhammad Shebl Farag
 
write a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdfwrite a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdfPRATIKSINHA7304
 
Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]Palak Sanghani
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxmary772
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxmccormicknadine86
 
google play service 7.8 & new tech in M
google play service 7.8 & new tech in M google play service 7.8 & new tech in M
google play service 7.8 & new tech in M Ted Liang
 
Spin Up Desktop Apps with Electron.js
Spin Up Desktop Apps with Electron.jsSpin Up Desktop Apps with Electron.js
Spin Up Desktop Apps with Electron.jsSteve Godin
 
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
 
GridFiller AppletWrite an applet that displays a 4 x 4 grid. When .pdf
GridFiller AppletWrite an applet that displays a 4 x 4 grid. When .pdfGridFiller AppletWrite an applet that displays a 4 x 4 grid. When .pdf
GridFiller AppletWrite an applet that displays a 4 x 4 grid. When .pdfalokkesh1
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1PRN USM
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdffathimaoptical
 
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfimport java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfanyacarpets
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfflashfashioncasualwe
 

Similar to Task Write a Java program to implement a simple graphics editor tha.pdf (20)

JAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdfJAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdf
 
Graphical User Components Part 2
Graphical User Components Part 2Graphical User Components Part 2
Graphical User Components Part 2
 
MIDP: Game API
MIDP: Game APIMIDP: Game API
MIDP: Game API
 
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
 
Android Studio (Java)The SimplePaint app (full code given below).docx
Android Studio (Java)The SimplePaint app (full code given below).docxAndroid Studio (Java)The SimplePaint app (full code given below).docx
Android Studio (Java)The SimplePaint app (full code given below).docx
 
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
 
write a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdfwrite a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdf
 
Applications
ApplicationsApplications
Applications
 
Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
google play service 7.8 & new tech in M
google play service 7.8 & new tech in M google play service 7.8 & new tech in M
google play service 7.8 & new tech in M
 
Spin Up Desktop Apps with Electron.js
Spin Up Desktop Apps with Electron.jsSpin Up Desktop Apps with Electron.js
Spin Up Desktop Apps with Electron.js
 
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)
 
Applets
AppletsApplets
Applets
 
GridFiller AppletWrite an applet that displays a 4 x 4 grid. When .pdf
GridFiller AppletWrite an applet that displays a 4 x 4 grid. When .pdfGridFiller AppletWrite an applet that displays a 4 x 4 grid. When .pdf
GridFiller AppletWrite an applet that displays a 4 x 4 grid. When .pdf
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
 
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfimport java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdf
 

More from cronkwurphyb44502

A. What are two ways in which the extracellular and cytoplasmic leaf.pdf
A. What are two ways in which the extracellular and cytoplasmic leaf.pdfA. What are two ways in which the extracellular and cytoplasmic leaf.pdf
A. What are two ways in which the extracellular and cytoplasmic leaf.pdfcronkwurphyb44502
 
Answer True or False to the following statements Colony is forme.pdf
Answer True or False to the following statements  Colony is forme.pdfAnswer True or False to the following statements  Colony is forme.pdf
Answer True or False to the following statements Colony is forme.pdfcronkwurphyb44502
 
Certain entities are required to disclose the fair value of financial.pdf
Certain entities are required to disclose the fair value of financial.pdfCertain entities are required to disclose the fair value of financial.pdf
Certain entities are required to disclose the fair value of financial.pdfcronkwurphyb44502
 
From 1982 to 2012, the cumulative U.S. inflation rate was 95. In .pdf
From 1982 to 2012, the cumulative U.S. inflation rate was 95. In .pdfFrom 1982 to 2012, the cumulative U.S. inflation rate was 95. In .pdf
From 1982 to 2012, the cumulative U.S. inflation rate was 95. In .pdfcronkwurphyb44502
 
Dermatome and myotome are terms that refer to embryonic development..pdf
Dermatome and myotome are terms that refer to embryonic development..pdfDermatome and myotome are terms that refer to embryonic development..pdf
Dermatome and myotome are terms that refer to embryonic development..pdfcronkwurphyb44502
 
describe the definitions of substrate, enzyme active site and its ge.pdf
describe the definitions of substrate, enzyme active site and its ge.pdfdescribe the definitions of substrate, enzyme active site and its ge.pdf
describe the definitions of substrate, enzyme active site and its ge.pdfcronkwurphyb44502
 
You have subnetted a Class A address space of 17.0.0.0 using a subne.pdf
You have subnetted a Class A address space of 17.0.0.0 using a subne.pdfYou have subnetted a Class A address space of 17.0.0.0 using a subne.pdf
You have subnetted a Class A address space of 17.0.0.0 using a subne.pdfcronkwurphyb44502
 
write a MATLAB function to implement Continues-time Fourier Transfor.pdf
write a MATLAB function to implement Continues-time Fourier Transfor.pdfwrite a MATLAB function to implement Continues-time Fourier Transfor.pdf
write a MATLAB function to implement Continues-time Fourier Transfor.pdfcronkwurphyb44502
 
Write a hypothesis from the following observation. a. Every April, f.pdf
Write a hypothesis from the following observation.  a. Every April, f.pdfWrite a hypothesis from the following observation.  a. Every April, f.pdf
Write a hypothesis from the following observation. a. Every April, f.pdfcronkwurphyb44502
 
What were the outstanding accomplishments of the Byzantine empire un.pdf
What were the outstanding accomplishments of the Byzantine empire un.pdfWhat were the outstanding accomplishments of the Byzantine empire un.pdf
What were the outstanding accomplishments of the Byzantine empire un.pdfcronkwurphyb44502
 
What is genetic drift O Achange in allele frequencies caused by rand.pdf
What is genetic drift O Achange in allele frequencies caused by rand.pdfWhat is genetic drift O Achange in allele frequencies caused by rand.pdf
What is genetic drift O Achange in allele frequencies caused by rand.pdfcronkwurphyb44502
 
What are some characteristics associated with effective project .pdf
What are some characteristics associated with effective project .pdfWhat are some characteristics associated with effective project .pdf
What are some characteristics associated with effective project .pdfcronkwurphyb44502
 
We have discussed outliers for several times during the semester. Wh.pdf
We have discussed outliers for several times during the semester. Wh.pdfWe have discussed outliers for several times during the semester. Wh.pdf
We have discussed outliers for several times during the semester. Wh.pdfcronkwurphyb44502
 
2. External events include all of the following except Purchasing equ.pdf
2. External events include all of the following except Purchasing equ.pdf2. External events include all of the following except Purchasing equ.pdf
2. External events include all of the following except Purchasing equ.pdfcronkwurphyb44502
 
The Missequa Valley Protectors understand groundwater is a great dri .pdf
The Missequa Valley Protectors understand groundwater is a great dri .pdfThe Missequa Valley Protectors understand groundwater is a great dri .pdf
The Missequa Valley Protectors understand groundwater is a great dri .pdfcronkwurphyb44502
 
The If and IF else are a pair of commands in the Arduino Processing .pdf
The If and IF else are a pair of commands in the Arduino Processing .pdfThe If and IF else are a pair of commands in the Arduino Processing .pdf
The If and IF else are a pair of commands in the Arduino Processing .pdfcronkwurphyb44502
 
The duct from an expanded chamber called the node truck A substance t.pdf
The duct from an expanded chamber called the node truck A substance t.pdfThe duct from an expanded chamber called the node truck A substance t.pdf
The duct from an expanded chamber called the node truck A substance t.pdfcronkwurphyb44502
 
Suppose you have a method triPartition, whose documentation is given.pdf
Suppose you have a method triPartition, whose documentation is given.pdfSuppose you have a method triPartition, whose documentation is given.pdf
Suppose you have a method triPartition, whose documentation is given.pdfcronkwurphyb44502
 
A CALLING MODEMA calling modem transmits each data bit 1 as a 1270.pdf
A CALLING MODEMA calling modem transmits each data bit 1 as a 1270.pdfA CALLING MODEMA calling modem transmits each data bit 1 as a 1270.pdf
A CALLING MODEMA calling modem transmits each data bit 1 as a 1270.pdfcronkwurphyb44502
 
Show that L = {a^k k is a square} is not regular.SolutionLet .pdf
Show that L = {a^k  k is a square} is not regular.SolutionLet .pdfShow that L = {a^k  k is a square} is not regular.SolutionLet .pdf
Show that L = {a^k k is a square} is not regular.SolutionLet .pdfcronkwurphyb44502
 

More from cronkwurphyb44502 (20)

A. What are two ways in which the extracellular and cytoplasmic leaf.pdf
A. What are two ways in which the extracellular and cytoplasmic leaf.pdfA. What are two ways in which the extracellular and cytoplasmic leaf.pdf
A. What are two ways in which the extracellular and cytoplasmic leaf.pdf
 
Answer True or False to the following statements Colony is forme.pdf
Answer True or False to the following statements  Colony is forme.pdfAnswer True or False to the following statements  Colony is forme.pdf
Answer True or False to the following statements Colony is forme.pdf
 
Certain entities are required to disclose the fair value of financial.pdf
Certain entities are required to disclose the fair value of financial.pdfCertain entities are required to disclose the fair value of financial.pdf
Certain entities are required to disclose the fair value of financial.pdf
 
From 1982 to 2012, the cumulative U.S. inflation rate was 95. In .pdf
From 1982 to 2012, the cumulative U.S. inflation rate was 95. In .pdfFrom 1982 to 2012, the cumulative U.S. inflation rate was 95. In .pdf
From 1982 to 2012, the cumulative U.S. inflation rate was 95. In .pdf
 
Dermatome and myotome are terms that refer to embryonic development..pdf
Dermatome and myotome are terms that refer to embryonic development..pdfDermatome and myotome are terms that refer to embryonic development..pdf
Dermatome and myotome are terms that refer to embryonic development..pdf
 
describe the definitions of substrate, enzyme active site and its ge.pdf
describe the definitions of substrate, enzyme active site and its ge.pdfdescribe the definitions of substrate, enzyme active site and its ge.pdf
describe the definitions of substrate, enzyme active site and its ge.pdf
 
You have subnetted a Class A address space of 17.0.0.0 using a subne.pdf
You have subnetted a Class A address space of 17.0.0.0 using a subne.pdfYou have subnetted a Class A address space of 17.0.0.0 using a subne.pdf
You have subnetted a Class A address space of 17.0.0.0 using a subne.pdf
 
write a MATLAB function to implement Continues-time Fourier Transfor.pdf
write a MATLAB function to implement Continues-time Fourier Transfor.pdfwrite a MATLAB function to implement Continues-time Fourier Transfor.pdf
write a MATLAB function to implement Continues-time Fourier Transfor.pdf
 
Write a hypothesis from the following observation. a. Every April, f.pdf
Write a hypothesis from the following observation.  a. Every April, f.pdfWrite a hypothesis from the following observation.  a. Every April, f.pdf
Write a hypothesis from the following observation. a. Every April, f.pdf
 
What were the outstanding accomplishments of the Byzantine empire un.pdf
What were the outstanding accomplishments of the Byzantine empire un.pdfWhat were the outstanding accomplishments of the Byzantine empire un.pdf
What were the outstanding accomplishments of the Byzantine empire un.pdf
 
What is genetic drift O Achange in allele frequencies caused by rand.pdf
What is genetic drift O Achange in allele frequencies caused by rand.pdfWhat is genetic drift O Achange in allele frequencies caused by rand.pdf
What is genetic drift O Achange in allele frequencies caused by rand.pdf
 
What are some characteristics associated with effective project .pdf
What are some characteristics associated with effective project .pdfWhat are some characteristics associated with effective project .pdf
What are some characteristics associated with effective project .pdf
 
We have discussed outliers for several times during the semester. Wh.pdf
We have discussed outliers for several times during the semester. Wh.pdfWe have discussed outliers for several times during the semester. Wh.pdf
We have discussed outliers for several times during the semester. Wh.pdf
 
2. External events include all of the following except Purchasing equ.pdf
2. External events include all of the following except Purchasing equ.pdf2. External events include all of the following except Purchasing equ.pdf
2. External events include all of the following except Purchasing equ.pdf
 
The Missequa Valley Protectors understand groundwater is a great dri .pdf
The Missequa Valley Protectors understand groundwater is a great dri .pdfThe Missequa Valley Protectors understand groundwater is a great dri .pdf
The Missequa Valley Protectors understand groundwater is a great dri .pdf
 
The If and IF else are a pair of commands in the Arduino Processing .pdf
The If and IF else are a pair of commands in the Arduino Processing .pdfThe If and IF else are a pair of commands in the Arduino Processing .pdf
The If and IF else are a pair of commands in the Arduino Processing .pdf
 
The duct from an expanded chamber called the node truck A substance t.pdf
The duct from an expanded chamber called the node truck A substance t.pdfThe duct from an expanded chamber called the node truck A substance t.pdf
The duct from an expanded chamber called the node truck A substance t.pdf
 
Suppose you have a method triPartition, whose documentation is given.pdf
Suppose you have a method triPartition, whose documentation is given.pdfSuppose you have a method triPartition, whose documentation is given.pdf
Suppose you have a method triPartition, whose documentation is given.pdf
 
A CALLING MODEMA calling modem transmits each data bit 1 as a 1270.pdf
A CALLING MODEMA calling modem transmits each data bit 1 as a 1270.pdfA CALLING MODEMA calling modem transmits each data bit 1 as a 1270.pdf
A CALLING MODEMA calling modem transmits each data bit 1 as a 1270.pdf
 
Show that L = {a^k k is a square} is not regular.SolutionLet .pdf
Show that L = {a^k  k is a square} is not regular.SolutionLet .pdfShow that L = {a^k  k is a square} is not regular.SolutionLet .pdf
Show that L = {a^k k is a square} is not regular.SolutionLet .pdf
 

Recently uploaded

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 

Recently uploaded (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 

Task Write a Java program to implement a simple graphics editor tha.pdf

  • 1. Task: Write a Java program to implement a simple graphics editor that can be used to draw a Pythagoras. The editor has a pull-down menu on top of the screen, with 2 buttons: "Pythagoras" and "Quit". 1) When the user selects "Pythagoras", he/she can draw a tree of Pythagoras on the screen. 2) The editor terminates/quits execution if the user selects "Quit" from the pulldown menu. 3) The editor has a horizontal and a vertical sliding bar that when slided, moves the tree on the canvas accordingly. Solution HOpe this will help-- import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example"); setSize(150, 150); JSlider framesPerSecond = new JSlider(JSlider.VERTICAL,FPS_MIN, FPS_MAX, FPS_INIT); framesPerSecond.addChangeListener(this); JSlider framesPerSecond1= new JSlider(JSlider.HORIZONTAL,FPS_MIN, FPS_MAX, FPS_INIT); framesPerSecond1.addChangeListener(this); // Creates a menubar for a JFrame JMenuBar menuBar = new JMenuBar();
  • 2. // Add the menubar to the frame setJMenuBar(menuBar); // Define and add two drop down menu to the menubar JMenu fileMenu = new JMenu("Process"); menuBar.add(fileMenu); // Create and add simple menu item to one of the drop down menu JMenuItem newAction = new JMenuItem("Pythagoras"); JMenuItem openAction = new JMenuItem("Quit"); fileMenu.add(newAction); fileMenu.add(openAction); newAction.addActionListner(new PythagorusListener()); openAction.addActionListner(new CloseListener()); // Add a listener to the New menu item. actionPerformed() method will // invoked, if user triggred this menu item newAction.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println("You have clicked on the new action"); } }); } public static void main(String[] args) { MenuExp me = new MenuExp(); me.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); me.setVisible(true); } } public class CloseListener implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { //DO SOMETHING
  • 3. System.exit(0); } } public class PythagorusListener implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { setSize(900, 900); setTitle("Pythagoras tree"); add(new Draw(n)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } } class Draw extends JComponent { private int height = 800; private int width = 800; private int steps; public Draw(int n) { steps = n; Dimension d = new Dimension(width, height); setMinimumSize(d); setPreferredSize(d); setMaximumSize(d); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.white); g.fillRect(0, 0, width, height); g.setColor(Color.black); int x1, x2, x3, y1, y2, y3; int base = width/7; x1 = (width/2)-(base/2); x2 = (width/2)+(base/2); x3 = width/2;
  • 4. y1 = (height-(height/15))-base; y2 = height-(height/15); y3 = (height-(height/15))-(base+(base/2)); //paint g.drawPolygon(new int[]{x1, x1, x2, x2, x1}, new int[]{y1, y2, y2, y1, y1}, 5); int n1 = steps; if(--n1 > 0){ g.drawPolygon(new int[] {x1, x3, x2}, new int[] {y1, y3, y1}, 3); paintMore(n1, g, x1, x3, x2, y1, y3, y1); paintMore(n1, g, x2, x3, x1, y1, y3, y1); } } public void paintMore(int n1, Graphics g, double x1_1, double x2_1, double x3_1, double y1_1, double y2_1, double y3_1){ double x1, x2, x3, y1, y2, y3; //counting x1 = x1_1 + (x2_1-x3_1); x2 = x2_1 + (x2_1-x3_1); x3 = ((x2_1 + (x2_1-x3_1)) + ((x2_1-x3_1)/2)) + ((x1_1-x2_1)/2); y1 = y1_1 + (y2_1-y3_1); y2 = y2_1 + (y2_1-y3_1); y3 = ((y1_1 + (y2_1-y3_1)) + ((y2_1-y1_1)/2)) + ((y2_1-y3_1)/2); //paint g.setColor(Color.green); g.drawPolygon(new int[] {(int)x1, (int)x2, (int)x2_1, (int)x1}, new int[] {(int)y1, (int)y2, (int)y2_1, (int)y1}, 4); g.drawLine((int)x1, (int)y1, (int)x1_1, (int)y1_1); g.drawLine((int)x2_1, (int)y2_1, (int)x2, (int)y2); g.drawLine((int)x1, (int)y1, (int)x2, (int)y2); if(--n1 > 0){ g.drawLine((int)x1, (int)y1, (int)x3, (int)y3); g.drawLine((int)x2, (int)y2, (int)x3, (int)y3); paintMore(n1, g, x1, x3, x2, y1, y3, y2); paintMore(n1, g, x2, x3, x1, y2, y3, y1); } }
  • 5. }