欢迎来到天天文库
浏览记录
ID:25979816
大小:263.50 KB
页数:136页
时间:2018-11-24
《经典Java程序源代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、.经典Java程序源代码1.加法器(该java源文件的名称是Adder.java)importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassAdderimplementsActionListener{JFrameAdderFrame;JTextFieldTOprand1;JTextFieldTOprand2;JLabelLAdd,LSum;JButtonBAdd,BClear;JPanelJP1,JP2;publicAdd
2、er(){AdderFrame=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);
3、BClear.addActionListener(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.a
4、dd(JP2);JP2.add(BAdd);JP2.add(BClear);AdderFrame.getContentPane().setLayout(newBorderLayout());AdderFrame.getContentPane().add(JP1,BorderLayout.NORTH);AdderFrame.getContentPane().add(JP2,BorderLayout.SOUTH);....AdderFrame.addWindowListener(newWindowAdapte
5、r(){publicvoidwindowClosing(WindowEventevent){System.exit(0);}});AdderFrame.pack();AdderFrame.setVisible(true);AdderFrame.setResizable(false);AdderFrame.setSize(250,100);}publicvoidactionPerformed(ActionEventevent){doublesum=(double)(Double.valueOf(TOpran
6、d1.getText()).doubleValue()+Double.valueOf(TOprand2.getText()).doubleValue());LSum.setText("="+sum);}publicstaticvoidmain(String[]args){Adderadder=newAdder();}}....2.小型记事本(该java源文件由两个类构成,名称为Notepad.java)importjava.awt.*;importjava.awt.event.*;importjavax.
7、swing.*;importjava.io.*;classmynotepadextendsJFrame{Filefile=null;Colorcolor=Color.red;mynotepad(){initTextContent();initMenu();initAboutDialog();}voidinitTextContent(){getContentPane().add(newJScrollPane(content));}JTextPanecontent=newJTextPane();JFileCh
8、ooseropenfile=newJFileChooser();JColorChooseropencolor=newJColorChooser();....JDialogabout=newJDialog(this);JMenuBarmenu=newJMenuBar();//菜单栏的各个菜单项JMenu[]menus=newJMenu[]{newJMenu("文件"),newJMenu("编辑"),newJMenu("关于")}
此文档下载收益归作者所有