经典Java程序源代码
- 格式:doc
- 大小:395.00 KB
- 文档页数:58
经典Java程序源代码(总57页)
本页仅作为文档封面,使用时可以删除
This document is for reference only-rar21year.March 经典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();