-
Notifications
You must be signed in to change notification settings - Fork 0
/
CircleView1.java
executable file
·38 lines (38 loc) · 1.02 KB
/
CircleView1.java
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
import java.awt.*;
import java.awt.event.*;
public class CircleView1 extends javax.swing.JPanel
implements ActionListener
{ private static final long serialVersionUID = 1L;
private CircleModel1 model;
@Override
public void actionPerformed(ActionEvent actionEvent)
{ repaint();
}
/** Set a model */
public void setModel(CircleModel1 newModel)
{ model = newModel;
if (model != null)
// Register the view as listener for the model
model.addActionListener(this);
//repaint();
}
public CircleModel1 getModel()
{ return model;
}
public void paintComponent(Graphics g)
{ super.paintComponent(g);
if (model == null) return;
g.setColor(model.getColor());
int xCenter = getWidth() / 2;
int yCenter = getHeight() / 2;
int radius = (int)model.getRadius();
if (model.isFilled())
{ g.fillOval(xCenter - radius, yCenter - radius,
2 * radius, 2 * radius);
}
else
{ g.drawOval(xCenter - radius, yCenter - radius,
2 * radius, 2 * radius);
}
}
}