返回顶部

收藏

进制转换

更多

textField_1.setText(Integer.toHexString(i)); //十进制转换二进制

textField_2.setText(Integer.toOctalString(i)); //十进制转换八进制

textField_3.setText(Integer.toBinaryString(i)); //十进制转换十六进

import javax.swing.JDialog;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.Color;
import java.awt.Toolkit;

public class jzzh  {
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;

    public static int i;
    public static String str;
    private JTextField textField_3;

    public jzzh()
    {
        JDialog jd=new JDialog();
        jd.setIconImage(Toolkit.getDefaultToolkit().getImage("icop.png"));

        jd.getContentPane().setLayout(null);
        jd.setAlwaysOnTop(true);
        jd.setTitle("\\u8FDB\\u5236\\u8F6C\\u6362");
        jd.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent arg0) {
                System.exit(0);
            }
        });

        textField = new JTextField();                          //十进制

        textField.addKeyListener(new KeyAdapter() {
            public void keyReleased(KeyEvent arg0) {          //键盘输入触发
                str=textField.getText();
                if(str.length()<=0){

                    textField_1.setText("");
                    textField_2.setText("");
                    textField_3.setText("");
                }else
                {
                i=Integer.parseInt(str);
                textField_1.setText(Integer.toHexString(i));     //十进制转换二进制
                textField_2.setText(Integer.toOctalString(i));   //十进制转换八进制
                textField_3.setText(Integer.toBinaryString(i));  //十进制转换十六进制
            }
            }   
        });
        textField.setBounds(110, 38, 116, 23);
        jd.getContentPane().add(textField);
        textField.setColumns(10);

        textField_1 = new JTextField();
        textField_1.addKeyListener(new KeyAdapter() {

            public void keyReleased(KeyEvent arg0) {
                str=textField_1.getText();
                if(str.length()<=0){
                    textField.setText("");
                    textField_2.setText("");
                    textField_3.setText("");
                }else{
                i=Integer.valueOf(str,16);
                textField.setText(Integer.toString(i));
                textField_2.setText(Integer.toOctalString(i));
                textField_3.setText(Integer.toBinaryString(i));
            }
            }
        });
        textField_1.setBounds(110, 75, 116, 23);
        jd.getContentPane().add(textField_1);
        textField_1.setColumns(10);

        textField_2 = new JTextField();
        textField_2.addKeyListener(new KeyAdapter() {

            public void keyReleased(KeyEvent arg0) {
                str=textField_2.getText();
                if(str.length()<=0){
                    textField.setText("");
                    textField_1.setText("");
                    textField_3.setText("");
                }else{
                i=Integer.valueOf(str,8);
                textField.setText(Integer.toString(i));
                textField_1.setText(Integer.toHexString(i));
                textField_3.setText(Integer.toBinaryString(i));
                }
            }
        });

        textField_3 = new JTextField();
        textField_3.addKeyListener(new KeyAdapter() {
            @Override
            public void keyReleased(KeyEvent arg0) {
                str=textField_3.getText();  
                if(str.length()<=0){
                    textField.setText("");
                    textField_1.setText("");
                    textField_2.setText("");
                }else{
                i=Integer.valueOf(str,2);
                textField.setText(Integer.toString(i));
                textField_1.setText(Integer.toHexString(i));
                textField_2.setText(Integer.toOctalString(i));
                }
            }

        });
        textField_2.setBounds(110, 112, 116, 23);
        jd.getContentPane().add(textField_2);

        textField_2.setColumns(10);

        JLabel lblNewLabel = new JLabel("\\u5341\\u8FDB\\u5236\\u3000\\uFF1A");
        lblNewLabel.setBackground(SystemColor.textText);
        lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 12));
        lblNewLabel.setForeground(SystemColor.menuText);
        lblNewLabel.setBounds(40, 41, 68, 17);
        jd.getContentPane().add(lblNewLabel);

        JLabel lblNewLabel_1 = new JLabel("\\u5341\\u516D\\u8FDB\\u5236\\uFF1A");
        lblNewLabel_1.setBackground(SystemColor.textText);
        lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 12));
        lblNewLabel_1.setForeground(SystemColor.menuText);
        lblNewLabel_1.setBounds(40, 78, 68, 17);
        jd.getContentPane().add(lblNewLabel_1);

        JLabel lblNewLabel_2 = new JLabel("\\u516B\\u8FDB\\u5236\\u3000\\uFF1A");
        lblNewLabel_2.setBackground(SystemColor.textText);
        lblNewLabel_2.setFont(new Font("微软雅黑", Font.BOLD, 12));
        lblNewLabel_2.setForeground(SystemColor.menuText);
        lblNewLabel_2.setBounds(40, 115, 68, 17);
        jd.getContentPane().add(lblNewLabel_2);

        JLabel label = new JLabel("\\u4E8C\\u8FDB\\u5236\\u3000\\uFF1A");
        label.setForeground(Color.BLACK);
        label.setFont(new Font("微软雅黑", Font.BOLD, 12));
        label.setBackground(Color.BLACK);
        label.setBounds(40, 152, 68, 17);
        jd.getContentPane().add(label);

        textField_3.setBounds(110, 149, 116, 23);
        jd.getContentPane().add(textField_3);
        textField_3.setColumns(10);

        JLabel lblNewLabel_3 = new JLabel("by zhang");
        lblNewLabel_3.setBounds(218, 198, 88, 15);
        jd.getContentPane().add(lblNewLabel_3);
        jd.setSize(322,261);
        jd.setVisible(true);

    }

    public static void main(String[] args) {

            new jzzh();

    }
}
//该片段来自于http://outofmemory.cn

标签:java,基础

收藏

0人收藏

支持

0

反对

0

相关聚客文章
  1. 博主 发表 2013-08-26 02:35:24 JAVA操作Hbase基础例子
  2. Terry Zhang 发表 2014-04-27 08:18:40 [集合框架] Java 集合框架简介
  3. Terry Zhang 发表 2014-05-02 08:58:00 [集合框架] Set 接口
  4. 郑 旭东 发表 2014-01-16 16:46:51 JAVA多线程和并发基础面试问答
  5. Terry Zhang 发表 2014-04-17 15:27:06 [正则] 字符类型
  6. Terry Zhang 发表 2014-04-27 10:43:29 [集合框架] 接口
  7. 逍遥冲 发表 2013-12-05 05:53:28 [引]Java NIO —- IO复用
  8. 糖果 发表 2015-08-03 21:33:22 逆向基础(十三) JAVA (四)
  9. Terry Zhang 发表 2014-04-18 05:08:52 [NIO.2] 编写一个文件拷贝应用
  10. Terry Zhang 发表 2014-04-24 08:14:18 [正则] 边界匹配器
  11. Terry Zhang 发表 2014-05-03 06:33:32 [集合框架] List 接口
  12. Terry Zhang 发表 2014-05-13 06:05:01 [集合框架] SortedSet 接口

发表评论