Java编写一个有两个文本框和一个按钮的应用程序在一个文本框输入一个字符串按回车或单击按钮,

另一个文本框都显示字符串中每个字符在Unicode表中的顺序位置。
要用到awt和swing,高手帮忙下,谢谢!~!~

这段应该符合你的要求

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

import sun.io.ByteToCharConverter;
import sun.io.CharToByteConverter;

public class Test extends JFrame implements ActionListener {
JButton btn = new JButton("ok");
JTextField tf1 = new JTextField(20);
JTextField tf2 = new JTextField(20);

public Test() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pn = new JPanel();
pn.add(tf1);
tf1.addActionListener(this);
pn.add(tf2);
this.getContentPane().add(pn, BorderLayout.CENTER);
this.getContentPane().add(btn, BorderLayout.SOUTH);
btn.addActionListener(this);
this.pack();
this.setVisible(true);
}

public void actionPerformed(ActionEvent e) {
String str=tf1.getText();
tf2.setText("");
try {
ByteToCharConverter converter = ByteToCharConverter
.getConverter("GB2312");
CharToByteConverter converter1 = CharToByteConverter
.getConverter("GB2312");
byte[] b =str.getBytes();
char[] c = new char[4];
c = converter.convertAll(b);
for (int i = 0; i < c.length; i++) {
tf2.setText(tf2.getText()+"\\u" + Integer.toHexString(c[i]));
}
} catch (Exception ex) {
ex.printStackTrace();
}

}

public static void main(String[] args) {
new Test();
}
}
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网