Werken Met Afbeeldingen
Auteur: Ontani - 17 maart 2005 - 13:36 - Gekeurd door: Joel - Hits: 7945 - Aantal punten: 3.00 (8 stemmen)
plaats de afbeeldingen in een map "images" naast de webpagina die gebruikt maakt van de applet.
dit appletje is geschreven om wat te spelen met afbeeldingen.
alle gif bestanden hebben een transparante achtergrond.
en worden random op de achtergrond geplaatst
ik had problemen met doorlopen van de array dus teken ik ze een voor een.
Vragen? Stel ze hier of mail naar ontani [at] ontani [dotterdedot] net
|
Code: |
package afbeeldingen;
import java.awt.*;
import java.applet.*;
public class Afbeelding extends Applet {
Image background;
Image[] smilies;
int xPos, yPos, smilieWidth, smilieHeight;
public void init() {
// instellen van de grootte van de afbeeldingen
smilieWidth = 19;
smilieHeight = 19;
smilies = new Image[11];
smilies[0] = getImage(getDocumentBase(), "images/amazed.gif");
smilies[1] = getImage(getDocumentBase(), "images/bigsmile.gif");
smilies[2] = getImage(getDocumentBase(), "images/cool.gif");
smilies[3] = getImage(getDocumentBase(), "images/cry.gif");
smilies[4] = getImage(getDocumentBase(), "images/huh.gif");
smilies[5] = getImage(getDocumentBase(), "images/mad.gif");
smilies[6] = getImage(getDocumentBase(), "images/rolleyes.gif");
smilies[7] = getImage(getDocumentBase(), "images/sick.gif");
smilies[8] = getImage(getDocumentBase(), "images/smile.gif");
smilies[9] = getImage(getDocumentBase(), "images/tounge.gif");
smilies[10] = getImage(getDocumentBase(), "images/wink.gif");
background = getImage(getDocumentBase(), "images/achtergrond.jpg");
}
public void paint(Graphics g) {
g.drawImage(background, 0, 0, 640, 480, this);
g.drawImage(smilies[0], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this);
g.drawImage(smilies[1], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this);
g.drawImage(smilies[2], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this);
g.drawImage(smilies[3], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this);
g.drawImage(smilies[4], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this);
g.drawImage(smilies[5], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this);
g.drawImage(smilies[6], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this);
g.drawImage(smilies[7], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this);
g.drawImage(smilies[8], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this);
g.drawImage(smilies[9], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this);
g.drawImage(smilies[10], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this);
}
}
package afbeeldingen; import java.awt.*; import java.applet.*; public class Afbeelding extends Applet { Image background; Image[] smilies; int xPos, yPos, smilieWidth, smilieHeight; public void init() { // instellen van de grootte van de afbeeldingen smilieWidth = 19; smilieHeight = 19; smilies = new Image[11]; smilies[0] = getImage(getDocumentBase(), "images/amazed.gif"); smilies[1] = getImage(getDocumentBase(), "images/bigsmile.gif"); smilies[2] = getImage(getDocumentBase(), "images/cool.gif"); smilies[3] = getImage(getDocumentBase(), "images/cry.gif"); smilies[4] = getImage(getDocumentBase(), "images/huh.gif"); smilies[5] = getImage(getDocumentBase(), "images/mad.gif"); smilies[6] = getImage(getDocumentBase(), "images/rolleyes.gif"); smilies[7] = getImage(getDocumentBase(), "images/sick.gif"); smilies[8] = getImage(getDocumentBase(), "images/smile.gif"); smilies[9] = getImage(getDocumentBase(), "images/tounge.gif"); smilies[10] = getImage(getDocumentBase(), "images/wink.gif"); background = getImage(getDocumentBase(), "images/achtergrond.jpg"); } public void paint(Graphics g) { g.drawImage(background, 0, 0, 640, 480, this); g.drawImage(smilies[0], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this); g.drawImage(smilies[1], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this); g.drawImage(smilies[2], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this); g.drawImage(smilies[3], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this); g.drawImage(smilies[4], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this); g.drawImage(smilies[5], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this); g.drawImage(smilies[6], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this); g.drawImage(smilies[7], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this); g.drawImage(smilies[8], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this); g.drawImage(smilies[9], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this); g.drawImage(smilies[10], (int)(640 * Math.random()), (int)(480 * Math.random()), smilieWidth, smilieHeight, this); } }
Download code (.txt)
|
|
|
Stemmen |
Niet ingelogd. |
|