AWT图形界面设计---二进制八进制十进制十六进制之间的转换.doc_第1页
AWT图形界面设计---二进制八进制十进制十六进制之间的转换.doc_第2页
AWT图形界面设计---二进制八进制十进制十六进制之间的转换.doc_第3页
AWT图形界面设计---二进制八进制十进制十六进制之间的转换.doc_第4页
AWT图形界面设计---二进制八进制十进制十六进制之间的转换.doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

import java.awt.*;import java.awt.event.*;import javax.swing.BoxLayout;public class H5 /* param args*/class stateString prevous_in;String current_in;String prevous_out;String current_out;String prevous_i_s;String prevous_o_s;String current_o_s;String current_i_s;public state()prevous_in=;current_in=; prevous_out=; current_out=; prevous_i_s=; prevous_o_s=; current_o_s=; current_i_s=;state st=new state();Frame f=new Frame(张三);Panel ptop=new Panel();Panel pbot=new Panel();Label label1=new Label(数据转换,FlowLayout.CENTER);Label label2=new Label(result,FlowLayout.CENTER);TextField tfin=new TextField(20);TextField tfout=new TextField(20);Button ok=new Button(确定);Button exit=new Button(exit);Panel pcen=new Panel();CheckboxGroup cbg1=new CheckboxGroup();CheckboxGroup cbg2=new CheckboxGroup();Checkbox in2=new Checkbox(2,cbg1,false);Checkbox in8=new Checkbox(8,cbg1,false);Checkbox in10=new Checkbox(10,cbg1,true);Checkbox in16=new Checkbox(16,cbg1,false);Checkbox out2=new Checkbox(2,cbg2,false);Checkbox out8=new Checkbox(8,cbg2,false);Checkbox out10=new Checkbox(10,cbg2,true);Checkbox out16=new Checkbox(16,cbg2,false);Panel pinshuzhi=new Panel();Panel poutshuzhi=new Panel();B_e_lis bel=new B_e_lis();B_OK_lis bokl=new B_OK_lis();int temint=0;MenuBar mb=new MenuBar();Menu edit=new Menu(编辑);MenuItem back=new MenuItem(回看,new MenuShortcut(KeyEvent.VK_B);MenuItem recover=new MenuItem(恢复,new MenuShortcut(KeyEvent.VK_R);MenuItem quit=new MenuItem(退出,new MenuShortcut(KeyEvent.VK_X);QuitListener qlisten=new QuitListener();String prevous=;String current=;String prevous_s=;String current_s=;public void init()System.out.println(quit.getLabel();f.addWindowListener(new Mylistener();/f.setBounds(0,0,400,400);ptop.setLayout(new BoxLayout(ptop,BoxLayout.Y_AXIS);ptop.add(label1);/ptop.add(tf);pbot.add(ok);exit.addActionListener(bel);ok.addActionListener(bokl);pbot.add(exit);pinshuzhi.add(in2);pinshuzhi.add(in8);pinshuzhi.add(in10);pinshuzhi.add(in16); poutshuzhi.add(out2);poutshuzhi.add(out8);poutshuzhi.add(out10); poutshuzhi.add(out16);pcen.setLayout(new BoxLayout(pcen,BoxLayout.Y_AXIS);pcen.add(tfin);pcen.add(pinshuzhi);pcen.add(label2);pcen.add(poutshuzhi);pcen.add(tfout);f.add(ptop,BorderLayout.NORTH);f.add(pbot,BorderLayout.SOUTH);f.add(pcen,BorderLayout.CENTER);quit.addActionListener(qlisten);edit.addActionListener(qlisten);edit.add(back);edit.add(recover);edit.add(quit);mb.add(edit);f.setMenuBar(mb);f.setBounds(50, 50, 400, 300);/f.pack();f.setVisible(true); class Mylistener extends WindowAdapterpublic void windowClosing(WindowEvent e)System.exit(0); class QuitListener implements ActionListenerpublic void actionPerformed(ActionEvent e)System.out.println(menu);String s=e.getActionCommand();if(s.equals(退出) System.out.println(quit);System.exit(0);if(s.equals(回看)tfout.setText(st.prevous_out);tfin.setText(st.prevous_in);if(in2.getLabel().equals(st.prevous_i_s) in2.setState(true);if(in8.getLabel().equals(st.prevous_i_s) in8.setState(true);if(in10.getLabel().equals(st.prevous_i_s) in10.setState(true);if(in16.getLabel().equals(st.prevous_i_s) in16.setState(true);if(s.equals(恢复)tfout.setText(st.current_out);tfin.setText(st.current_in);if(out2.getLabel().equals(st.current_i_s) out2.setState(true);if(out8.getLabel().equals(st.current_i_s) out8.setState(true);if(out10.getLabel().equals(st.current_i_s) out10.setState(true);if(out16.getLabel().equals(st.current_i_s) out16.setState(true); private int get_int(char c)int tem=-1;if(c=0 & c=A & c=a & c=0 & c=0 & c=0 & c=0 & c=a & c=A & c=F) return true;return false;class B_OK_lis implements ActionListenerpublic void actionPerformed(ActionEvent e)st.prevous_i_s=st.current_i_s;st.prevous_in=st.current_in;st.prevous_o_s=st.current_o_s;st.prevous_out=st.current_out;temint=0;System.out.println(ok);String sin=tfin.getText();String sout=null;char tem;tem=new charsin.length();tem=sin.toCharArray();/for(int j=0;jsin.length();j+)/int i=Integer.parseInt(s);/boolean ss;/ss=in2.getState();/System.out.println(ss);/int i=Integer./tfout.setText(sout);/for(int i=0;isin.length();i+)/System.out.println(temi);/System.out.println(sin.length();boolean flag=true;if(in2.getState()=true)st.current_i_s=in2.getLabel();for(int i=0;isin.length();i+)tryif(check_2(temi)=false) throw new Exception(wrong input);else temint=temint*2+get_int(temi);catch(Exception ea)sout=input wrong+temi;flag=false;break; if(in10.getState()=true)st.current_i_s=in10.getLabel();for(int i=0;isin.length();i+)tryif (check_10(temi)=false) throw new Exception(wrong input); else temint=temint*10+get_int(temi); catch(Exception ea)sout=input wrong+temi;flag=false;break;if(in8.getState()=true)st.current_i_s=in8.getLabel();for(int i=0;isin.length();i+)tryif(check_8(temi)=false) throw new Exception(wrong input);else temint=temint*8+get_int(temi);catch(Exception ea)sout=input wrong+temi; flag=false;break;if(in16.getState()=true)st.current_i_s=in16.getLabel();for(int i=0;isin.length();i+)tryif(check_16(temi)=false)throw new Exception(wrong input);else temint=temint*16+get_int(temi);catch(Exception ea)sout=input wrong+temi; flag=false;break;if(out2.getState()=true & flag)st.current_o_s=out2.getLabel(); sout=Integer.toBinaryString(temint);if(out8.getState()=true & flag) st.current_o_s=out8.getLabel();sout=Integer.toOctalString(temint); if(out10.getState()=true & flag)st.current_o_s=out10.getLabel();sout=Integer.toString(temint);if(out16.getState()=true & flag)st.current_o_s=out16.getLabel(); sout=Integer.toHexString(temint);st.current_in=s

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论