import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
class frame2 extends JFrame
{
public frame2(int n)
{
this.setSize(400,400);
this.setLayout(new GridLayout(0, 2));
while(n-- > 0)
this.add(new JTextField());
this.setVisible(true);
}
}
public class test3 extends JPanel
{
private JTextField jtText;
private JButton jbOK;
public test3()
{
jtText = new JTextField();
jbOK = new JButton("OK");
this.add(jbOK);
this.add(jtText);
this.setLayout(new GridLayout(1, 2));
jbOK.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
frame2 test = new frame2(Integer.parseInt(jtText.getText()));
}
});
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.add(new test3());
frame.setSize(100, 50);
frame.setVisible(true);
}
}
温馨提示:内容为网友见解,仅供参考