Unicode编译器

编写一个类似ASCII转换器一样的,java中的Unicode转换器,用awt组件写的

import java.awt.*;
import java.awt.Event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class QueryFrame extends Frame implements ActionListener
{
private TextField text_char,text_uni;
private Button button_char,button_uni;
public QueryFrame()
{
super("Unicode 字符查询器");
this.setBounds(300,240,280,90);
this.setBackground(Color.lightGray);
this.setLayout(new GridLayout(2,3,2,2));
this.add(new Label("字符",Label.RIGHT));
text_char=new TextField("汉子",10);
this.add(text_char);
button_char=new Button("查询Unicode码");
this.add(button_char);
button_char.addActionListener((ActionListener) this);
this.add(new Label("Unicode编码",Label.RIGHT));
text_uni=new TextField(10);
this.add(text_uni);
button_uni=new Button("查询字符");
this.add(button_uni);
button_uni.addActionListener(this);
this.addWindowListener((WindowListener) new WinClose());
this.setVisible(true);
}
public void actionPerformed(ActionEvent ev)
{
if(ev.getSource()==button_char)
{
String str=text_char.getText();
if(str.equals(""))
return;
char ch=str.charAt(0);
text_char.setText(""+ch);
text_uni.setText(""+(int)ch);
}
else if(ev.getSource()==button_uni)
{
String str=text_uni.getText();
if(str.equals(""))
return;
int uni=Integer.parseInt(str);
text_char.setText(""+(char)uni);
}
}
public static void main(String arg[])
{
new QueryFrame();
}
}
class WinClose implements WindowListener
{
public void windowClosing(WindowEvent ev)
{
System.exit(0);
}
public void windowOpened(WindowEvent ev){}
public void windowActivated(WindowEvent ev){}
public void windowDeactivated(WindowEvent ev){}
public void windowClosed(WindowEvent ev){}
public void windowIconified(WindowEvent ev){}
public void windowDeiconified(WindowEvent ev){}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值