animatebox.java
来自「here is a project that really dsecribes 」· Java 代码 · 共 64 行
JAVA
64 行
package box;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
public class AnimateBox extends JFrame {
public static final int MAX_WIDTH = 550;
public static final int MAX_HEIGHT = 500;
// define an array of image names
private String [] names = new String [] { "flower.jpg", "star.jpg",
"drum.jpg", "globe.jpg" };
// an array of icons
private Icon [] icons = new ImageIcon [names.length];
// Box array equal in length to names array
private Box [] boxes = new Box[names.length];
// constructor
public AnimateBox(String str) {
super(str);
setBounds(10, 10, MAX_WIDTH, MAX_HEIGHT);
Container container = getContentPane();
// set null layout to control placement of components manually
container.setLayout(null);
for(int i = 0; i<boxes.length;i++) {
// create an image icon
icons[i] = new ImageIcon(names[i]);
// this encapsulates the starting location and
// dimensions of a box
Rectangle r = new Rectangle(i*100+100, // x
30, // y
40, // w
40 // h
);
boxes[i] = new Box(r, // set bounds
icons[i] // set icon
);
container.add(boxes[i]); // add the box to frame
}
setDefaultCloseOperation(EXIT_ON_CLOSE);
// display frame
setVisible(true);
}
public static void main(String args[]) {
AnimateBox a = new AnimateBox("Animated Boxes");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?