import java.awt.*;
import java.awt.image.*;public class jwmem extends java.applet.Applet
{
Image i;
int width = 200;
int height = 200;
public void init()
{
int[] pixels = new int[width * height];
int c;
double radianConversion = Math.PI / 180.0;
for(int index = 0, y = 0; y < height; y ++ )
{
c = ((0xff) & (byte)(Math.abs(Math.sin((y + height) * radianConversion)) * 255));
for(int x = 0; x < width; x ++ )
{
pixels[index++] = ((0xff << 24) | (c << 16) | (c << 8) | c);
}
}
i = createImage(new MemoryImageSource(width, height, pixels, 0, width));
setFont(new Font("TimesRoman", Font.BOLD | Font.ITALIC, 32));
}
public void paint(Graphics g)
{
g.drawImage(i, 0, 0, this);
g.drawString("JavaWorld", 30, 80);
}
}
import java.awt.image.*;public class jwmem extends java.applet.Applet
{
Image i;
int width = 200;
int height = 200;
public void init()
{
int[] pixels = new int[width * height];
int c;
double radianConversion = Math.PI / 180.0;
for(int index = 0, y = 0; y < height; y ++ )
{
c = ((0xff) & (byte)(Math.abs(Math.sin((y + height) * radianConversion)) * 255));
for(int x = 0; x < width; x ++ )
{
pixels[index++] = ((0xff << 24) | (c << 16) | (c << 8) | c);
}
}
i = createImage(new MemoryImageSource(width, height, pixels, 0, width));
setFont(new Font("TimesRoman", Font.BOLD | Font.ITALIC, 32));
}
public void paint(Graphics g)
{
g.drawImage(i, 0, 0, this);
g.drawString("JavaWorld", 30, 80);
}
}
解决方案 »
- Jtree大问题
- Swing 程序的模拟键盘事件 & keyRelease 事件不触发的问题?
- 如何测试无返回值的方法
- java 3d请教!
- 关于.properties文件的问题
- JDBC数据缓冲问题,GOOGLE里也没有找到解决方案,有高手没
- *.class经过javac编译后的文件能否直接运行
- 有关jtable的问题
- 有两个:1.class与2.java,2.java继承1.class类,要把2.java编译成2.class给如何书写!
- 请问我做的java的软件如何做成演示版,用什么软件?就是把我的操作录下来,给别人看
- 谁有jbuilder6的中文资料,[email protected],感激不尽!!
- 有没有对Class:Observer,熟悉的?
import java.awt.image.*;public class jwmem2 extends java.applet.Applet
{
Image i;
int width = 200;
int height = 200;
public void init()
{
byte[] pixels = new byte[width * height];
int arraySize = 3;
Color colorArray[] = new Color[arraySize];
colorArray[0] = Color.green;
for(int i = 1; i < arraySize; i ++ )
colorArray[i] = colorArray[i - 1].darker();
byte reds[] = new byte[arraySize];
byte greens[] = new byte[arraySize];
byte blues[] = new byte[arraySize];
for(int i = 0; i < arraySize; i ++ )
{
reds[i] = (byte)colorArray[i].getRed();
greens[i] = (byte)colorArray[i].getGreen();
blues[i] = (byte)colorArray[i].getBlue();
}
for(int index = 0, y = 0; y < height; y ++ )
for(int x = 0; x < width; x ++ )
pixels[index++] = (byte)(x % arraySize);
i = createImage(new MemoryImageSource(width, height, new IndexColorModel(8, arraySize, reds, greens, blues), pixels, 0, width));
setFont(new Font("TimesRoman", Font.BOLD | Font.ITALIC, 32));
}
public void paint(Graphics g)
{
g.drawImage(i, 0, 0, this);
g.drawString("JavaWorld", 30, 80);
}
}
Image pImg[]; 的用法。
abstract boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
Draws as much of the specified image as is currently available.
abstract boolean drawImage(Image img, int x, int y, ImageObserver observer)
Draws as much of the specified image as is currently available.
abstract boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.
abstract boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle.
abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.
abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface.
byte[] pixels = new byte[width * height]; //图片点阵数组Image pImg[]; 图片数组
如:
pImg[1] = image1;
pImg[2] = image2;
pImg[3] = image3;