SHARE
TWEET

Untitled

a guest Jul 19th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.*;      
  2. import javax.swing.*;  
  3.  
  4. public class CGTemplate extends JFrame
  5. {
  6.  
  7.    public static final int CANVAS_WIDTH  = 640;
  8.    public static final int CANVAS_HEIGHT = 480;
  9.  
  10.  
  11.    private DrawCanvas canvas;
  12.  
  13.    public CGTemplate() {
  14.       canvas = new DrawCanvas();  
  15.       canvas.setPreferredSize(new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT));
  16.  
  17.       Container cp = getContentPane();
  18.       cp.add(canvas);
  19.  
  20.       setDefaultCloseOperation(EXIT_ON_CLOSE);  
  21.       pack();            
  22.       setTitle("......");
  23.       setVisible(true);    
  24.    }
  25.  
  26.    private class DrawCanvas extends JPanel {
  27.  
  28.       public void paintComponent(Graphics g) {
  29.          super.paintComponent(g);    
  30.          setBackground(Color.BLACK);  
  31.  
  32.          g.setColor(Color.YELLOW);  
  33.          g.drawLine(30, 40, 100, 200);
  34.          g.drawOval(150, 180, 10, 10);
  35.          g.drawRect(200, 210, 20, 30);
  36.          g.setColor(Color.RED);    
  37.          g.fillOval(300, 310, 30, 50);
  38.          g.fillRect(400, 350, 60, 50);
  39.  
  40.          g.setColor(Color.WHITE);
  41.          g.setFont(new Font("Monospaced", Font.PLAIN, 12));
  42.          g.drawString("Testing custom drawing ...", 10, 20);
  43.       }
  44.    }
  45.  
  46.    
  47.    public static void main(String[] args) {
  48.      
  49.       SwingUtilities.invokeLater(new Runnable() {
  50.  
  51.          public void run() {
  52.             new CGTemplate();
  53.          }
  54.       });
  55.    }
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top