-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTriangle.java
More file actions
83 lines (64 loc) · 1.86 KB
/
Copy pathTriangle.java
File metadata and controls
83 lines (64 loc) · 1.86 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Programmer: Edgar Colin
// Student ID: EDG2140344
// Class: CIS263AA JAVA II Class # 12303
// Instructor: Michael Parmeley
// Chapter: 16 Advanced GUI part II
// Problem:2
// Part:
// Filename:Triangle.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Triangle extends
JFrame implements ActionListener
{
int flag;
JButton pressButton = new JButton("NORMAL");
JButton pressButton2 = new JButton("MIRROR");
public Triangle()
{
setTitle("Paint Demo");
setLayout(new FlowLayout());
add(pressButton);
pressButton.addActionListener(this);
add(pressButton2);
pressButton2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
flag++;
System.out.println(flag);
if (source == pressButton)
{
int xPoints[] = {150,200,250};
int yPoints[] = {200,100,200};
Graphics g1 = getGraphics();
g1.drawPolygon(xPoints, yPoints, xPoints.length);
flag--;
System.out.println(flag);
repaint();
}
else if (source == pressButton2)
{
int xPoints[] = {150,200,250};
int yPoints[] = {200,300,200};
Graphics g1 = getGraphics();
g1.drawPolygon(xPoints, yPoints, xPoints.length);
flag--;
}
}
public void paint(Graphics gr)
{
super.paint(gr);
int xPoints[] = {150,200,250};
int yPoints[] = {200,100,200};
gr.drawPolygon(xPoints, yPoints, xPoints.length);
}
public static void main(String[] args)
{
Triangle frame = new Triangle();
frame.setSize(400, 400);
frame.setVisible(true);
}
}