Hot 15 Update

2024-01-22 2023-09-17 2023-05-21 2023-02-17 2022-12-02 2022-11-27 2022-11-26 2022-10-07 2022-10-03

topJava教室 ≫ たくさんの画像を並べる 更新: 2023.05.21 (342d)

たくさんの画像を並べる


import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.applet.*;
import java.awt.*;

public class puzzle2 extends Applet
{
    int gazou = 16;			// 画像の枚数
    Image img[] = new Image[gazou];
    public void init()		// 画像の読み込み
    {
	img[0] = getImage(getDocumentBase(), "image/0.gif");
	img[1] = getImage(getDocumentBase(), "image/1.gif");
	img[2] = getImage(getDocumentBase(), "image/2.gif");
	img[3] = getImage(getDocumentBase(), "image/3.gif");
	img[4] = getImage(getDocumentBase(), "image/4.gif");
	img[5] = getImage(getDocumentBase(), "image/5.gif");
	img[6] = getImage(getDocumentBase(), "image/6.gif");
	img[7] = getImage(getDocumentBase(), "image/7.gif");
	img[8] = getImage(getDocumentBase(), "image/8.gif");
	img[9] = getImage(getDocumentBase(), "image/9.gif");
	img[10] = getImage(getDocumentBase(), "image/10.gif");
	img[11] = getImage(getDocumentBase(), "image/11.gif");
	img[12] = getImage(getDocumentBase(), "image/12.gif");
	img[13] = getImage(getDocumentBase(), "image/13.gif");
	img[14] = getImage(getDocumentBase(), "image/14.gif");
	img[15] = getImage(getDocumentBase(), "image/15.gif");

    }
    
    public void paint(Graphics g) // 画像表示
    {
	g.drawImage( img[1],0,0, this );
	g.drawImage( img[2],50,0, this );
	g.drawImage( img[3],100,0, this );
	g.drawImage( img[4],150,0, this );

	g.drawImage( img[5],0,50, this );
	g.drawImage( img[6],50,50, this );
	g.drawImage( img[7],100,50, this );
	g.drawImage( img[8],150,50, this );

	g.drawImage( img[9],0,100, this );
	g.drawImage( img[10],50,100, this );
	g.drawImage( img[11],100,100, this );
	g.drawImage( img[12],150,100, this );

	g.drawImage( img[13],0,150, this );
	g.drawImage( img[14],50,150, this );
	g.drawImage( img[15],100,150, this );
	g.drawImage( img[0],150,150, this );

    }
}





img[0] = getImage(getDocumentBase(), "image/0.gif");
img[1] = getImage(getDocumentBase(), "image/1.gif");
img[2] = getImage(getDocumentBase(), "image/2.gif");
・
・
・
・
g.drawImage( img[1],0,0, this );
g.drawImage( img[2],50,0, this );
g.drawImage( img[3],100,0, this );
・
・
・
・


//表示部分にfor分を使った画像表示
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.applet.*;
import java.awt.*;

public class puzzle3 extends Applet
{
    int gazou = 16;			// 画像の枚数
    Image img[] = new Image[gazou];
    public void init()		// 画像の読み込み
    {

	img[0] = getImage(getDocumentBase(), "image/0.gif");
	img[1] = getImage(getDocumentBase(), "image/1.gif");
	img[2] = getImage(getDocumentBase(), "image/2.gif");
	img[3] = getImage(getDocumentBase(), "image/3.gif");
	img[4] = getImage(getDocumentBase(), "image/4.gif");
	img[5] = getImage(getDocumentBase(), "image/5.gif");
	img[6] = getImage(getDocumentBase(), "image/6.gif");
	img[7] = getImage(getDocumentBase(), "image/7.gif");
	img[8] = getImage(getDocumentBase(), "image/8.gif");
	img[9] = getImage(getDocumentBase(), "image/9.gif");
	img[10] = getImage(getDocumentBase(), "image/10.gif");
	img[11] = getImage(getDocumentBase(), "image/11.gif");
	img[12] = getImage(getDocumentBase(), "image/12.gif");
	img[13] = getImage(getDocumentBase(), "image/13.gif");
	img[14] = getImage(getDocumentBase(), "image/14.gif");
	img[15] = getImage(getDocumentBase(), "image/15.gif");

    }
    
    public void paint(Graphics g) // 画像表示
    {
	int j=0;
	    for(int y=0; y<=150; y+=50){ // 画像サイズが50×50だから,y軸を50ずつ増やしていく。
		for(int x=0; x<=150; x+=50){ // 画像サイズが50×50だから,x軸を50ずつ増やしていく。
		    g.drawImage( img[(j+1)%16],x,y, this );
		    j++;	// jを増やさないと,全部同じ画像になる。
		}
	    }
    }
}


for(int y=0; y<=150; y+=50){ // 画像サイズが50×50だから,y軸を50ずつ増やしていく。
    for(int x=0; x<=150; x+=50){ // 画像サイズが50×50だから,x軸を50ずつ増やしていく。


g.drawImage( img[(j+1)%16],x,y, this );


j++;




//for分を使った画像表示
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.applet.*;
import java.awt.*;

public class puzzle4 extends Applet
{
    int gazou = 16;			// 画像の枚数
    Image img[] = new Image[gazou];
    public void init()		// 画像の読み込み
    {
	String filename;		// 文字列の宣言。
	for(int j=0; j<gazou; j++){	// 0から15まで回す。画像が0から15だから。
	    filename = "image/" + j + ".gif"; // +で文字列と文字列をくっつける。
	    img[j] = getImage(getDocumentBase(), filename );
	}

	
    }
    
    public void paint(Graphics g) // 画像表示
    {
	int j=0;
	    for(int y=0; y<=150; y+=50){ // 画像サイズが50×50だから,y軸を50ずつ増やしていく。
		for(int x=0; x<=150; x+=50){ // 画像サイズが50×50だから,x軸を50ずつ増やしていく。
		    g.drawImage( img[(j+1)%16],x,y, this );
		    j++;	// jを増やさないと,全部同じ画像になる。
		}
	    }
    }
}







選択肢 投票
32  


添付ファイル: file0.gif 917件 [詳細] file1.gif 846件 [詳細] file2.gif 823件 [詳細] file3.gif 798件 [詳細] file4.gif 815件 [詳細] file5.gif 798件 [詳細] file6.gif 820件 [詳細] file7.gif 781件 [詳細] file8.gif 782件 [詳細] file9.gif 750件 [詳細] file10.gif 782件 [詳細] file11.gif 823件 [詳細] file12.gif 804件 [詳細] file13.gif 814件 [詳細] file14.gif 835件 [詳細] file15.gif 782件 [詳細] filepuzzle4.html 767件 [詳細] filepuzzle4.java 692件 [詳細] filepuzzle3.html 808件 [詳細] filepuzzle3.java 635件 [詳細] filepuzzle2.html 791件 [詳細] filepuzzle2.java 664件 [詳細] filepuzzle2.gif 2636件 [詳細]


topJava教室 ≫ たくさんの画像を並べる