Java万能进制转换器Word文档格式.docx

上传人:b****5 文档编号:20259616 上传时间:2023-01-21 格式:DOCX 页数:20 大小:41.83KB
下载 相关 举报
Java万能进制转换器Word文档格式.docx_第1页
第1页 / 共20页
Java万能进制转换器Word文档格式.docx_第2页
第2页 / 共20页
Java万能进制转换器Word文档格式.docx_第3页
第3页 / 共20页
Java万能进制转换器Word文档格式.docx_第4页
第4页 / 共20页
Java万能进制转换器Word文档格式.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

Java万能进制转换器Word文档格式.docx

《Java万能进制转换器Word文档格式.docx》由会员分享,可在线阅读,更多相关《Java万能进制转换器Word文档格式.docx(20页珍藏版)》请在冰豆网上搜索。

Java万能进制转换器Word文档格式.docx

importjava.awt.Panel;

importjava.awt.TextField;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjava.awt.event.FocusEvent;

importjava.awt.event.FocusListener;

importjava.awt.event.ItemEvent;

importjava.awt.event.ItemListener;

importjava.awt.event.KeyEvent;

importjava.awt.event.KeyListener;

importjavax.swing.ButtonGroup;

importjavax.swing.JRadioButton;

publicclassScaleFrameextendsFrameimplementsItemListener,KeyListener

/**

*

*/

privatestaticfinallongserialVersionUID=2007836309679852768L;

JRadioButtonoldDecimalRadix;

JRadioButtonoldBinaryRadix;

JRadioButtonoldOctalRadix;

JRadioButtonoldHexRadix;

JRadioButtonoldOtherRadix;

ButtonGroupoldScaleGroup;

JRadioButtonnewDecimalRadix;

JRadioButtonnewBinaryRadix;

JRadioButtonnewOctalRadix;

JRadioButtonnewHexRadix;

JRadioButtonnewOtherRadix;

ButtonGroupnewScaleGroup;

intoldRadix;

intnewRadix;

TextFieldnewValue;

TextFieldoldValue;

TextFieldoldCustomRadixTF;

TextFieldnewCustomRadixTF;

publicvoidlaunchFrame()

this.setTitle("

Java万能进制转换器"

);

this.setVisible(true);

this.addWindowListener(newMyWindowListener());

PaneloldRadixPanel=newPanel();

oldValue=newTextField(10);

PaneloldValuePanel=newPanel();

oldValuePanel.add(newLabel("

转换前的值:

"

));

oldValuePanel.add(oldValue);

oldRadixPanel.setBackground(Color.gray);

oldRadixPanel.setLayout(newGridLayout(3,1));

oldRadixPanel.add(oldValuePanel);

LabeloldRadixLabel=newLabel("

转换前的进制如下:

"

oldCustomRadixTF=newTextField(10);

oldCustomRadixTF.addFocusListener(newFocusListener()

publicvoidfocusLost(FocusEventarg0)

//System.out.println();

Stringtext=oldCustomRadixTF.getText();

intoldTextInt=0;

if(text.indexOf("

."

)==-1)

oldTextInt=Integer.parseInt(text);

if(oldTextInt==10||oldTextInt==2||oldTextInt==8||oldTextInt==16)

switch(oldTextInt)

case10:

oldDecimalRadix.setSelected(true);

break;

case2:

oldBinaryRadix.setSelected(true);

case8:

oldOctalRadix.setSelected(true);

case16:

oldHexRadix.setSelected(true);

else

if(0!

=oldTextInt)//当输入不是10、2、8、16的整数时。

if(oldDecimalRadix.isSelected())

oldOtherRadix.setSelected(true);

elseif(oldBinaryRadix.isSelected())

elseif(oldOctalRadix.isSelected())

elseif(oldHexRadix.isSelected())

if(oldOtherRadix.isSelected())

oldCustomRadixTF.setText(text);

publicvoidfocusGained(FocusEventarg0)

});

newCustomRadixTF=newTextField(10);

newCustomRadixTF.addFocusListener(newFocusListener()

Stringtext=newCustomRadixTF.getText();

intnewTextInt=0;

newTextInt=Integer.parseInt(text);

if(newTextInt==10||newTextInt==2||newTextInt==8||newTextInt==16)

switch(newTextInt)

newDecimalRadix.setSelected(true);

newBinaryRadix.setSelected(true);

newOctalRadix.setSelected(true);

newHexRadix.setSelected(true);

=newTextInt)//当输入不是10、2、8、16的整数时。

if(newDecimalRadix.isSelected())

//System.out.println("

10"

newOtherRadix.setSelected(true);

elseif(newBinaryRadix.isSelected())

elseif(newOctalRadix.isSelected())

elseif(newHexRadix.isSelected())

if(newOtherRadix.isSelected())

newCustomRadixTF.setText(text);

PaneloldCustomPanel=newPanel();

oldCustomPanel.add(oldRadixLabel);

oldCustomPanel.add(oldCustomRadixTF);

oldRadixLabel.setAlignment

(1);

oldRadixPanel.add(oldCustomPanel);

//oldRadixPanel.add(radixRadios);

oldDecimalRadix=newJRadioButton(ScaleUtil.SCALE_DECIMAL_STR);

oldBinaryRadix=newJRadioButton(ScaleUtil.SCALE_BINARY_STR);

oldOctalRadix=newJRadioButton(ScaleUtil.SCALE_OCTAL_STR);

oldHexRadix=newJRadioButton(ScaleUtil.SCALE_HEX_STR);

oldOtherRadix=newJRadioButton("

oldOtherRadix.setVisible(false);

oldScaleGroup=newButtonGroup();

oldScaleGroup.add(oldDecimalRadix);

oldScaleGroup.add(oldBinaryRadix);

oldScaleGroup.add(oldOctalRadix);

oldScaleGroup.add(oldHexRadix);

oldScaleGroup.add(oldOtherRadix);

PaneloldRadixRadioButton=newPanel();

oldRadixRadioButton.add(oldDecimalRadix);

oldRadixRadioButton.add(oldBinaryRadix);

oldRadixRadioButton.add(oldOctalRadix);

oldRadixRadioButton.add(oldHexRadix);

oldRadixPanel.add(oldRadixRadioButton);

oldDecimalRadix.addItemListener(this);

oldBinaryRadix.addItemListener(this);

oldOctalRadix.addItemListener(this);

oldHexRadix.addItemListener(this);

oldDecimalRadix.addKeyListener(this);

oldBinaryRadix.addKeyListener(this);

oldOctalRadix.addKeyListener(this);

oldHexRadix.addKeyListener(this);

PanelnewRadixPanel=newPanel();

newRadixPanel.setBackground(newColor(255,200,200));

ButtonexcuButton=newButton();

newDecimalRadix=newJRadioButton(ScaleUtil.SCALE_DECIMAL_STR);

newBinaryRadix=newJRadioButton(ScaleUtil.SCALE_BINARY_STR);

newOctalRadix=newJRadioButton(ScaleUtil.SCALE_OCTAL_STR);

newHexRadix=newJRadioButton(ScaleUtil.SCALE_HEX_STR);

newOtherRadix=newJRadioButton("

newOtherRadix.setVisible(false);

newScaleGroup=newButtonGroup();

newScaleGroup.add(newDecimalRadix);

newScaleGroup.add(newBinaryRadix);

newScaleGroup.add(newOctalRadix);

newScaleGroup.add(newHexRadix);

newScaleGroup.add(newOtherRadix);

PanelnewRadixRadioButton=newPanel();

newRadixRadioButton.add(newDecimalRadix);

newRadixRadioButton.add(newBinaryRadix);

newRadixRadioButton.add(newOctalRadix);

newRadixRadioButton.add(newHexRadix);

newRadixPanel.setLayout(newGridLayout(2,1));

newDecimalRadix.addItemListener(this);

newBinaryRadix.addItemListener(this);

newOctalRadix.addItemListener(this);

newHexRadix.addItemListener(this);

newDecimalRadix.addKeyListener(this);

newBinaryRadix.addKeyListener(this);

newOctalRadix.addKeyListener(this);

newHexRadix.addKeyListener(this);

excuButton.setLabel("

转化"

PanelnewCustomPanel=newPanel();

newCustomPanel.add(newCustomRadixTF);

newCustomPanel.add(excuButton);

excuButton.addActionListener(newMyActionListener());

newRadixPanel.add(newRadixRadioButton);

newRadixPanel.add(newCustomPanel);

PanelnewValuePanel=newPanel();

LabelnewValueLabel=newLabel("

转换后的值:

//newValueLabel.setAlignment(0);

newValuePanel.add(newValueLabel);

newValuePanel.setLayout(newFlowLayout());

newValue=newTextField(20);

newValue.setBackground(Color.red);

newValue.setSize(100,200);

newValue.setEditable(false);

newValuePanel.add(newValue);

newValuePanel.setBackground(newColor(200,200,255));

this.setLayout(newBorderLayout());

this.add(oldRadixPanel,BorderLayout.NORTH);

this.add(newRadixPanel,BorderLayout.CENTER);

this.add(newValuePanel,BorderLayout.SOUTH);

this.pack();

this.setBounds(300,200,500,230);

this.setResizable(false);

publicstaticvoidmain(String[]args)

newScaleFrame().launchFrame();

//事件单选在用户已选定或取消选定某项时调用。

publicvoiditemStateChanged(ItemEvente)

oldCustomRadixTF.setText("

if(e.getSource()==oldDecimalRadix)

oldRadix=ScaleUtil.SCALE_DECIMAL;

elseif(e.getSource()==oldBinaryRadix)

oldRadix=ScaleUtil.SCALE_BINARY;

elseif(e.getSource()==oldOctalRadix)

oldRadix=ScaleUtil.SCALE_OCTAL;

elseif(e.getSource()==oldHexRadix)

oldRadix=ScaleUtil.SCALE_HEX;

if(e.getSource()==newDecimalRadix)

newRadix=ScaleUtil.SCALE_DECIMAL;

elseif(e.getSource()==newBinaryRadix)

newRadix=ScaleUtil.SCALE_BINARY;

elseif(e.getSource()==newOctalRadix)

newRadix=ScaleUtil.SCALE_OCTAL;

elseif(e.getSource()==newHexRadix)

newRadix=ScaleUtil.SCALE_HEX;

if(oldRadix!

=0)

+oldRadix);

if(newRadix!

newCustomRadixTF.setText("

+newRadix);

classMyActionListenerimplementsActionListener

publicvoidactionPerformed(ActionEventarg0)

execute!

//System.out.println(oldRadix+"

"

+newRadix);

//newValue.setText(oldRadix+"

newValue.setText("

intoldCustomRadInt=0;

intnewCustomRadInt=0;

StringoldV=oldValue.getText();

StringoldCustomRad=oldCustomRadixTF.getText();

StringnewCustomRad=newCustomRadixTF.getText();

if(oldCustomRad.indexOf("

)==-1&

&

!

oldCustomRad.equals("

))

oldCustomRadInt=Integer.parseInt(oldCustomRad);

if(newCustomRad.indexOf("

newCustomRad.equals("

newCustomRadInt=Integer.parseInt(newCustomRad);

=oldCustomRadInt)

oldRadix=oldCustomRadInt;

=newCustomRadInt)

newRadix=newCustomRadInt;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 预防医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1