JAVA - שיעור #10
1. Clipboard   flavors

2. Beans: components.  
     Visual programming: VisualBasic, Delphi (Borland).
     Characteristics: properties, events, reflection.
     Java Bean:  xxx --> getXxx(), setXxx(), isXxx().
          import java.beans.*;
          import java.lang.reflect.*;
          bean.getName();
          BeanInfo bi = Introspector.getBeanInfo(bean, 
                       java.lang.Object.class); 
          PropertyDescriptor properties [] =   
                                      bi.getPropertyDescriptors();
          properties.length
          properties[i].getPropertyType();

      jar:  Java Archive file 

3. Graphics:  Applet or Canvas
     paint(Graphics g)     Components

     import java.applet.Applet;
     import java.awt.Graphics;
     public class simpleApplet extends Applet {
          public void paint(Graphics g) {
               g.drawRect(10,10,100,75): }
     }

4. drawRect(int, int, int, int)
    drawRoundRect(int, int, int, int, int, int)
    drawString(String, int, int)
    fill3DRect(int, int, int, int, boolean)
    fillArc(int, int, int, int, int, int)
    fillOval(int, int, int, int)
    fillPolygon(int[], int[], int)


5. public void paint(Graphics g) {
         Font someFont = new Font("Courier",Font.BOLD,12);
         g.setFont(someFont);
         g.drawString("Some Text!",10,10);
    }

6. FontMetric someFontMetric = new FontMetric(someFont);
    int wordLength= someFontmetric.stringWidth("Hello there");
    int charLength = someFontmetric.charWidth('h');

7.Color(int, int, int)
  Color(int)
  Color(float, float, float)
  java.awt.Color -
      black, blue, cyan, darkGray, gray, green, lightGray, 
      magenta, orange, pink, red, white, yellow

    public void paint(Graphics g) {
        Color myColor = new Color(Color.green);
        g.setColor(myColor);
        g.fillRect(10,10,100,100);
    }

8. Applets: init, start, stop, destroy.
          paint, repaint, update.
public void update(Graphics g) {
    g.setColor(getBackground());
    g.fillRect(0,0,width,height);
    g.setColor(getForeground());
    paint(g);
 }
public void paint(Graphics g) { 
    }

9. Threads:  init, stop, destroy.



10. Double buffering.
import java.applet.Applet;
import java.awt.*;
public class singleBuffer extends Applet {
    public void init() {  }
    public void paint(Graphics g) {
        for (int x=0; x<size().width; x+=2) {
            g.drawLine(x,0,x,size().height); 
        }
        for (int y=0; y<xize().height; y+=2) {
            g.drawLine(0,y,size().width,y);  
        }
    }
}

import java.applet.Applet;
import java.awt.*;
public class doubleBuffer extends Applet {
    Image offScrImage;
    Graphics offScrGr;
    public void init() {
       offScrImage = createImage(size().width,size().height);
       offScrGr = offScrImage.getGraphics();
    }
    public void paint(Graphics g) {
        for (int x=0; x<size().width; x+=2) {
            offScrGr.drawLine(x,0,x,size().height);
        }
        for (int y=0; y<size().height; y+=2) {
            offScrGr.drawLine(0,y,size().width,y); 
        }
        g.drawImage(offScrImage,0,0,this);
    }
}