问题在于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);
}