Java程序源代码.docx
- 文档编号:1938395
- 上传时间:2023-05-02
- 格式:DOCX
- 页数:55
- 大小:24.28KB
Java程序源代码.docx
《Java程序源代码.docx》由会员分享,可在线阅读,更多相关《Java程序源代码.docx(55页珍藏版)》请在冰点文库上搜索。
Java程序源代码
经典Java程序源代码
1.加法器(该java源文件的名称是)
import.*;
import.*;
publicclassAdderimplementsActionListener
{
JFrameAdderFrame;
JTextFieldTOprand1;
JTextFieldTOprand2;
JLabelLAdd,LSum;
JButtonBAdd,BClear;
JPanelJP1,JP2;
publicAdder()
{
AdderFrame=newJFrame("AdderFrame");
TOprand1=newJTextField("");
TOprand2=newJTextField("");
LAdd=newJLabel("+");
LSum=newJLabel("=");
BAdd=newJButton("Add");
BClear=newJButton("Clear");
JP1=newJPanel();
JP2=newJPanel();
(this);
(newActionListener()
{
publicvoidactionPerformed(ActionEventevent)
{
("");
("");
("=");
}
});
(JP1);
(TOprand1);
(LAdd);
(TOprand2);
(LSum);
(JP2);
(BAdd);
(BClear);
().setLayout(newBorderLayout());
().add(JP1,;
().add(JP2,;
(newWindowAdapter()
{
publicvoidwindowClosing(WindowEventevent)
{
(0);
}
});
();
(true);
(false);
(250,100);
}
publicvoidactionPerformed(ActionEventevent)
{
doublesum=(double)()).doubleValue()+()).doubleValue());
("="+sum);
}
publicstaticvoidmain(String[]args)
{
Adderadder=newAdder();
}
}
2.小型记事本(该java源文件由两个类构成,名称为)
import.*;
import.*;
import.*;
classmynotepadextendsJFrame
{
Filefile=null;
Colorcolor=;
mynotepad()
{
initTextContent();
initMenu();
initAboutDialog();
}
voidinitTextContent()
{
getContentPane().add(newJScrollPane(content));
}
JTextPanecontent=newJTextPane();
JFileChooseropenfile=newJFileChooser();
JColorChooseropencolor=newJColorChooser();
JDialogabout=newJDialog(this);
JMenuBarmenu=newJMenuBar();
ength;j++)
{
menus[i].add(optionofmenu[i][j]);
optionofmenu[i][j].addActionListener(action);
}
}
(menu);
}
ActionListeneraction=newActionListener()
{quals(name))
{
("");
file=null;
}
elseif("打开".equals(name))
{
if(file!
=null)
(file);
intreturnVal=;
if(returnVal==
{
file=();
unfold();
}
}
elseif("保存".equals(name))
{
if(file!
=null)(file);
intreturnVal=;
if(returnVal==
{
file=();
saving();
}
}
elseif("退出".equals(name))
{
mynotepadf=newmynotepad();
ints=(f,"退出?
","退出",;
if(s==
(0);
}
elseif("剪切".equals(name))
{
();
}
elseif("复制".equals(name))
{
();
}
elseif("粘贴".equals(name))
{
();
}
elseif("颜色".equals(name))
{
color=,"",color);
(color);
}
elseif("关于".equals(name))
{
(300,150);
();
}
}
};
voidsaving()
{
try
{
FileWriterWritef=newFileWriter(file);
());
();
}
catch(Exceptione)
{
();
}
}
voidunfold()
{
try
{
FileReaderReadf=newFileReader(file);
intlen=(int)();
char[]buffer=newchar[len];
(buffer,0,len);
();
(newString(buffer));
}
catch(Exceptione)
{
();
}
}
voidinitAboutDialog()
{
(newGridLayout(3,1));
().setBackground;
().add(newJLabel("我的记事本程序"));dd(newJLabel("制作者:
Fwx"));
().add(newJLabel("2007年12月"));
(true);;
import.*;
classsimplecalculator
{
staticStringpoint=newString();
staticStringAmal=newString();
staticStringONE=newString();
staticStringTWO=newString();
staticStringTHREE=newString();
staticStringFOUR=newString();
staticStringFIVE=newString();
staticStringSIX=newString();
staticStringSEVEN=newString();
staticStringEIGHT=newString();
staticStringNINE=newString();
staticStringZERO=newString();
staticStringResultState=newString();
staticDoubleQF;
staticJButtonzero=newJButton("0");
staticJButtonone=newJButton("1");
staticJButtontwo=newJButton("2");
staticJButtonthree=newJButton("3");
staticJButtonfour=newJButton("4");
staticJButtonfive=newJButton("5");
staticJButtonsix=newJButton("6");
staticJButtonseven=newJButton("7");
staticJButtoneight=newJButton("8");
staticJButtonnine=newJButton("9");
staticJButtonadd=newJButton("+");
staticJButtonsub=newJButton("-");
staticJButtonmul=newJButton("*");
staticJButtondiv=newJButton("/");
staticJButtonQuFan=newJButton("+/-");
staticJButtonDian=newJButton(".");
staticJButtonequal=newJButton("=");
staticJButtonclear=newJButton("C");
staticJButtonBaiFen=newJButton("%");
staticJButtonFenZhiYi=newJButton("1/x");
staticinti=0;
staticDoubleaddNumber;
staticDoublesubNumber;
staticDoublemulNumber;
staticDoubledivNumber;
staticDoubleequalNumber;
staticDoubletemp;
staticJTextArearesult=newJTextArea(1,20);
publicstaticvoidmain(String[]args)
{
JFrameframe=newJFrame("计算器");
(false);
("");
ResultState="窗口空";
JPanelForResult=newJPanel();
JPanelForButton7_clear=newJPanel();
JPanelForButton4_mul=newJPanel();
JPanelForButton1_sub=newJPanel();
JPanelForButton0_equal=newJPanel();
FlowLayoutFLO=newFlowLayout();
(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);
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
("");
ZERO="";
ONE="";
TWO="";
THREE="";
FOUR="";
FIVE="";
SIX="";
SEVEN="";
EIGHT="";
NINE="";
ResultState="窗口空";
point="";
i=0;
}
});
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
ZERO="已经点击";
ResultState="窗口不为空";
if(ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FOUR=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击")
{
("0");
}
if(ResultState=="窗口空")
{
("0");
}
}
});
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
ONE="已经点击";
ResultState="窗口不为空";
if(point=="已经点击"||ZERO!
="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!
="0")
{
("1");
}
if(ResultState=="窗口空")
{
("1");
}
}
});
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
TWO="已经点击";
ResultState="窗口不为空";
if(point=="已经点击"||ZERO!
="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!
="0")
{
("2");
}
if(ResultState=="窗口空")
{
("2");
}
}
});
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
THREE="已经点击";
ResultState="窗口不为空";
if(point=="已经点击"||ZERO!
="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!
="0")
{
("3");
}
if(ResultState=="窗口空")
{
("3");
}
}
});
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
FOUR="已经点击";
ResultState="窗口不为空";
if(point=="已经点击"||ZERO!
="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!
="0")
{
("4");
}
if(ResultState=="窗口空")
{
("4");
}
}
});
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
FIVE="已经点击";
ResultState="窗口不为空";
if(point=="已经点击"||ZERO!
="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!
="0")
{
("5");
}
if(ResultState=="窗口空")
{
("6");
}
}
});
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
SIX="已经点击";
ResultState="窗口不为空";
if(point=="已经点击"||ZERO!
="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!
="0")
{
("6");
}
if(ResultState=="窗口空")
{
("6");
}
}
});
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
SEVEN="已经点击";
ResultState="窗口不为空";
if(point=="已经点击"||ZERO!
="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!
="0")
{
("7");
}
if(ResultState=="窗口空")
{
("7");
}
}
});
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
EIGHT="已经点击";
ResultState="窗口不为空";
if(point=="已经点击"||ZERO!
="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!
="0")
{
("8");
}
if(ResultState=="窗口空")
{
("8");
}
}
});
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
NINE="已经点击";
ResultState="窗口不为空";
if(point=="已经点击"||ZERO!
="已经点击"||ONE=="已经点击"||TWO=="已经点击"||THREE=="已经点击"||FIVE=="已经点击"||SIX=="已经点击"||SEVEN=="已经点击"||EIGHT=="已经点击"||NINE=="已经点击"&&()!
="0")
{
("9");
}
if(ResultState=="窗口空")
{
("9");
}
}
});
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
point="已经点击";
i=i+1;
if(ResultState=="窗口不为空"&&i==1)
{
(".");
}
}
});
(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
Amal="已经选择加号";
addNumber=
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 程序 源代码
![提示](https://static.bingdoc.com/images/bang_tan.gif)