java按下按钮后,文本区域没显示,为什么?求解释啊! 为什么没响应啊?
这是个排序的测试类,其余的就不复上来了publicclassJTestextendsJFrameimplementsActionListener{publicstatic...
这是个排序的测试类,其余的就不复上来了
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 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);
}
} 展开
2个回答
展开全部
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中有没有错误不知道,所以如果还有错,希望贴出一个排序让我们看看。
还有主程序有问题。我帮你改了一下。完整的程序如下:
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中有没有错误不知道,所以如果还有错,希望贴出一个排序让我们看看。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询