收藏 分销(赏)

经典Java程序源代码.doc

上传人:w****g 文档编号:6623392 上传时间:2024-12-17 格式:DOC 页数:90 大小:123.50KB 下载积分:18 金币
下载 相关 举报
经典Java程序源代码.doc_第1页
第1页 / 共90页
经典Java程序源代码.doc_第2页
第2页 / 共90页


点击查看更多>>
资源描述
经典Java程序源代码 1.加法器(该java源文件的名称是) import .*; import .*; public class Adder implements ActionListener { JFrame AdderFrame; JTextField TOprand1; JTextField TOprand2; JLabel LAdd,LSum; JButton BAdd,BClear; JPanel JP1,JP2; public Adder() { AdderFrame=new JFrame("AdderFrame"); TOprand1=new JTextField(""); TOprand2=new JTextField(""); LAdd=new JLabel("+"); LSum=new JLabel("= "); BAdd=new JButton("Add"); BClear=new JButton("Clear"); JP1=new JPanel(); JP2=new JPanel(); (this); (new ActionListener() { public void actionPerformed(ActionEvent event) { (""); (""); ("="); } }); (JP1); (TOprand1); (LAdd); (TOprand2); (LSum); (JP2); (BAdd); (BClear); ().setLayout(new BorderLayout()); ().add(JP1,; ().add(JP2,; (new WindowAdapter() { public void windowClosing(WindowEvent event) { (0); } }); (); (true); (false); (250,100); } public void actionPerformed(ActionEvent event) { double sum=(double)()).doubleValue()+()).doubleValue()); ("="+sum); } public static void main(String[] args) { Adder adder=new Adder(); } } 2. 小型记事本(该java源文件由两个类构成,名称为) import .*; import .*; import .*; class mynotepad extends JFrame { File file=null; Color color=; mynotepad() { initTextContent(); initMenu(); initAboutDialog(); } void initTextContent() { getContentPane().add(new JScrollPane(content)); } JTextPane content=new JTextPane(); JFileChooser openfile=new JFileChooser(); JColorChooser opencolor=new JColorChooser(); JDialog about=new JDialog(this); JMenuBar menu=new JMenuBar(); ength;j++) { menus[i].add(optionofmenu[i][j]); optionofmenu[i][j].addActionListener( action ); } } (menu); } ActionListener action=new ActionListener() { quals(name)) { (""); file=null; } else if("打开".equals(name)) { if(file !=null) (file); int returnVal=; if(returnVal== { file=(); unfold(); } } else if("保存".equals(name)) { if(file!=null) (file); int returnVal=; if(returnVal== { file=(); saving(); } } else if("退出".equals(name)) { mynotepad f=new mynotepad(); int s=(f,"退出","退出",; if(s== (0); } else if("剪切".equals(name)) { (); } else if("复制".equals(name)) { (); } else if("粘贴".equals(name)) { (); } else if("颜色".equals(name)) { color=,"",color); (color); } else if("关于".equals(name)) { (300,150); (); } } }; void saving() { try { FileWriter Writef=new FileWriter(file); ()); (); } catch(Exception e) { (); } } void unfold() { try { FileReader Readf=new FileReader(file); int len=(int)(); char []buffer=new char[len]; (buffer,0,len); (); (new String(buffer)); } catch(Exception e) { (); } } void initAboutDialog() { (new GridLayout(3,1)); ().setBackground; ().add(new JLabel("我的记事本程序"));dd(new JLabel("制作者:Fwx")); ().add(new JLabel("2007年12月")); (true); ; import .*; class simplecalculator { static String point=new String(); static String Amal=new String(); static String ONE=new String(); static String TWO=new String(); static String THREE=new String(); static String FOUR=new String(); static String FIVE=new String(); static String SIX=new String(); static String SEVEN=new String(); static String EIGHT=new String(); static String NINE=new String(); static String ZERO=new String(); static String ResultState=new String(); static Double QF; static JButton zero=new JButton("0"); static JButton one=new JButton("1"); static JButton two=new JButton("2"); static JButton three=new JButton("3"); static JButton four=new JButton("4"); static JButton five=new JButton("5"); static JButton six=new JButton("6"); static JButton seven=new JButton("7"); static JButton eight=new JButton("8"); static JButton nine=new JButton("9"); static JButton add=new JButton("+"); static JButton sub=new JButton("-"); static JButton mul=new JButton("*"); static JButton div=new JButton("/"); static JButton QuFan=new JButton("+/-"); static JButton Dian=new JButton("."); static JButton equal=new JButton("="); static JButton clear=new JButton("C"); static JButton BaiFen=new JButton("%"); static JButton FenZhiYi=new JButton("1/x"); static int i=0; static Double addNumber; static Double subNumber; static Double mulNumber; static Double divNumber; static Double equalNumber; static Double temp; static JTextArea result=new JTextArea(1,20); public static void main(String[] args) { JFrame frame=new JFrame("计算器"); (false); (""); ResultState="窗口空"; JPanel ForResult=new JPanel(); JPanel ForButton7_clear=new JPanel(); JPanel ForButton4_mul=new JPanel(); JPanel ForButton1_sub=new JPanel(); JPanel ForButton0_equal=new JPanel(); FlowLayout FLO=new FlowLayout(); (result); (FLO); (seven); (eight); (nine); (div); (clear); (FLO); (four); (five); (six); (mul); (BaiFen); (FLO); (one); (two); (three); (sub); (FenZhiYi); (FLO); (zero); (QuFan); (Dian); (add); (equal); ().setLayout(FLO); ().add(ForResult); ().add(ForButton7_clear); ().add(ForButton4_mul); ().add(ForButton1_sub); ().add(ForButton0_equal); ; (250,250,245,245); (false); (true); ( new ActionListener() { public void actionPerformed(ActionEvent e) { (""); ZERO=""; ONE=""; TWO=""; THREE=""; FOUR=""; FIVE=""; SIX=""; SEVEN=""; EIGHT=""; NINE=""; ResultState="窗口空"; point=""; i=0; } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { ZERO="已经点击"; ResultState="窗口不为空"; if(ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FOUR=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击") { ("0"); } if(ResultState=="窗口空") { ("0"); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { ONE="已经点击"; ResultState="窗口不为空"; if(point=="已经点击"||ZERO!="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!="0") { ("1"); } if(ResultState=="窗口空") { ("1"); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { TWO="已经点击"; ResultState="窗口不为空"; if(point=="已经点击"||ZERO!="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!="0") { ("2"); } if(ResultState=="窗口空") { ("2"); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { THREE="已经点击"; ResultState="窗口不为空"; if(point=="已经点击"||ZERO!="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!="0") { ("3"); } if(ResultState=="窗口空") { ("3"); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { FOUR="已经点击"; ResultState="窗口不为空"; if(point=="已经点击"||ZERO!="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!="0") { ("4"); } if(ResultState=="窗口空") { ("4"); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { FIVE="已经点击"; ResultState="窗口不为空"; if(point=="已经点击"||ZERO!="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!="0") { ("5"); } if(ResultState=="窗口空") { ("6"); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { SIX="已经点击"; ResultState="窗口不为空"; if(point=="已经点击"||ZERO!="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!="0") { ("6"); } if(ResultState=="窗口空") { ("6"); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { SEVEN="已经点击"; ResultState="窗口不为空"; if(point=="已经点击"||ZERO!="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!="0") { ("7"); } if(ResultState=="窗口空") { ("7"); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { EIGHT="已经点击"; ResultState="窗口不为空"; if(point=="已经点击"||ZERO!="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!="0") { ("8"); } if(ResultState=="窗口空") { ("8"); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { NINE="已经点击"; ResultState="窗口不为空"; if(point=="已经点击"||ZERO!="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!="0") { ("9"); } if(ResultState=="窗口空") { ("9"); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { point="已经点击"; i=i+1; if(ResultState=="窗口不为空"&&i==1) { ("."); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { Amal="已经选择加号"; addNumber=()).doubleValue(); (""); i=0; } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { Amal="已经选择减号"; subNumber=()).doubleValue(); (""); i=0; } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { Amal="已经选择乘号"; mulNumber=()).doubleValue(); (""); i=0; } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { Amal="已经选择除号"; divNumber=()).doubleValue(); (""); i=0; } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { QF=new Double()).doubleValue()); QF=QF*(-1); ()); } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { equalNumber=()).doubleValue(); if(Amal=="已经选择加号") { temp=addNumber+equalNumber; ()); } if(Amal=="已经选择减号") { temp=subNumber-equalNumber; ()); } if(Amal=="已经选择乘号") { temp=mulNumber*equalNumber; ()); } if(Amal=="已经选择除号") { temp=divNumber/equalNumber; ()); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { if(ResultState=="窗口不为空") { temp=()).doubleValue()/100; ()); } } }); ( new ActionListener() { public void actionPerformed(ActionEvent e) { temp=1/()).doubleValue()); ()); } }); } } 3. 图形化写字板(该java源文件的名称是) ; import .*; import .*; import class JNotePadUI extends JPanel { etSystemClipboard(); String text = ""; etPath(); if (file == null) { return; } etPath(); if (savefile == null) { return; } else { String docToSave = (); if (docToSave != null) { FileOutputStream fstrm = null; BufferedOutputStream ostrm = null; try { fstrm = new FileOutputStream(savefile); ostrm = new BufferedOutputStream(fstrm); byte[] bytes = null; try { bytes = (); } catch (Exception e1) { (); } (bytes); } catch (IOException io) { "IOException: "+ ()); } finally { try { (); (); (); } catch (IOException ioe) { "IOException: "+ ()); } } } } } else { return; } } } etVisible(true); (0); } dd(applet, ; (new appCloseL()); (800, 500); (500,170); (true); (); (false); } } 4. 数字化的连连看(该java源文件的名称是) import .*; import .*; import public class lianliankan implements ActionListener { JFrame mainFrame; ddActionListener(this); (diamondsButton[cols][rows]); } } exitButton=new JButton("退出"); (this); resetButton=new JButton("重列"); (this); newlyButton=new JButton("再来一局"); (this); (exitButton); (resetButton); (newlyButton); ()))); (fractionLable); (280,100,500,450); (true); } public void randomBuild() { int randoms,cols,rows; for(int twins=1;twins<=15;twins++) { randoms=(int)()*25+1); for(int alike=1;alike<=2;alike++) { cols=(int)()*6+1); rows=(int)()*5+1); while(grid[cols][rows]!=0) { cols=(int)()*6+1); rows=(int)()*5+1); } [cols][rows]=randoms; } } } public void fraction() { ())+100)); } public void reload() { int save[] = new int[30]; int n=0,cols,rows; int grid[][]= new int[8][7]; for(int i=0;i<=6;i++) { for(int j=0;j<=5;j++) { if[i][j]!=0) { save[n]=[i][j]; n++; } } } n=n-1; =grid; while(n>=0) { cols=(int)()*6+1); rows=(int)()*5+1); while(grid[cols][rows]!=0) { cols=(int)()*6+1); rows=(int)()*5+1); } [cols][row
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服