-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaintablePanel.java
More file actions
45 lines (29 loc) · 1 KB
/
PaintablePanel.java
File metadata and controls
45 lines (29 loc) · 1 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
package javaGUItesting;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class PaintablePanel extends JPanel implements ActionListener {
public void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D) g;
int red = (int) (Math.random() * 255);
int green = (int) (Math.random() * 255);
int blue = (int) (Math.random() * 255);
Color startColor = new Color(red, green, blue);
red = (int) (Math.random() * 255);
green = (int) (Math.random() * 255);
blue = (int) (Math.random() * 255);
Color endColor = new Color(red, green, blue);
GradientPaint gradient = new GradientPaint(70, 170, startColor, 170, 170, endColor);
g2.setPaint(gradient);
g2.fillRect(70, 70, 100, 100);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}