📄 zhuanhuan.java
字号:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class Zhuanhuan extends Frame implements ActionListener,WindowListener
{
private TextField text_shi,text_er,text_ba,text_shiliu;
private Dialog dialog;
private Label label_dialog;
public Zhuanhuan()
{
super("十进制整数转换");
this.setSize(200,160);
this.setResizable(false);
this.setBackground(java.awt.Color.lightGray);
this.setLocation(380,220);
this.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT));
this.add(new Label(" 十进制"));
text_shi=new TextField(6);
this.add(text_shi);
text_shi.addActionListener(this);
this.add(new Label(" 二进制"));
text_er=new TextField(12);
this.add(text_er);
text_er.setEditable(false);
this.add(new Label(" 八进制"));
text_ba=new TextField(12);
this.add(text_ba);
text_ba.setEditable(false);
this.add(new Label("十六进制"));
text_shiliu=new TextField(12);
this.add(text_shiliu);
text_shiliu.setEditable(false);
this.addWindowListener(this);
this.setVisible(true);
dialog=new Dialog(this,"提示",true);
dialog.setSize(240,80);
label_dialog=new Label("",Label.CENTER);
dialog.add(label_dialog);
dialog.addWindowListener(this);
}
public void actionPerformed(ActionEvent e)
{
try
{
int x=Integer.valueOf(text_shi.getText()).intValue();
text_er.setText(Integer.toBinaryString(x));
text_ba.setText(Integer.toOctalString(x));
text_shiliu.setText(Integer.toHexString(x));
// text_er.setText(x.toBinaryString());
// text_er.setText(decimalToBinary(text_shi.getText()));
// String strBin = hexToBinary(strHex);
// strDec = binaryToDecimal(strBin);
// Integer.parseInt(binary,2);
// Integer.parseInt(text_shi.getText(),2);
}
catch(NumberFormatException xj)
{
label_dialog.setText("\""+text_shi.getText()+"\"输入错误,请重新输入!");
dialog.setLocation(this.getX()+100,this.getY()+100);
dialog.setVisible(true);
}
finally
{
text_shi.setText("");
text_er.setText("");
text_ba.setText("");
text_shiliu.setText("");
}
}
public void windowClosing(WindowEvent e)
{
if(e.getSource()==dialog)
dialog.setVisible(false);
else
System.exit(0);
}
public void windowOpened(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public static void main(String[] args)
{
new Zhuanhuan();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -