80分求JAVA高手。

来源:百度知道 编辑:UC知道 时间:2024/06/04 07:12:31
有2个文本框(1个用于输入,1个用于输出),3个单选框(分别是2,8,16进制),在1文本框中输入十进制数,选中3个单选框其中一个单选框按回车会在输出文本框显示对应进制数。

匆忙,界面写的简单

  import java.awt.*;
  import java.awt.event.*;

  import javax.swing.*;

  public class Mconversion extends JFrame implements ActionListener {

  private JTextField f1;
  private JTextField f2;
  private JRadioButton binary, octal, hexadecimal;
  private ButtonGroup radioGroup;
  private int n = 0;

  public Mconversion() {
  super("进制转换");
  Container c = getContentPane();
  c.setLayout(new FlowLayout());
  f1 = new JTextField("输入:", 20);
  f2 = new JTextField("输出:", 20);

  f1.addActionListener(this);
  f2.addActionListener(this);

  binary = new JRadioButton("二进制", false);
  octal = new JRadioButton("八进制", false);
  hexadecimal = new JRadioButton("十六进制", false);

  binary.addItemListener(new RadioButtonHandler(2));
  octal.addItemListener(new RadioButtonHandler(