import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class A extends JFrame {
public static void main(String[]args){
new A();
}
new A();
}
public A()
{
String s;
JFrame F=new JFrame("A");
F.setDefaultLookAndFeelDecorated(true);
F.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel P = new JPanel();
P.setLayout(new GridLayout(4,4));
JButton button[]=new JButton[16];
{
String s;
JFrame F=new JFrame("A");
F.setDefaultLookAndFeelDecorated(true);
F.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel P = new JPanel();
P.setLayout(new GridLayout(4,4));
JButton button[]=new JButton[16];
for (int i = 0; i < 16; i++){
button[i] = new JButton();
button[i] = new JButton();
button[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int j = 0; j < 16; j++){ 需要知道這是什麼.......
if (e.getSource()==button[j]){
System.out.println(j+1);
}
}
}
});
button[i].setSize(50,50);
button[i].setText(Integer.toString(i+1));
public void actionPerformed(ActionEvent e) {
for (int j = 0; j < 16; j++){ 需要知道這是什麼.......
if (e.getSource()==button[j]){
System.out.println(j+1);
}
}
}
});
button[i].setSize(50,50);
button[i].setText(Integer.toString(i+1));
P.add(button[i]);
}
F.getContentPane().add(P,BorderLayout.CENTER);
F.setVisible(true);
}
}
F.getContentPane().add(P,BorderLayout.CENTER);
F.setVisible(true);
}
}
沒有留言:
張貼留言