?? codeconvert.java
字號:
package jbbtlh.jbb.tlh;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.UnsupportedEncodingException;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
@SuppressWarnings("serial")
public class CodeConvert extends JFrame {
private JLabel jltitle = new JLabel("編碼轉換器");
private JLabel jlgb2312 = new JLabel("GB2312:");
private JTextArea jtagb2312 = new JTextArea();
private JScrollPane jspgb2312 = new JScrollPane(jtagb2312);
private JLabel jlunicode = new JLabel("Unicode:");
private JTextArea jtaunicode = new JTextArea();
private JScrollPane jspunicode = new JScrollPane(jtaunicode);
private JLabel jlbottom = new JLabel("第二個文本區的內容自動復制到粘貼板,方便使用");
private CodeConvert() {
this.setBounds(200, 100, 600, 500);
this.setTitle("編碼轉換器");
this.setLayout(null);
launchFrame();
this.setResizable(false);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void launchFrame() {
jtagb2312.setLineWrap(true);
jtaunicode.setLineWrap(true);
jtaunicode.setEditable(false);
jtagb2312.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
try {
String s1 = jtagb2312.getText().trim();
String s2 = toUnicode(s1);
jtaunicode.setText(s2);
setClipboardText(s2);
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
}
public void keyTyped(KeyEvent e) {
}
});
jltitle.setBounds(250, 30, 100, 20);
this.add(jltitle);
jlgb2312.setBounds(50, 50, 60, 20);
this.add(jlgb2312);
jspgb2312.setBounds(50, 70, 500, 150);
this.add(jspgb2312);
jlunicode.setBounds(50, 230, 60, 20);
this.add(jlunicode);
jspunicode.setBounds(50, 250, 500, 150);
this.add(jspunicode);
jlbottom.setBounds(160, 420, 300, 20);
this.add(jlbottom);
}
public String toUnicode(String strText) throws UnsupportedEncodingException {
char c;
String strRet = "";
int intAsc;
String strHex;
for (int i = 0; i < strText.length(); i++) {
c = strText.charAt(i);
intAsc = (int) c;
if (intAsc > 128) {
strHex = Integer.toHexString(intAsc);
strRet += "\\u" + strHex;
}
else {
strRet = strRet + c;
}
}
return strRet;
}
private void setClipboardText(String writeMe) {
Clipboard sysc = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable tText = new StringSelection(writeMe);
sysc.setContents(tText, null);
}
public static void main(String args[]) {
new CodeConvert();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -