问题描述
importjava.awt.*;importjava.awt.event.*;publicclassPaiXuextendsFrameimplementsActionListener{Buttonb;TextFieldtf1,tf2;Labell1,l2;publicPaiXu(){b=newButton("Enter");tf1=newTextField();tf2=newTextField();l1=newLabel("请输入要排序的字母:");l2=newLabel("排序后的字母:");setLayout(newFlowLayout());add(l1);add(tf1);add(l2);add(tf2);add(b);//b.addActionListener(this);tf1.addActionListener(this);tf2.addActionListener(this);setVisible(true);setSize(500,500);setBackground(Color.LIGHT_GRAY);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});}publicvoidactionPerformed(ActionEvente){Strings=tf1.getText();char[]c=s.toCharArray();for(inti=0;i<s.length();i++){for(intj=i+1;j<s.length();j++){if(c[i]>c[j]){chartemp=c[j];c[j]=c[i];c[i]=temp;}}}System.out.println(c);//tf2.setText(c);//tf2.setText(c);}publicstaticvoidmain(String[]args){PaiXuv=newPaiXu();v.setTitle("排序");}}
解决方案
解决方案二:
先谢过高手啊,我这没点了啊,只能感谢你们啊!