Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- public class CGTemplate extends JFrame
- {
- public static final int CANVAS_WIDTH = 640;
- public static final int CANVAS_HEIGHT = 480;
- private DrawCanvas canvas;
- public CGTemplate() {
- canvas = new DrawCanvas();
- canvas.setPreferredSize(new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT));
- Container cp = getContentPane();
- cp.add(canvas);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- pack();
- setTitle("......");
- setVisible(true);
- }
- private class DrawCanvas extends JPanel {
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- setBackground(Color.BLACK);
- g.setColor(Color.YELLOW);
- g.drawLine(30, 40, 100, 200);
- g.drawOval(150, 180, 10, 10);
- g.drawRect(200, 210, 20, 30);
- g.setColor(Color.RED);
- g.fillOval(300, 310, 30, 50);
- g.fillRect(400, 350, 60, 50);
- g.setColor(Color.WHITE);
- g.setFont(new Font("Monospaced", Font.PLAIN, 12));
- g.drawString("Testing custom drawing ...", 10, 20);
- }
- }
- public static void main(String[] args) {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- new CGTemplate();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement