*/ 出自: 编程中国 http://www.bc-cn.net
*/ 作者: 野蛮女人
*/ 时间: 2007-8-31 编程论坛首发
*/ 声明: 尊重作者劳动,转载请保留本段文字
*/ --------------------------------------------------------------------------------------
这个原创没问题了吧
package swing;import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.UIManager;public class Temp extends JFrame {
private ButtonGroup buttonGroup = new ButtonGroup();
private static Temp frame;
public static void main(String args[]) {
frame = new Temp();
frame.setTitle(\"大小写转换工具\");
frame.setVisible(true);
}public Temp() {
getContentPane().setLayout(null);
setBounds(100, 100, 500, 375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final JPanel panel = new JPanel();
panel.setBackground(SystemColor.activeCaptionBorder);
panel.setLayout(null);
panel.setBounds(64, 59, 371, 272);
getContentPane().add(panel);final JLabel label = new JLabel();
label.setBounds(22, 48, 71, 15);
label.setText(\"来源路径:\");
panel.add(label);final JLabel label_1 = new JLabel();
label_1.setText(\"目标路径:\");
label_1.setBounds(22, 98, 71, 15);
panel.add(label_1);final JTextField textField = new JTextField();
textField.setBounds(99, 45, 161, 21);
panel.add(textField);final JTextField textField_1 = new JTextField();
textField_1.setBounds(99, 95, 161, 21);
panel.add(textField_1);final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(button);
if(returnVal == chooser.APPROVE_OPTION){
File file = chooser.getSelectedFile();
textField.setText(file.getAbsolutePath());
}
}
});
button.setText(\"选择\");
button.setBounds(266, 44, 99, 23);
panel.add(button);final JButton button_1 = new JButton();
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showSaveDialog(button);
if(returnVal == chooser.APPROVE_OPTION){
File file = chooser.getSelectedFile();
textField_1.setText(file.getAbsolutePath());
}
}
});
button_1.setText(\"选择\");
button_1.setBounds(266, 94, 99, 23);
panel.add(button_1);final JRadioButton radioButton = new JRadioButton();
radioButton.setSelected(true);
radioButton.setBackground(SystemColor.activeCaptionBorder);
buttonGroup.add(radioButton);
radioButton.setText(\"小写转大写\");
radioButton.setBounds(48, 143, 121, 23);
panel.add(radioButton);final JRadioButton radioButton_1 = new JRadioButton();
radioButton_1.setBackground(SystemColor.activeCaptionBorder);
buttonGroup.add(radioButton_1);
radioButton_1.setText(\"大写转小写\");
radioButton_1.setBounds(225, 143, 121, 23);
panel.add(radioButton_1);final JButton button_2 = new JButton();
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String path1 = textField.getText();
String path2 = textField_1.getText();
try {
if(radioButton.isSelected()){
TransitionToUpper(path1, path2);
ShowDialog(\"转换成功!\",\"成功\");
}else if(radioButton_1.isSelected()){
TransitionToLower(path1, path2);
ShowDialog(\"转换成功!\",\"成功\");
}
} catch (IOException e1) {
ShowDialog(\"转换失败!\",\"失败\");
}
}
private void ShowDialog(String str1,String str2) {final JDialog dialog = new JDialog(frame, str2);
dialog.setSize(180, 80);
JLabel label = new JLabel(str1);
dialog.setLayout(new FlowLayout());
dialog.add(label);
dialog.setLocation(420, 250);
dialog.setVisible(true);}
});
button_2.setText(\"转换开始\");
button_2.setBounds(132, 211, 99, 23);
panel.add(button_2);final JLabel label_2 = new JLabel();
label_2.setFont(new Font(\"\", Font.BOLD, 26));
label_2.setText(\"大小写转换\");
label_2.setBounds(174, 23, 144, 30);
getContentPane().add(label_2);
getContentPane().setBackground(SystemColor.activeCaptionBorder);}
public void TransitionToUpper(String path1, String path2) throws IOException {
String tmp = null;
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path1)));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path2)));
while ((tmp = br.readLine()) != null) {
String tmp1 = tmp.toUpperCase();
bw.write(tmp1 + \"\n\");
bw.flush();
}
br.close();
bw.close();
}
public void TransitionToLower(String path1, String path2) throws IOException {
String tmp = null;
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path1)));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path2)));
while ((tmp = br.readLine()) != null) {
String tmp1 = tmp.toLowerCase();
bw.write(tmp1 + \"\n\");
bw.flush();
}
br.close();
bw.close();
}
}