test.java
来自「《Java2图形设计卷II:Swing》配套光盘源码」· Java 代码 · 共 40 行
JAVA
40 行
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JApplet {
Container cp = getContentPane();
private final Component[] comps = {
new JButton(), new JButton(),
new JButton(), new JButton(),
new JButton(), new JButton(),
};
public void init() {
cp.setLayout(null);
for(int i=0; i < comps.length; ++i) {
AbstractButton button = (AbstractButton)comps[i];
cp.add(button);
String t = "Button #";
t += i + " Index: " + getIndexOf(button);
button.setText(t);
button.setBounds(i*50, i*50, 350, 75);
System.out.println("Adding: " + button.getText());
}
}
private int getIndexOf(Component button) {
int ncomponents = cp.getComponentCount();
for(int i=0; i < ncomponents; ++i) {
Component c = cp.getComponent(i);
if(button == c)
return i;
}
return -1;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?