得到textfield的textdocument,控制里面的几个接口方法。
不过你的正整数是个位数吗?
不过你的正整数是个位数吗?
解决方案 »
- 排序
- 两天无法解决的问题!java文件重命名问题!为什么文件无法重命名?谢谢哈……
- java 类型转换错误。。。
- 如何修改局域网内的一台机器上的非共享文件,已知 用户名/密码
- 高人请留步:请教一个jdbc连mysql的奇怪问题,连接只能支持一天,第一天什么问题都没有,第二天早上报措:recv failed,急死了!分不够再
- 微软网站有问题,还是网络错误?
- 第一个类里的对象已经实例化了,在另外的一个类如何调用第一个类里面的方法(不要重新实例化第一个类的对象情况下).
- 如何用java -Xms 来增加缓存?
- 基础问题
- 如何判断一个程序已经启动过
- 希望各位前辈不要因为是菜问题就不 赐教!谢谢!
- 在java里面怎样得到当前路径?
{
public FrameTest()
{}
public static void main(String args[])
{
}
}
{
JButton button;
JTextField field; public Frame1()
{
super();
button = new JButton("Close");
button.addActionListener(this);
field = new JTextField(); this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(button);
this.getContentPane().add(field);
this.setSize(400, 300);
this.setVisible(true);
} public void actionPerformed(ActionEvent event)
{
if(event.getSource() == button)
{
if(field.getText() != null)
{
try
{
int num = Integer.parseInt(field.getText());
dispose();
new Frame2(num);
}catch(NumberFormatException nfe) { }
}
}
}
}
public class Frame2 extends JFrame
{
int num;
public Frame2(int num)
{
this.num = num; this.getContentPane().setLayout(new FlowLayout());
JLabel labels[] = new JLabel[num];
for(int i=0; i<labels.length; i++)
{
this.getContentPane().add(labels[i]);
}
this.setSize(400, 300);
this.setVisible(true);
}
}
mercury1231原代码写的有水平
public class Frame1 extends JFrame implements ActionListener
{
JButton button;
JTextField field; public Frame1()
{
super();
button = new JButton("Close");
button.addActionListener(this);
field = new JTextField(); this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(button);
this.getContentPane().add(field);
this.setSize(400, 300);
this.setVisible(true);
} public void actionPerformed(ActionEvent event)
{
if(event.getSource() == button)
{
if(field.getText() != null)
{
try
{
int num = Integer.parseInt(field.getText());
dispose();
new Frame2(num);
}catch(NumberFormatException nfe) { }
}
}
}
}
public class Frame2 extends JFrame
{
int num;
public Frame2(int num)
{
this.num = num; this.getContentPane().setLayout(new FlowLayout());
JLabel labels[] = new JLabel[num];
for(int i=0; i<labels.length; i++)
{
labels[i]=new JLabel("fd");//要加一句
this.getContentPane().add(labels[i]);
}
this.setSize(400, 300);
this.setVisible(true);
}
}