第1个回答 推荐于2016-11-06
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ZuoYe10_2{
public static void main(String args[]){
MathWindow win=new MathWindow();
}
}
class MathWindow extends JFrame implements ActionListener{
JTextField inputText,showUnicode;
JButton button;
MathWindow(){
inputText=new JTextField(10);
showUnicode=new JTextField(10);
button=new JButton("enter");
button.addActionListener(this);
inputText.addActionListener(this);
setLayout(new FlowLayout());
add(inputText);
add(button);
add(showUnicode);
setBounds(100,100,260,190);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
String s=inputText.getText();
StringBuffer str=new StringBuffer();
for(int i=0;i<s.length();i++){
char c=s.charAt(i);
str.append((int)c);
str.append(",");
}
showUnicode.setText(new String(str));
}
}本回答被提问者采纳