-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPanel.java
More file actions
80 lines (51 loc) · 1.28 KB
/
CPanel.java
File metadata and controls
80 lines (51 loc) · 1.28 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
package df;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;
import javax.swing.JPanel;
public class CPanel extends JPanel implements ActionListener, KeyListener{
private int a;
private int b;
private int c;
@Override
public void keyTyped(KeyEvent e) {
a = new Random().nextInt(255);
b = new Random().nextInt(255);
c = new Random().nextInt(255);
//draw(getGraphics());
}
public void draw(Graphics g) {
g.setColor(new Color(a,b,c));
g.fillRect(0,0,1000,1000);
if((a+b+c)/3 > 150 || (a+b+c)>370) {
g.setColor(Color.BLACK);
}
else {
g.setColor(Color.WHITE);
}
g.drawString("("+a+","+b+","+c+")", 10 , 20);
g.drawString("Brightness Level:" + (a+b+c)/3, 10, 40);
repaint();
}
@Override
public void paintComponent(Graphics g){
draw(g);
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}