-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleFrameTest.java
More file actions
32 lines (29 loc) · 811 Bytes
/
SimpleFrameTest.java
File metadata and controls
32 lines (29 loc) · 811 Bytes
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
import javax.swing.JFrame;
import javax.swing.JComponent;
import java.awt.Toolkit;
import java.awt.Frame;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.Color;
public class SimpleFrameTest{
public static void main(String[] args){
JFrame frame = new JFrame();
MyComponent a = new MyComponent();
a.setBackground(Color.PINK);
frame.add(a);
frame.setSize(300,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class MyComponent extends JComponent{
public void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D)g;
Rectangle2D rect = new Rectangle2D.Double(50,50,100,100);
g2.setPaint(new Color(123,200,50));
System.out.println(Color.RED);
g2.fill(rect);
}
}