JAVA程序源码 - Unicode - 编码转换器

转换器截图!QQ:11745405

/*

 * UnicodeConversionTool.java

 *

 * Created on __DATE__, __TIME__

 */



package unicodeConversionTool;



import java.awt.Dimension;

import java.awt.Toolkit;



import javax.swing.UIManager;

import javax.swing.UnsupportedLookAndFeelException;



import com.jtattoo.plaf.bernstein.BernsteinLookAndFeel;

import com.jtattoo.plaf.mint.MintLookAndFeel;



/**

 *

 * @author  __USER__

 */

public class UnicodeConversionTool extends javax.swing.JFrame {



/** Creates new form UnicodeConversionTool */

public UnicodeConversionTool() {

initComponents();

this.setResizable(false);

Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

this.setLocation(d.width / 2 - this.getWidth() / 2,

d.height / 2 - this.getHeight() / 2 - 20);

}



/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

//GEN-BEGIN:initComponents

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {



jScrollPane1 = new javax.swing.JScrollPane();

jTextArea1 = new javax.swing.JTextArea();

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

jScrollPane2 = new javax.swing.JScrollPane();

jTextArea2 = new javax.swing.JTextArea();

jButton3 = new javax.swing.JButton();

jButton4 = new javax.swing.JButton();



setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle("Unicode\u7f16\u7801\u8f6c\u6362\u5668\u4f5c\u8005\uff1a\u5c0f\u9633");



jTextArea1.setColumns(20);

jTextArea1.setForeground(new java.awt.Color(204, 0, 0));

jTextArea1.setLineWrap(true);

jTextArea1.setRows(5);

jScrollPane1.setViewportView(jTextArea1);



jLabel1.setFont(new java.awt.Font("微软雅黑", 1, 14));

jLabel1.setForeground(new java.awt.Color(255, 0, 0));

jLabel1.setText("\u6e90\u5b57\u7b26");



jLabel2.setFont(new java.awt.Font("微软雅黑", 1, 14));

jLabel2.setForeground(new java.awt.Color(255, 0, 0));

jLabel2.setText("\u8f6c\u6362\u540e\u5b57\u7b26");



jTextArea2.setColumns(20);

jTextArea2.setForeground(new java.awt.Color(204, 0, 0));

jTextArea2.setLineWrap(true);

jTextArea2.setRows(5);

jTextArea2.setCaretColor(new java.awt.Color(204, 0, 0));

jScrollPane2.setViewportView(jTextArea2);



jButton3.setText("\u6e05\u9664");

jButton3.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton3ActionPerformed(evt);

}

});



jButton4.setText("\u8f6c\u6362");

jButton4.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton4ActionPerformed(evt);

}

});



javax.swing.GroupLayout layout = new javax.swing.GroupLayout(

getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(layout

.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(

layout.createSequentialGroup()

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.TRAILING)

.addGroup(

layout.createSequentialGroup()

.addContainerGap()

.addComponent(

jScrollPane2,

javax.swing.GroupLayout.PREFERRED_SIZE,

262,

javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(

layout.createSequentialGroup()

.addGap(113,

113,

113)

.addComponent(

jLabel1))

.addGroup(

layout.createSequentialGroup()

.addContainerGap()

.addComponent(

jScrollPane1,

javax.swing.GroupLayout.DEFAULT_SIZE,

262,

Short.MAX_VALUE))

.addGroup(

layout.createSequentialGroup()

.addGap(102,

102,

102)

.addComponent(

jLabel2))))

.addContainerGap())

.addGroup(

javax.swing.GroupLayout.Alignment.TRAILING,

layout.createSequentialGroup()

.addGap(53, 53, 53)

.addComponent(jButton4,

javax.swing.GroupLayout.DEFAULT_SIZE,

82, Short.MAX_VALUE)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jButton3,

javax.swing.GroupLayout.PREFERRED_SIZE,

84,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(60, 60, 60)));

layout.setVerticalGroup(layout

.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(

layout.createSequentialGroup()

.addComponent(jLabel1)

.addGap(5, 5, 5)

.addComponent(jScrollPane1,

javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jLabel2)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jScrollPane2,

javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(

javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(

layout.createParallelGroup(

javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(

jButton4,

javax.swing.GroupLayout.PREFERRED_SIZE,

29,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(

jButton3,

javax.swing.GroupLayout.PREFERRED_SIZE,

29,

javax.swing.GroupLayout.PREFERRED_SIZE))

.addContainerGap(

javax.swing.GroupLayout.DEFAULT_SIZE,

Short.MAX_VALUE)));



pack();

}// </editor-fold>

//GEN-END:initComponents



private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

String str = "";

String source = jTextArea1.getText();

for(int i = 0; i < source.length(); i++){

char c = source.charAt(i);

if(c < 256){

str += "\\u00" + Integer.toHexString(c);

}else if(c < 4096){

str += "\\u0" + Integer.toHexString(c);

}else{

str += "\\u" + Integer.toHexString(c);

}

}

jTextArea2.setText(str);

jTextArea2.setEditable(false);

jTextArea2.selectAll();//选中所有文本

jTextArea2.copy();

}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

jTextArea1.setText("");

jTextArea2.setText("");

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

try {

UIManager.setLookAndFeel(new BernsteinLookAndFeel());

//UIManager.setLookAndFeel(new MintLookAndFeel());

} catch (UnsupportedLookAndFeelException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}//黄色

new UnicodeConversionTool().setVisible(true);

}

});

}

//GEN-BEGIN:variables

// Variables declaration - do not modify

private javax.swing.JButton jButton3;

private javax.swing.JButton jButton4;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JScrollPane jScrollPane2;

private javax.swing.JTextArea jTextArea1;

private javax.swing.JTextArea jTextArea2;

// End of variables declaration//GEN-END:variables

}

你可能感兴趣的:(JAVA程序源码 - Unicode - 编码转换器)