import java.awt.*;
import java.awt.event.ActionEvent;
import java.lang.reflect.Array;
import javax.swing.*;
import java.util.*;
public class 排序 {
public static void main(String args[]) {
//初始化控件们
JFrame jf = new JFrame("小排序");
jf.setLayout(new FlowLayout(FlowLayout.LEFT));
jf.setBounds(400,300,300,300);
JLabel l1 = new JLabel("输入数据");
JLabel l2 = new JLabel("排序结果");
JTextField t1 = new JTextField("", 30);
JTextField t2 = new JTextField("", 30);
JButton b1=new JButton("排序");
//加入框架
jf.add(b1);
jf.add(l1);
jf.add(t1);
jf.add(l2);
jf.add(t2);
//可视化
jf.setVisible(true);
//给button添加事件监听器
b1.addActionListener(new AbstractAction(){
@Override public void actionPerformed(ActionEvent e) {
String s=t1.getText();
char []a=s.toCharArray();
Arrays.sort(a);
t2.setText(Arrays.toString(a));
}
}
);
}
}
JAVA-图形化编程——排序
于 2023-10-30 22:30:01 首次发布