问题在于JTextArea ta1=new JTextArea(50,100);定义的宽度过大,而flowlayout布局选用的是居中布局,不是你按了三下才有反映,我想你测试用的数据应该不够大:)JTextArea ta1=new JTextArea(20,20);试试看而且我想你需要加一句ta1.setLineWrap(true);
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Color;
//import java.applet.*;
public class javaa extends JApplet
{
JTextField t1=new JTextField(10);
JTextField t2=new JTextField(10);
Label l1=new Label("the smaller number");
Label l2=new Label("the bigger number");
JButton b1=new JButton("go");
JTextArea ta1=new JTextArea(20,20);
ActionListener a=new ActionListener(){
public void actionPerformed(ActionEvent e)
{
String s1=new String(t1.getText());
String s2=new String(t2.getText());
int i1=Integer.parseInt(s1);
int i2=Integer.parseInt(s2);
for(int i=i1;i<i2;i++)
{
String s=new String();
ta1.append(s.valueOf(i));
}
}
};
public void init()
{
ta1.setBackground( Color.red );
ta1.setLineWrap(true); b1.addActionListener(a);
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
cp.add(l1);
cp.add(t1);
cp.add(l2);
cp.add(t2);
cp.add(b1);
cp.add(ta1);
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Color;
//import java.applet.*;
public class javaa extends JApplet
{
JTextField t1=new JTextField(10);
JTextField t2=new JTextField(10);
Label l1=new Label("the smaller number");
Label l2=new Label("the bigger number");
JButton b1=new JButton("go");
JTextArea ta1=new JTextArea(20,20);
ActionListener a=new ActionListener(){
public void actionPerformed(ActionEvent e)
{
String s1=new String(t1.getText());
String s2=new String(t2.getText());
int i1=Integer.parseInt(s1);
int i2=Integer.parseInt(s2);
for(int i=i1;i<i2;i++)
{
String s=new String();
ta1.append(s.valueOf(i));
}
}
};
public void init()
{
ta1.setBackground( Color.red );
ta1.setLineWrap(true); b1.addActionListener(a);
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
cp.add(l1);
cp.add(t1);
cp.add(l2);
cp.add(t2);
cp.add(b1);
cp.add(ta1);
}
解决方案 »
- 求大神帮我看看这个DEMO的createCircle方法,怎么返回圆的点阵的
- MyEclipse能运行新建ASP文件吗?
- 汉字问题
- 绘制图形时 (paint 方法) 如何出现滚动条
- 我的程序怎么回事,为什么不能编译通过?错在哪里?各位大侠帮帮忙啊!
- 在线等:求指数运算的方法
- 我这句有错吗,自己机上能通过,虚拟主机商出现错误,有关存文件不成功,他们的系统是linux,我测试的是windows,是否是目录另有写法?
- 大问题!新问题!(非高手莫留言)
- 关于使用jbuilder中的一个警告信息的问题。
- 每次运行时,将针对该用户的数据放在临时表如-temTableA中,用完之后删除数据,安全上有问题吗?
- 我是菜鸟,我求助!
- 请教java中有没有象vc中的熟悉页那样的东东?
也可以将大数字和小数字的间隔放大一点,这样一来第一次点就可以看到你要打印的数字:)