-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.java
More file actions
51 lines (46 loc) · 1.1 KB
/
Copy pathView.java
File metadata and controls
51 lines (46 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//Name: Jacob Smith
//Date: 9/11/20
//Description: The point of his class is to create and hold the
//code that we use for the JButton and the image of the turtle. Also this
//is where the JPanel info of the code is held`
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.io.File;
import javax.swing.JButton;
import java.awt.Color;
class View extends JPanel
{
JButton b1;
BufferedImage turtle_image;
Model model;
View(Controller c, Model m)
{
model = m;
b1 = new JButton("Hey Press me if you dare!");
b1.addActionListener(c);
this.add(b1);
c.setView(this);
try
{
this.turtle_image =
ImageIO.read(new File("turtle.png"));
} catch(Exception e) {
e.printStackTrace(System.err);
System.exit(1);
}
}
void removeButton()
{
this.remove(b1);
this.repaint();
}
public void paintComponent(Graphics g)
{
g.setColor(new Color(128, 255, 255));
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.drawImage(this.turtle_image, model.turtle_x, model.turtle_y, null);
}
}