日期:2014-05-20 浏览次数:20951 次
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class ButtonFrame {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Frames frame = new Frames();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class Frames extends JFrame {
JTextField t;
Random random;
public Frames() {
random = new Random();
//JTextField
t = new JTextField();
t.setBounds(200, 200, 10, 1);
t.setBackground(Color.BLACK);
/*JButton
JButton b1 = new JButton("Left");
JButton b2 = new JButton("Center");
JButton b3 = new JButton("Right");
JButton b4 = new JButton("Left");
JButton b5 = new JButton("Center");
JButton b6 = new JButton("Right");
b1.addActionListener(new Actt());
//JPanel
JPanel p = new JPanel();
p.setLocation(240, 240);
p.setVisible(true);
p.setLayout(new GridLayout(3,2));
p.setBackground(Color.YELLOW);
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(b5);
p.add(b6);*/
//this
setLayout(null);
//getContentPane().add(p);
getContentPane().add(t);
setSize(300,300);
setTitle("T-T");
//setBackground(Color.BLACK);
}
class Actt implements ActionListener {
public void actionPerformed(ActionEvent event) {
t.setColumns(random.nextInt(10)* 2);
Frames.this.validate();
}
}
}
t.setBounds(200, 200, 10, 1);