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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
| import java.applet.Applet; import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.lang.StrictMath; import java.util.*; public class GradientPaintEx extends JFrame { myCustomCanvas mc; JSlider p1slide, p2slide; JRadioButton cyclic_rb, acyclic_rb; public GradientPaintEx() { super("GradientPaint examples"); BorderLayout f1 = new BorderLayout(); Panel uipanel = new Panel(); p1slide = new JSlider(); p2slide = new JSlider(); cyclic_rb = new JRadioButton(); acyclic_rb = new JRadioButton(); mc = new myCustomCanvas(this); mc.setSize(500,500); mc.setPaint(100,200); SliderListner sl = new SliderListner(this,mc); // compiler zegt: cannot resolve symbol p1slide.addSliderListner(sl); uipanel.add(cyclic_rb); uipanel.add(acyclic_rb); uipanel.add(p1slide); uipanel.add(p2slide); this.getContentPane().setLayout(f1); this.getContentPane().add(mc,BorderLayout.CENTER); this.getContentPane().add(uipanel,BorderLayout.NORTH); this.setSize(500,500); this.show(); addWindowListener(new WindowEventHandler()); } class WindowEventHandler extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } public static void main(String[] args) { new GradientPaintEx(); } }// end class SliderListner implements ChangeListener { GradientPaintEx gex; myCustomCanvas mc; int slider_val; public void SliderListner(GradientPaintEx gex, myCustomCanvas mc) { this.gex = gex; this.mc = mc; } public void stateChanged(ChangeEvent e) { int p1pos = gex.p1slide.getValue(); int p2pos = gex.p2slide.getValue(); mc.setPaint(p1pos,p2pos); } }// end class myCustomCanvas extends Canvas { GradientPaintEx gex; double p1pos, p2pos; GradientPaint gpaint; public myCustomCanvas(GradientPaintEx gex) { this.gex = gex; } public void setPaint(int p1pos, int p2pos) { this.p1pos = (double) p1pos; this.p2pos = (double) p2pos; boolean cycle = true; if (gex.cyclic_rb.isSelected()) cycle = true; else cycle = false; Point2D x = new Point2D.Double(p1pos,this.getSize().height/2); Point2D y = new Point2D.Double(p2pos,this.getSize().height/2); gpaint = new GradientPaint(x, Color.red, y, Color.green, cycle); repaint(); } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { gex.p1slide.setMaximum(this.getSize().width); gex.p2slide.setMaximum(this.getSize().width); Graphics2D g2d = (Graphics2D) g; g2d.setPaint(gpaint); g2d.fill(new Rectangle2D.Double(0, 0, this.getSize().width, this.getSize().height)); g2d.setColor(Color.black); BasicStroke stroke = new BasicStroke(4); g2d.setStroke(stroke); Line2D line1 = new Line2D.Double(p1pos,0,p1pos,this.getSize().height); g2d.draw(line1); Line2D line2 = new Line2D.Double(p2pos,0,p2pos,this.getSize().height); g2d.draw(line1); } }// end |
Cannot resolve symbol
(but again: zie ik er geen fout in?)
welcome my son, welcome to the machine