欢迎来到天天文库
浏览记录
ID:26312014
大小:262.50 KB
页数:136页
时间:2018-11-25
《[精品]经典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(){Adder
2、Frame=newJFrame("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.addActionListene
3、r(newActionListener(){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(BCl
4、ear);AdderFrame.getContentPane().setLayout(newBorderLayout());AdderFrame.getContentPane().add(JP1,BorderLayout.NORTH);AdderFrame.getContentPane().add(JP2,BorderLayout.SOUTH);.AdderFrame.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEventevent){
5、System.exit(0);}});AdderFrame.pack();AdderFrame.setVisible(true);AdderFrame.setResizable(false);AdderFrame.setSize(250,100);}publicvoidactionPerformed(ActionEventevent){doublesum=(double)(Double.valueOf(TOprand1.getText()).doubleValue()+Double.valueOf(TOprand2.getT
6、ext()).doubleValue());LSum.setText("="+sum);}publicstaticvoidmain(String[]args){Adderadder=newAdder();}}.2.小型记事本(该java源文件由两个类构成,名称为Notepad.java)importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjava.io.*;classmynotepadextendsJFrame{Filefile=null;Col
7、orcolor=Color.red;mynotepad(){initTextContent();initMenu();initAboutDialog();}voidinitTextContent(){getContentPane().add(newJScrollPane(content));}JTextPanecontent=newJTextPane();JFileChooseropenfile=newJFileChooser();JColorChooseropencolor=newJColorChooser();.JDia
8、logabout=newJDialog(this);JMenuBarmenu=newJMenuBar();//菜单栏的各个菜单项JMenu[]menus=newJMenu[]{newJMenu("文件"),newJMenu("编辑"),newJMenu("关于")};//"文件"菜单项的四
此文档下载收益归作者所有