java按下按钮后,文本区域没显示,为什么?求解释啊! 为什么没响应啊?

这是个排序的测试类,其余的就不复上来了

public class JTest extends JFrame implements ActionListener
{
public static int i;
public static int fan;
public String args[];
public JRadioButton[] r={new JRadioButton("冒泡排序"),new JRadioButton("快速排序"),new JRadioButton("插入排序")};
public JTextArea t=new JTextArea("",8,25);
public JButton b=new JButton("开始排序");
public JTest()
{

super("排序窗口");
Container c=getContentPane();
c.setLayout(new FlowLayout());

ButtonGroup rg=new ButtonGroup();
for(i=0;i<r.length;i++)
{
c.add(r[i]);
rg.add(r[i]);
r[i].addActionListener(this);
}

c.add(b);
b.addActionListener(this);

JScrollPane st=new JScrollPane(t);
c.add(st);

}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b)
{

if(r[0].isSelected())
{
Bubblesort B=new Bubblesort(args);
t.setText(B.Sort());
}
else
{
if(r[1].isSelected())
{
Quicksort Q=new Quicksort(args);
t.setText(Q.Sort());
}
else
{
if(r[2].isSelected())
{
Insertsort I=new Insertsort(args);
t.setText(I.Sort());
}
}
}
}
}

public static void main(String args[])throws IOException
{
try (BufferedReader fin = new BufferedReader(new FileReader("testdata.txt")))
{
int m=Integer.parseInt(fin.readLine());
args=new String[m];
for(i=0;i<m;i++)
{
args[i]=fin.readLine();
}
}
JTest T=new JTest();
T.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
T.setSize(400,250);
T.setVisible(true);
}
}

public String args[];与public static void main(String args[])中的变量重名了,必须换一个变量名。
还有主程序有问题。我帮你改了一下。完整的程序如下:
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class JTest extends JFrame implements ActionListener
{
public static int i;
public static int fan;
public static String args1[];
public JRadioButton[] r={new JRadioButton("冒泡排序"),new JRadioButton("快速排序"),new JRadioButton("插入排序")};
public JTextArea t=new JTextArea("",8,25);
public JButton b=new JButton("开始排序");
public JTest()
{
super("排序窗口");
Container c=getContentPane();
c.setLayout(new FlowLayout());

ButtonGroup rg=new ButtonGroup();
for(i=0;i<r.length;i++)
{
c.add(r[i]);
rg.add(r[i]);
r[i].addActionListener(this);
}
r[0].setSelected(true);
c.add(b);
b.addActionListener(this);
JScrollPane st=new JScrollPane(t);
c.add(st);
  }
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b)
{
  if(r[0].isSelected())
{
Bubblesort B=new Bubblesort(args);
t.setText(B.Sort());
}
else
{
if(r[1].isSelected())
{
Quicksort Q=new Quicksort(args);
t.setText(Q.Sort());
}
else
{
if(r[2].isSelected())
{
Insertsort I=new Insertsort(args);
t.setText(I.Sort());
}
}
}
}
}
public static void main(String args[])throws IOException
{
try
{
BufferedReader fin = new BufferedReader(new FileReader("testdata.txt"));
int m=Integer.parseInt(fin.readLine());
args1=new String[m];
for(i=0;i<m;i++)
{
args1[i]=fin.readLine();
}
}catch(IOException e){
e.printStackTrace();
}
JTest T=new JTest();
T.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
T.setSize(400,250);
T.setVisible(true);
}
}
Bubblesort,Quicksort,Insertsort中有没有错误不知道,所以如果还有错,希望贴出一个排序让我们看看。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-05-05
你的侦听事件没有问题.
但是,你点排序按钮时,有选择那个排序算法吗?
你的单选按钮默认的是不选中的.追问

有啊!

追答

你给出的代码有很多错,我注掉那些,点你的按钮,让文本域中显示点内容,是可以的.
要不你就留下QQ,远程帮你看一下.,
这样是猜不出你的问题在那了.