str2txt

package com.text2str;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;


public class Start extends JFrame {
private static final long serialVersionUID = 1L;
private JButton ba = null;
private JButton bb = null;
private JLabel code = new JLabel("Text: ");
private JLabel input = new JLabel("String: ");
private JLabel rel = new JLabel();
private JTextArea formatField = null;
private JTextArea codeField = null;
//private

public Start(){
init();
}


public void init(){
 JPanel p = new JPanel();
  formatField = new JTextArea();
  codeField = new JTextArea();
   JScrollPane jp1= new JScrollPane(codeField);
  jp1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  JScrollPane jp2= new JScrollPane(formatField);
  jp2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  this.add(jp1);
  this.add(jp2);
 this.setBounds(1, 1, 550, 600);
 this.setResizable(false);
 this.setLayout(null);
 this.setTitle("tItLE=sTRiNg2TExT(v1.0) *** [email protected]");
 //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 codeField.setLineWrap(true);
 formatField.setLineWrap(true);
 codeField.setWrapStyleWord(true);      
 formatField.setWrapStyleWord(true);
 ba = new JButton("str2text");
 bb = new JButton("text2str");

 ba.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e) {
   String str;
   str=formatField.getText();
   str=s2t(str);
   codeField.setText(str); 
   
  }
 });

 bb.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e) {
   String str1;
   str1=codeField.getText();
   str1=t2s(str1);
   formatField.setText(str1);
  }
 });
 
 jp2.setBounds(30, 30, 480, 200);
 jp1.setBounds(30, 285, 480, 200);
 code.setBounds(30, 260, 180, 25);
 ba.setBounds(30, 500, 180, 25);
 bb.setBounds(300, 500, 180, 25);
 rel.setBounds(30, 155, 100, 25);
 input.setForeground(Color.RED);
 code.setForeground(Color.RED);
 rel.setForeground(Color.RED);
 input.setBounds(30, 5, 100, 25);
 
 

 this.add(rel);
 this.add(input);
 this.add(code);
 this.add(ba);
 this.add(bb);
 
 
 jp1.getViewport().add(codeField,   null);      
 jp2.getViewport().add(formatField, null);
 ba.setDefaultCapable(true);
 this.setVisible(true);
 }

 public String s2t(String str){
  str=str.replace("////", "//");
  str=str.replace("///"","/"");
  str=str.replace("///'", "/'");
  str=str.replace("//r", "/r");
  str=str.replace("//n", "/n");
  str=str.replace("//t", "/t");
  str=str.replace("//b", "/b");
  str=str.replace("//0", "/0");
  return str;
 }
 
 public String t2s(String str1){
  str1=str1.replace("//", "////");
  str1=str1.replace("/"","///"");
  str1=str1.replace("/'", "///'");
  str1=str1.replace("/r", "//r");
  str1=str1.replace("/n", "//n");
  str1=str1.replace("/t", "//t");
  str1=str1.replace("/b", "//b");
  str1=str1.replace("/0", "//0");
  return str1;
 }
 public static void main(String[] args) {
  new Start();
 }
}

你可能感兴趣的:(str2txt)