アレイ反転アルゴリズム
3125 ワード
/* ( )
*
* Copyright (c) 2011,
* All rights reserved.
* :
* :
* : 2013 8 16
* : 001
*
* :
* : eclipse windowBuilder .
* :
*
*/
package ;
import java.awt.BorderLayout;
public class extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
private JTextArea textArea ;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frame = new ();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public () {
setTitle("\u7528\u6570\u7EC4\u53CD\u8F6C\u5B57\u7B26\u4E32");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("\u8F93\u5165\u4E00\u4E2A\u5B57\u7B26\u4E32");
lblNewLabel.setBounds(10, 33, 95, 15);
contentPane.add(lblNewLabel);
textField = new JTextField();
textField.setBounds(139, 30, 285, 21);
contentPane.add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(139, 64, 285, 21);
contentPane.add(textField_1);
JButton button = new JButton("\u53CD\u8F6C");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String inputstr = textField.getText(); //
char[] str = inputstr.toCharArray(); //
textArea.setText(""); //
for(int i = 0;i<str.length/2;i++){ //
char temp = str[i];
str[i] = str[str.length-i-1];
str[str.length-i-1] = temp;
textArea.append(" "+(i+1)+" :\t"); //
for(char c : str){ //
textArea.append(c+"");
}
textArea.append("
"); //
}
String outputstr = new String(str); //
textField_1.setText(outputstr); //
}
});
button.setBounds(10, 63, 93, 23);
contentPane.add(button);
textArea = new JTextArea();
textArea.setBounds(10, 96, 414, 156);
contentPane.add(textArea);
}
}