-
Notifications
You must be signed in to change notification settings - Fork 0
/
RotatePanel.java
44 lines (37 loc) · 1.12 KB
/
RotatePanel.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
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class RotatePanel extends JPanel {
public RotatePanel() {
this.setPreferredSize(new Dimension(320, 240));
this.add(new JLabel("Hello World!", JLabel.CENTER));
}
@Override
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
int w2 = getWidth() / 2;
int h2 = getHeight() / 2;
g2d.rotate(-Math.PI / 2, w2, h2);
super.paintComponent(g);
}
private void display() {
JFrame f = new JFrame("RotatePanel");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new RotatePanel().display();
}
});
}
}