📄 test.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -