Commit | Line | Data |
---|---|---|
21c4e167 H |
1 | import javax.swing.*; |
2 | import java.awt.*; | |
3 | ||
4 | class DrawingCanvas extends Canvas { | |
5 | public DrawingCanvas() { | |
6 | setSize(100, 50); | |
7 | } | |
8 | public String text = new String("LOOOL"); | |
9 | public void paint(Graphics g) { | |
10 | createBufferStrategy(2); //double buffered | |
11 | ||
12 | Graphics2D g2D=(Graphics2D) g; // cast to 2D | |
13 | g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, | |
14 | RenderingHints.VALUE_ANTIALIAS_ON); | |
15 | ||
16 | ||
17 | g.drawRect(0, 0, 99, 49); // draw border | |
18 | g.drawString(text, 20,20); | |
19 | } | |
20 | } | |
21 | ||
22 | public class canvas { | |
23 | public static void main(String[] args) throws InterruptedException { | |
24 | JFrame window = new JFrame(); | |
25 | window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
26 | window.setSize(640,480); | |
27 | window.setTitle("hello"); | |
28 | window.setVisible(true); | |
29 | ||
30 | DrawingCanvas canvas = new DrawingCanvas(); | |
31 | window.getContentPane().add(canvas); | |
32 | ||
33 | Thread.sleep(2000); | |
34 | canvas.text="omg"; | |
35 | canvas.repaint(); | |
36 | } | |
37 | } |