-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathAlgoFrame.java
More file actions
62 lines (42 loc) · 1.48 KB
/
Copy pathAlgoFrame.java
File metadata and controls
62 lines (42 loc) · 1.48 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
52
53
54
55
56
57
58
59
60
61
import java.awt.*;
import javax.swing.*;
import java.awt.geom.Ellipse2D;
public class AlgoFrame extends JFrame{
private int canvasWidth;
private int canvasHeight;
public AlgoFrame(String title, int canvasWidth, int canvasHeight){
super(title);
this.canvasWidth = canvasWidth;
this.canvasHeight = canvasHeight;
AlgoCanvas canvas = new AlgoCanvas();
setContentPane(canvas);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
}
public AlgoFrame(String title){
this(title, 1024, 768);
}
public int getCanvasWidth(){return canvasWidth;}
public int getCanvasHeight(){return canvasHeight;}
private class AlgoCanvas extends JPanel{
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
int strokeWidth = 5;
g2d.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g2d.setColor(Color.RED);
Ellipse2D circle = new Ellipse2D.Double(50, 50, 300, 300);
g2d.draw(circle);
g2d.setColor(Color.BLUE);
Ellipse2D circle2 = new Ellipse2D.Double(50, 50, 300, 300);
g2d.fill(circle2);
}
@Override
public Dimension getPreferredSize(){
return new Dimension(canvasWidth, canvasHeight);
}
}
}