C gitignore improvements
[mirrors/Programs.git] / java / pokusy / canvas.java
CommitLineData
21c4e167
H
1import javax.swing.*;
2import java.awt.*;
3
4class 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
22public 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}
This page took 0.422665 seconds and 4 git commands to generate.