Results 1 to 4 of 4

Thread: What is the use of the Canvas class?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    12

    Question What is the use of the Canvas class?

    Could somebody please tell me what is the general function of the Canvas class under the java.awt package? Under what situation do I have to call this class for use? Thanx.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    It is generally subclassed and used as an area to paint things on.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    The canvas class is pretty fun to play with
    even if your not really into graphic
    programming. Below is a pretty
    simple example that i whipped up.
    Code:
     
      import java.awt.*;
      import java.awt.event.*; 
      
      public class Shape{  
        public static void main(String[] args){
        new Circle();
      }
     }
      class Circle extends Canvas{
    
       public Circle(){
    
       JFrame jf = new JFrame("Circle!");
        jf.addWindowListener(new WindowAdapter(){
           public void windowClosing(WindowEvent e){
              System.exit(0);
           }
        });
    
         Dimension size = jf.getSize();
         Insets i = jf.getInsets(); 
         int height = size.height - i.top - i.bottom;
         int width = size.width - i.left - i.right;
    
        this.setSize(height,width);
        jf.getContentPane().add(this);
        jf.setSize(400,300);
        jf.setVisible(true);
      }
     
       public void paint(Graphics g){
        g.setColor(Color.red);
        g.fillOval(50,50,50,50); 
       }
      }

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    12

    Talking

    Thanx buddy, I appreciate the example given.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width