欢迎来到天天文库
浏览记录
ID:20601544
大小:1.16 MB
页数:136页
时间:2018-10-14
《经典java程序源代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、经典Java程序源代码1.加法器(该java源文件的名称是Adder.java)importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassAdderimplementsActionListener{JFrameAdderFrame;JTextFieldTOprand1;JTextFieldTOprand2;JLabelLAdd,LSum;JButtonBAdd,BClear;JPanelJP1,JP2;publicAdder(){AdderFrame=n
2、ewJFrame("AdderFrame");TOprand1=newJTextField("0.0");TOprand2=newJTextField("0.0");LAdd=newJLabel("+");LSum=newJLabel("=");BAdd=newJButton("Add");BClear=newJButton("Clear");JP1=newJPanel();JP2=newJPanel();BAdd.addActionListener(this);BClear.addActionListener(newActionLis
3、tener(){publicvoidactionPerformed(ActionEventevent){TOprand1.setText("0.0");TOprand2.setText("0.0");LSum.setText("=");}});AdderFrame.add(JP1);JP1.add(TOprand1);JP1.add(LAdd);JP1.add(TOprand2);JP1.add(LSum);AdderFrame.add(JP2);JP2.add(BAdd);JP2.add(BClear);AdderFrame.getC
4、ontentPane().setLayout(newBorderLayout());AdderFrame.getContentPane().add(JP1,BorderLayout.NORTH);AdderFrame.getContentPane().add(JP2,BorderLayout.SOUTH);AdderFrame.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEventevent){System.exit(0);}});AdderFra
5、me.pack();AdderFrame.setVisible(true);AdderFrame.setResizable(false);AdderFrame.setSize(250,100);}publicvoidactionPerformed(ActionEventevent){doublesum=(double)(Double.valueOf(TOprand1.getText()).doubleValue()+Double.valueOf(TOprand2.getText()).doubleValue());LSum.setTex
6、t("="+sum);}publicstaticvoidmain(String[]args){Adderadder=newAdder();}}2.小型记事本(该java源文件由两个类构成,名称为Notepad.java)importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjava.io.*;classmynotepadextendsJFrame{Filefile=null;Colorcolor=Color.red;mynotepad(){initTextCo
7、ntent();initMenu();initAboutDialog();}voidinitTextContent(){getContentPane().add(newJScrollPane(content));}JTextPanecontent=newJTextPane();JFileChooseropenfile=newJFileChooser();JColorChooseropencolor=newJColorChooser();JDialogabout=newJDialog(this);JMenuBarmenu=newJMenu
8、Bar();//菜单栏的各个菜单项JMenu[]menus=newJMenu[]{newJMenu("文件"),newJMenu("编辑"),newJMenu("关于")};//"文件"菜单项的四个下拉菜单
此文档下载收益归作者所有