有十六进制的计算机吗,吧里有学编程的吗,16进制计算机怎么转换啊。

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

4224c1bb1eddf83a18123fcd81db18b5.png源代码:

package cn.edu.lsu;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JRadioButton;

import javax.swing.JTextField;

public class RadixSwitch {

public JFrame frame;

private JTextField fromTf, toTf;

private JRadioButton fromEr, fromBa, fromShi, fromShiLiu, toEr, toBa,

toShi, toShiLiu;

private ButtonGroup fromBg, toBg;

private JLabel fromLabel, toLabel;

private JButton btnOK, btnReset;

private Judge judge = new Judge();

private int locationWidth,locationHeight;//位置

private GetScreenSize getScreenSize = new GetScreenSize();

public RadixSwitch() {

MyActionListener myActionListener = new MyActionListener();

locationWidth = (int)(getScreenSize.width * 0.305);

locationHeight = (int)(getScreenSize.height * 0.26);

frame = new JFrame("进制转换");

fromTf = new JTextField(35);

fromTf.setHorizontalAlignment(4);

toTf = new JTextField(35);

toTf.setEditable(false);

toTf.setHorizontalAlignment(4);

fromEr = new JRadioButton("二进制");

fromBa = new JRadioButton("八进制");

fromShi = new JRadioButton("十进制");

fromShi.setSelected(true);

fromShiLiu = new JRadioButton("十六进制");

fromBg = new ButtonGroup();

fromBg.add(fromEr);

fromBg.add(fromBa);

fromBg.add(fromShi);

fromBg.add(fromShiLiu);

toEr = new JRadioButton("二进制");

toBa = new JRadioButton("八进制");

toShi = new JRadioButton("十进制");

toShi.setSelected(true);

toShiLiu = new JRadioButton("十六进制");

toBg = new ButtonGroup();

toBg.add(toEr);

toBg.add(toBa);

toBg.add(toShi);

toBg.add(toShiLiu);

fromLabel = new JLabel("选择输入的进制: ");

toLabel = new JLabel("选择输出的进制: ");

btnOK = new JButton("确定转换");

btnOK.addActionListener(myActionListener);

btnReset = new JButton("清空数据");

btnReset.addActionListener(myActionListener);

frame.add(fromTf);

frame.add(fromLabel);

frame.add(fromEr);

frame.add(fromBa);

frame.add(fromShi);

frame.add(fromShiLiu);

frame.add(toLabel);

frame.add(toEr);

frame.add(toBa);

frame.add(toShi);

frame.add(toShiLiu);

frame.add(toTf);

frame.add(btnReset);

frame.add(btnOK);

frame.setLayout(new FlowLayout());

frame.setSize(420, 200);

frame.setVisible(true);

frame.setResizable(false);

frame.setLocation(locationWidth, locationHeight);

frame.setAlwaysOnTop(true);

frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

}

class MyActionListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

if (e.getSource() == btnReset) {

setNull();

fromShi.setSelected(true);

toShi.setSelected(true);

}

if (e.getSource() == btnOK) {

if ((!judge.isShi(fromTf.getText().toString()) && !fromShiLiu.isSelected())

|| (fromShiLiu.isSelected() && !judge.isShiLiu(fromTf.getText().toString()))

|| (fromEr.isSelected() && !judge.isEr(fromTf.getText().toString()))

|| (fromBa.isSelected() && !judge.isBa(fromTf.getText().toString()))) {

new ShowError(frame);//弹出错误提示对话框

setNull();

}

if (fromBa.isSelected() && toEr.isSelected()) {// 八进制——》二进制

toTf.setText("" + Integer.toBinaryString(Integer.parseInt(fromTf.getText().toString(), 8)));

}

if (fromShi.isSelected() && toEr.isSelected()) {// 十进制——》二进制

toTf.setText("" + Integer.toBinaryString(Integer.parseInt(fromTf.getText().toString())));

}

if (fromShiLiu.isSelected() && toEr.isSelected()) {// 十六进制——》二进制

toTf.setText("" + Integer.toBinaryString(Integer.parseInt(fromTf.getText().toString(), 16)));

}

if (fromEr.isSelected() && toBa.isSelected()) {// 二进制——》八进制

toTf.setText("" + Integer.toOctalString(Integer.parseInt(fromTf.getText().toString(), 2)));

}

if (fromShi.isSelected() && toBa.isSelected()) {// 十进制——》八进制

toTf.setText("" + Integer.toOctalString(Integer.parseInt(fromTf.getText())));

}

if (fromShiLiu.isSelected() && toBa.isSelected()) {// 十六进制——》八进制

toTf.setText("" + Integer.toOctalString(Integer.parseInt(fromTf.getText().toString(), 16)));

}

if (fromEr.isSelected() && toShi.isSelected()) {// 二进制——》十进制

toTf.setText("" + Integer.parseInt(fromTf.getText().toString(), 2));

}

if (fromBa.isSelected() && toShi.isSelected()) {// 八进制——》十进制

toTf.setText("" + Integer.parseInt(fromTf.getText().toString(), 8));

}

if (fromShiLiu.isSelected() && toShi.isSelected()) {// 十六进制——》十进制

toTf.setText("" + Integer.parseInt(fromTf.getText().toString(), 16));

}

if (fromEr.isSelected() && toShiLiu.isSelected()) {// 二进制——》十六进制

toTf.setText("" + Integer.toHexString(Integer.parseInt(fromTf.getText().toString(), 2)));

}

if (fromBa.isSelected() && toShiLiu.isSelected()) {// 八进制——》十六进制

toTf.setText("" + Integer.toHexString(Integer.parseInt(fromTf.getText().toString(), 8)));

}

if (fromShi.isSelected() && toShiLiu.isSelected()) {// 十进制——》十六进制

toTf.setText("" + Integer.toHexString(Integer.parseInt(fromTf.getText())));

}

if (fromShi.isSelected() && toShi.isSelected()

|| fromEr.isSelected() && toEr.isSelected()

|| fromBa.isSelected() && toBa.isSelected()

|| fromShiLiu.isSelected() && toShiLiu.isSelected()) {// 十进制——》十进制

toTf.setText(fromTf.getText().toString());

}

}

}

}

public void setNull(){

fromTf.setText("");

toTf.setText("");

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值