package appfinal01;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
public class AppFinal01 extends JFrame {
public static void main(String[] args) {
new AppFinal01();
}
public AppFinal01(){
Container con=getContentPane();
con.setLayout(null);
setBounds(100,100,350,400);
setTitle("Thanawat XXX 01");
setVisible(true);
setDefaultCloseOperation (javax.swing.WindowConstants.EXIT_ON_CLOSE);
Random r=new Random();
int n=0;
btChar=new JButton[25];
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
btChar[n]=new JButton(""+(char)(65+r.nextInt(26)));
//btChar[n]=new JButton(""+(char)(65+n));
btChar[n].setBounds(30+i*55,50+j*55,55,55);
btChar[n].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
btCharActionPerformed(evt);
}
});
con.add(btChar[n++]);
}
}
txtChar=new JTextField();
txtChar.setBounds(30,20,275,25);
con.add(txtChar);
}
private void btCharActionPerformed(java.awt.event.ActionEvent evt){
http://txtChar.setText(evt.getActionCommand()); txtChar.setText(txtChar.getText()+evt.getActionCommand());
}
private JButton[] btChar;
private JTextField txtChar;
}