Below I attach 2 documents of my code. How can i modify my code so that i am able to get the preferred output. The output i wish to have is when i click on the gui, either circle or rectangle of a fixed size will be drawn on the location i clicked on. But the output i got now is a circle or rectangle drawn at top left corner and when i click on the gui, nothing happen. My question is a bit long, hope u can reply me back. Thank you very much.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Below I attach 2 documents of my code. How can i modify my code so that i am able to get the preferred output. The output i wish to have is when i click on the gui, either circle or rectangle of a fixed size will be drawn on the location i clicked on. But the output i got now is a circle or rectangle drawn at top left corner and when i click on the gui, nothing happen. My question is a bit long, hope u can reply me back. Thank you very much.

e K16SO - FinalExamSem2/src/MyFrame.java - Eclipse IDE
File Edit Source Refactor Navigate Search Project Run Window Help
▼圖|品
E * - O - & - 4 -
即圓 T:
I Package Explorer 8 Ju JUnit
D MyShape.java
D MyFrame.java X D DrawTester.java
D RandomLine.java
1® import javax.swing.JFrame;
> E ANN
12
13 public class MyFrame extends JFrame
14 {
> S ANNCHallenge
> S Arrays
> S Employee
> E FinalExamSem2
private ArrayList<Shape> shape;
public static int x,y;
private JFrame frame;
private MyShape m;
15
16
17
> S Food
18
> S FoodOrderingSystem
> S Hangman
> E Inheritance
19
public MyFrame ()
{
frame = new JFrame();
frame.setSize(500,500);
frame.setTitle("K17SD Final Exam");
frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE);
m = new MyShape (shape);
frame.add(m);
MousePressListener mpl = new MousePressListener();
frame.addMouselistener(mpl);
frame.setVisible(true);
}
200
21
22
> E Iteration
23
> > k16so_2020_april_lab7 [k16so_2020_
> E > k16so_2020_april_tut2 [k16so_2020_a
> E > k16so_2020_april_tut3 [k16so_2020_a
> G > k16so_2020_april_tut5 [k16so_2020_a
> G k16so_2020_april-lab1_k16so_2020_api
> E > k16so_2020_april-lab10 [k16so_2020
> G > k16so_2020_april-lab2 [k16so_2020_
> G > k16so_2020_april-lab3 [k16so_2020
> E > k16so_2020_april-lab4 [k16so_2020_
> E > k16so_2020_april-lab5 [k16so_2020_
> E > k16so_2020_april-lab6 [k16so_2020_
> G > k16so_2020_april-lab8 [k16so_2020_
> > k16so_2020_april-lab9 [k16so_2020_
> G > k17sd_2020_april_s2-foxandrabbit [k
> E > k17sd_2020_april_s2-lab10 [k17sd_20
> E > k17sd_2020_april_s2-lab11 [k17sd_20
> > k17sd_2020_april_s2-lab3 [k17sd_202
> > k17sd_2020_april_s2-lab4 [k17sd_202
> G > k17sd_2020_april_s2-lab5 [k17sd_202
> E > k17sd_2020_april_s2-lab6 [k17sd_202
> G > k17sd_2020_april_s2-lab7 [k17sd_202
> > k17sd_2020_april_s2-lab8 [k17sd_202
> E > k17sd_2020_april_s2-lab9 [k17sd_202
> G > k17sd_2020_april_s2-practical1 [k17s
> G > k17sd_2020_september-lab2 [k17sd_
> > k17sd_2020_september-zuul-bad [k1
A > k17sd 2020 september-zuul-better i
24
25
26
27
28
29
30
31
32
class MousePressListener implements Mouselistener
{
public void mouseClicked (MouseEvent e)
{
x = e.getX();
y = e.getY();
repaint();
}
330
34
A350
36
37
38
39
40
41
public void mousePressed (MouseEvent e) {}
public void mouseReleased (MouseEvent e) {}
public void mouseEntered (MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
A42
443
A44
445
46
public int getx()
{
470
48
国A
A Problems @ Javadoc E Declaration e Console 8 3 Progress & Git Staging
<terminated> DrawTester [Java Application] C:\Program Files\Java\jdk-14.0.1\bin\javaw.exe (7 Dec 2020, 6:42:10 pm – 6:42:17 pm)
Writable
Smart Insert
16:27:420
6:42 PM
O 4) G ENG
7/12/2020
Transcribed Image Text:e K16SO - FinalExamSem2/src/MyFrame.java - Eclipse IDE File Edit Source Refactor Navigate Search Project Run Window Help ▼圖|品 E * - O - & - 4 - 即圓 T: I Package Explorer 8 Ju JUnit D MyShape.java D MyFrame.java X D DrawTester.java D RandomLine.java 1® import javax.swing.JFrame; > E ANN 12 13 public class MyFrame extends JFrame 14 { > S ANNCHallenge > S Arrays > S Employee > E FinalExamSem2 private ArrayList<Shape> shape; public static int x,y; private JFrame frame; private MyShape m; 15 16 17 > S Food 18 > S FoodOrderingSystem > S Hangman > E Inheritance 19 public MyFrame () { frame = new JFrame(); frame.setSize(500,500); frame.setTitle("K17SD Final Exam"); frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); m = new MyShape (shape); frame.add(m); MousePressListener mpl = new MousePressListener(); frame.addMouselistener(mpl); frame.setVisible(true); } 200 21 22 > E Iteration 23 > > k16so_2020_april_lab7 [k16so_2020_ > E > k16so_2020_april_tut2 [k16so_2020_a > E > k16so_2020_april_tut3 [k16so_2020_a > G > k16so_2020_april_tut5 [k16so_2020_a > G k16so_2020_april-lab1_k16so_2020_api > E > k16so_2020_april-lab10 [k16so_2020 > G > k16so_2020_april-lab2 [k16so_2020_ > G > k16so_2020_april-lab3 [k16so_2020 > E > k16so_2020_april-lab4 [k16so_2020_ > E > k16so_2020_april-lab5 [k16so_2020_ > E > k16so_2020_april-lab6 [k16so_2020_ > G > k16so_2020_april-lab8 [k16so_2020_ > > k16so_2020_april-lab9 [k16so_2020_ > G > k17sd_2020_april_s2-foxandrabbit [k > E > k17sd_2020_april_s2-lab10 [k17sd_20 > E > k17sd_2020_april_s2-lab11 [k17sd_20 > > k17sd_2020_april_s2-lab3 [k17sd_202 > > k17sd_2020_april_s2-lab4 [k17sd_202 > G > k17sd_2020_april_s2-lab5 [k17sd_202 > E > k17sd_2020_april_s2-lab6 [k17sd_202 > G > k17sd_2020_april_s2-lab7 [k17sd_202 > > k17sd_2020_april_s2-lab8 [k17sd_202 > E > k17sd_2020_april_s2-lab9 [k17sd_202 > G > k17sd_2020_april_s2-practical1 [k17s > G > k17sd_2020_september-lab2 [k17sd_ > > k17sd_2020_september-zuul-bad [k1 A > k17sd 2020 september-zuul-better i 24 25 26 27 28 29 30 31 32 class MousePressListener implements Mouselistener { public void mouseClicked (MouseEvent e) { x = e.getX(); y = e.getY(); repaint(); } 330 34 A350 36 37 38 39 40 41 public void mousePressed (MouseEvent e) {} public void mouseReleased (MouseEvent e) {} public void mouseEntered (MouseEvent e) {} public void mouseExited(MouseEvent e) {} A42 443 A44 445 46 public int getx() { 470 48 国A A Problems @ Javadoc E Declaration e Console 8 3 Progress & Git Staging <terminated> DrawTester [Java Application] C:\Program Files\Java\jdk-14.0.1\bin\javaw.exe (7 Dec 2020, 6:42:10 pm – 6:42:17 pm) Writable Smart Insert 16:27:420 6:42 PM O 4) G ENG 7/12/2020
e K16SO - FinalExamSem2/src/MyShape.java - Eclipse IDE
File Edit Source Refactor Navigate Search Project Run Window Help
▼圖 园
I Package Explorer & Ju JUnit
D DrawTester.java
D RandomLine.java
D MyShape.java X D MyFrame.java
1® import java.awt.Color;
> E ANN
13
> S ANNCHallenge
> S Arrays
> S Employee
> E FinalExamSem2
14 public class MyShape extends JComponent
15 {
16
private ArrayList<Shape> myshape;
17
private int count = 0;
int x = MyFrame.x;
int y = MyFrame.y;
18
> S Food
19
> S FoodOrderingSystem
> S Hangman
> E Inheritance
20
public MyShape (ArrayList<Shape> m)
{
myshape=m;
}
210
22
23
> E Iteration
24
> > k16so_2020_april_lab7 [k16so_2020_
> E > k16so_2020_april_tut2 [k16so_2020_a
> E > k16so_2020_april_tut3 [k16so_2020_a
> G > k16so_2020_april_tut5 [k16so_2020_a
> G k16so_2020_april-lab1_k16so_2020_api
> E > k16so_2020_april-lab10 [k16so_2020
> G > k16so_2020_april-lab2 [k16so_2020_
> G > k16so_2020_april-lab3 [k16so_2020
> E > k16so_2020_april-lab4 [k16so_2020_
> E > k16so_2020_april-lab5 [k16so_2020_
> E > k16so_2020_april-lab6 [k16so_2020_
> G > k16so_2020_april-lab8 [k16so_2020_
> > k16so_2020_april-lab9 [k16so_2020_
> G > k17sd_2020_april_s2-foxandrabbit [k
> E > k17sd_2020_april_s2-lab10 [k17sd_20
> E > k17sd_2020_april_s2-lab11 [k17sd_20
> > k17sd_2020_april_s2-lab3 [k17sd_202
> > k17sd_2020_april_s2-lab4 [k17sd_202
> G > k17sd_2020_april_s2-lab5 [k17sd_202
> E > k17sd_2020_april_s2-lab6 [k17sd_202
> G > k17sd_2020_april_s2-lab7 [k17sd_202
> > k17sd_2020_april_s2-lab8 [k17sd_202
> E > k17sd_2020_april_s2-lab9 [k17sd_202
> G > k17sd_2020_april_s2-practical1 [k17s
> G > k17sd_2020_september-lab2 [k17sd_
> > k17sd_2020_september-zuul-bad [k1
A > k17sd 2020 september-zuul-better i
25
260
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 }
public void paintComponent (Graphics g)
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2. setColor(Color.RED);
Random ran = new Random();
count = ran.nextInt (2);
if(count == 0)
{
Rectangle rnew = new Rectangle(x, y, 30, 30);
g2. draw(rnew);|
}
else
{
Ellipse2D.Double cnew = new Ellipse2D.Double(x, y, 30, 30);
g2.draw(cnew);
}
}
45
图
A Problems @ Javadoc e Declaration e Console 8 3 Progress Git Staging
<terminated> DrawTester [Java Application] C:\Program Files\Java\jdk-14.0.1\bin\javaw.exe (7 Dec 2020, 6:42:10 pm – 6:42:17 pm)
Writable
Smart Insert
36:27:824
6:43 PM
O 4) G ENG
7/12/2020
Transcribed Image Text:e K16SO - FinalExamSem2/src/MyShape.java - Eclipse IDE File Edit Source Refactor Navigate Search Project Run Window Help ▼圖 园 I Package Explorer & Ju JUnit D DrawTester.java D RandomLine.java D MyShape.java X D MyFrame.java 1® import java.awt.Color; > E ANN 13 > S ANNCHallenge > S Arrays > S Employee > E FinalExamSem2 14 public class MyShape extends JComponent 15 { 16 private ArrayList<Shape> myshape; 17 private int count = 0; int x = MyFrame.x; int y = MyFrame.y; 18 > S Food 19 > S FoodOrderingSystem > S Hangman > E Inheritance 20 public MyShape (ArrayList<Shape> m) { myshape=m; } 210 22 23 > E Iteration 24 > > k16so_2020_april_lab7 [k16so_2020_ > E > k16so_2020_april_tut2 [k16so_2020_a > E > k16so_2020_april_tut3 [k16so_2020_a > G > k16so_2020_april_tut5 [k16so_2020_a > G k16so_2020_april-lab1_k16so_2020_api > E > k16so_2020_april-lab10 [k16so_2020 > G > k16so_2020_april-lab2 [k16so_2020_ > G > k16so_2020_april-lab3 [k16so_2020 > E > k16so_2020_april-lab4 [k16so_2020_ > E > k16so_2020_april-lab5 [k16so_2020_ > E > k16so_2020_april-lab6 [k16so_2020_ > G > k16so_2020_april-lab8 [k16so_2020_ > > k16so_2020_april-lab9 [k16so_2020_ > G > k17sd_2020_april_s2-foxandrabbit [k > E > k17sd_2020_april_s2-lab10 [k17sd_20 > E > k17sd_2020_april_s2-lab11 [k17sd_20 > > k17sd_2020_april_s2-lab3 [k17sd_202 > > k17sd_2020_april_s2-lab4 [k17sd_202 > G > k17sd_2020_april_s2-lab5 [k17sd_202 > E > k17sd_2020_april_s2-lab6 [k17sd_202 > G > k17sd_2020_april_s2-lab7 [k17sd_202 > > k17sd_2020_april_s2-lab8 [k17sd_202 > E > k17sd_2020_april_s2-lab9 [k17sd_202 > G > k17sd_2020_april_s2-practical1 [k17s > G > k17sd_2020_september-lab2 [k17sd_ > > k17sd_2020_september-zuul-bad [k1 A > k17sd 2020 september-zuul-better i 25 260 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 } public void paintComponent (Graphics g) super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2. setColor(Color.RED); Random ran = new Random(); count = ran.nextInt (2); if(count == 0) { Rectangle rnew = new Rectangle(x, y, 30, 30); g2. draw(rnew);| } else { Ellipse2D.Double cnew = new Ellipse2D.Double(x, y, 30, 30); g2.draw(cnew); } } 45 图 A Problems @ Javadoc e Declaration e Console 8 3 Progress Git Staging <terminated> DrawTester [Java Application] C:\Program Files\Java\jdk-14.0.1\bin\javaw.exe (7 Dec 2020, 6:42:10 pm – 6:42:17 pm) Writable Smart Insert 36:27:824 6:43 PM O 4) G ENG 7/12/2020
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY