5. Зургийг засварлах шаардлага гарвал public boolean imageUpdate(Image theimg, int infoflags, int x, int y, int w, int h) Үүнд: theimg- Тухайн програмд ашиглагдаж байгаа зургийн нэр Infoflag- Binary image 5 RGB image 4 Intensity but not in standard range 3 Intensity image with values in standard range ([0,1] for single and double arrays, [0,255] for uint8 arrays, [0,65535] for uint16 arrays) 2 Indexed image data, 1 Type of Image Flags
6. import java.applet.Applet; import java.awt.*; Public class LoadImage&Scale extends JApplet{ Private Image logo1; Private ImageIcon logo2; Public void init() { Logo1=getImage(getDocumentBase(),”logo.gif”); Logo2.=new ImageIcon(“logo.gif”); } Public void paint (Graphics g){ g.drawImage(logo1,0,0,this); g.DrawImage(logo1,0,120,getWidth(),getHeight()-120,this); Logo2.paintIcon(this,g,180,0); } }
7. Displaying Images Дэлгэц дээр зургийг харуулахын тулд g.drawImage(image, 0, 0, this); Мөн g.drawImage(myImage, 90, 0, 300, 62, this); Дараахь байдлаар өргөтгөн ашиглаж болно. public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer) public abstract boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) public abstract boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) public abstract boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) drawImage() функц дараахь аргументуудтай : Image img –Зурагдах зураг int x, int y – x,y координат int width, int height - Зургийн урт, өргөн Color bgcolor – Backgound- ийн өнгө ImageObserver observer - An object that implements the ImageObserver interface. This registers the object as the image observer so that it's notified whenever new information about the image becomes available. Most components can simply specify this.
8. import java.awt.*; import java.applet.Applet; public class ImageDisplayer extends Applet { Image image; public void init() { image = getImage(getCodeBase(), "../images/rocketship.gif"); } public void paint(Graphics g) { g.drawImage(image, 0, 0, this); g.drawImage(image, 90, 0, 300, 62, this); } }
15. ...//Where instance variables are declared: Image stars; Image rocket; ...//In the init() method: stars = getImage(getCodeBase(), "../images/starfield.gif"); rocket = getImage(getCodeBase(), "../images/rocketship.gif"); ...//In the update() method: //Paint the frame into the image. paintFrame(offGraphics); ...//A new method: void paintFrame(Graphics g) { Dimension d = size(); int w; int h; //If we have a valid width and height for the background image, //draw it. w = stars.getWidth(this); h = stars.getHeight(this); if ((w > 0) && (h > 0)) { g.drawImage(stars, (d.width - w)/2, (d.height - h)/2, this); } //If we have a valid width and height for the background image, //draw it. w = rocket.getWidth(this); h = rocket.getHeight(this); if ((w > 0) && (h > 0)) { g.drawImage(rocket, ((frameNumber*5) % (w + d.width)) - w, (d.height - h)/2, this); }}
16. Audio Java хэлэнд түүнтэй харьцах дараахь 3 функц байдаг. public abstract void play() public abstract void loop() public abstract void stop() Тэдгээрийн хэрэглээг дараахь жижиг програм дээр харъя.