import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
public class SortIt extends JFrame {
public static void main(String args[]) {
// Create frame to display sortings
JFrame frame = new JFrame( "Sorting ");
setSize(400,300);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} );
JTextField TextField1 = new JTextField();
private JButton Button = new JButton( "排序 ");
JTextField TextField2 = new JTextField();
String st =TextField1.getText();
// Create initial list to sort
StringTokenizer st = new StringTokenizer( "123 234 345 ", " "); // 以空格来分隔数字
int[] array = new int[20]; // 这里最好是先经过st中的数字个数来计算,简单起见直接给个20
int index = 0;
while (st.hasMoreElements()) {
array[index++] = Integer.parseInt(st.nextToken());
}
Button.addActionListener(
new ActionListener()
{ public void actionPerformed(ActionEvent event)
{
Arrays.sort(array);
TextField2.setText()= Arrays.asList(array) ;}
});
frame.pack();
frame.show();
}
}
但是不对,请前辈们帮我改正确,十分感谢!
------解决方案--------------------
。。。。。 全是错。
------解决方案--------------------
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
public class SortIt extends JFrame
{
private JButton button;
private JTextField textField1,textField2;
public SortIt()
{
this.setSize(400,300);
this.setLayout(new BorderLayout());
textField1 = new JTextField();
textField2 = new JTextField();
button = new JButton( "排序 ");
this.add(textField1,BorderLayout.NORTH);
this.add(button,BorderLayout.CENTER);
this.add(textField2,BorderLayout.SOUTH);
button.addActionListener(
new ActionListener()
{