Java程序源代码Word文档下载推荐.docx
- 文档编号:20299054
- 上传时间:2023-01-21
- 格式:DOCX
- 页数:104
- 大小:47.37KB
Java程序源代码Word文档下载推荐.docx
《Java程序源代码Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《Java程序源代码Word文档下载推荐.docx(104页珍藏版)》请在冰豆网上搜索。
TOprand1.setText("
TOprand2.setText("
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.getContentPane().setLayout(newBorderLayout());
AdderFrame.getContentPane().add(JP1,BorderLayout.NORTH);
AdderFrame.getContentPane().add(JP2,BorderLayout.SOUTH);
AdderFrame.addWindowListener(newWindowAdapter()
publicvoidwindowClosing(WindowEventevent)
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.getText()).doubleValue());
LSum.setText("
+sum);
publicstaticvoidmain(String[]args)
Adderadder=newAdder();
}
2.小型记事本(该java源文件由两个类构成,名称为Notepad.java)
importjava.io.*;
classmynotepadextendsJFrame
Filefile=null;
Colorcolor=Color.red;
mynotepad()
initTextContent();
initMenu();
initAboutDialog();
}
voidinitTextContent()
getContentPane().add(newJScrollPane(content));
JTextPanecontent=newJTextPane();
JFileChooseropenfile=newJFileChooser();
JColorChooseropencolor=newJColorChooser();
JDialogabout=newJDialog(this);
JMenuBarmenu=newJMenuBar();
//菜单栏的各个菜单项
JMenu[]menus=newJMenu[]{newJMenu("
文件"
),newJMenu("
编辑"
关于"
)};
//"
菜单项的四个下拉菜单
//编辑菜单的四个下拉菜单
JMenuItemoptionofmenu[][]=newJMenuItem[][]{{newJMenuItem("
新建"
),newJMenuItem("
打开"
保存"
退出"
)},
{newJMenuItem("
复制"
剪切"
粘贴"
颜色"
{newJMenuItem("
)}
};
voidinitMenu()
for(inti=0;
i<
menus.length;
i++)
menu.add(menus[i]);
for(intj=0;
j<
optionofmenu[i].length;
j++)
menus[i].add(optionofmenu[i][j]);
optionofmenu[i][j].addActionListener(action);
this.setJMenuBar(menu);
}
ActionListeneraction=newActionListener()
{//添加事件监听
publicvoidactionPerformed(ActionEvente)
Stringname=e.getActionCommand();
JMenuItemMI=(JMenuItem)e.getSource();
if("
.equals(name))
content.setText("
"
file=null;
elseif("
if(file!
=null)
openfile.setSelectedFile(file);
intreturnVal=openfile.showOpenDialog(mynotepad.this);
if(returnVal==JFileChooser.APPROVE_OPTION)
file=openfile.getSelectedFile();
unfold();
elseif("
if(file!
=null)openfile.setSelectedFile(file);
intreturnVal=openfile.showSaveDialog(mynotepad.this);
file=openfile.getSelectedFile();
saving();
elseif("
mynotepadf=newmynotepad();
ints=JOptionPane.showConfirmDialog(f,"
退出?
"
JOptionPane.YES_NO_OPTION);
if(s==JOptionPane.YES_OPTION)
System.exit(0);
content.cut();
{
content.copy();
content.paste();
color=JColorChooser.showDialog(mynotepad.this,"
color);
content.setForeground(color);
about.setSize(300,150);
about.show();
}
};
voidsaving()
try
FileWriterWritef=newFileWriter(file);
Writef.write(content.getText());
Writef.close();
catch(Exceptione)
e.printStackTrace();
voidunfold()
FileReaderReadf=newFileReader(file);
intlen=(int)file.length();
char[]buffer=newchar[len];
Readf.read(buffer,0,len);
Readf.close();
content.setText(newString(buffer));
catch(Exceptione)
e.printStackTrace();
voidinitAboutDialog()
about.setLayout(newGridLayout(3,1));
about.getContentPane().setBackground(Color.white);
about.getContentPane().add(newJLabel("
我的记事本程序"
));
//对话框内容
制作者:
Fwx"
2007年12月"
about.setModal(true);
//设置对话框前端显示
about.setSize(100,100);
about.setLocation(250,170);
//设置对话框显示位置
};
}
publicclassNotepad
publicstaticvoidmain(Stringargs[])
{//入口main函数
mynotepadnoted=newmynotepad();
noted.addWindowListener(newWindowAdapter()
});
noted.setTitle("
//记事本标题
noted.setSize(640,320);
//设置记事本大小
noted.show();
noted.setLocation(150,100);
//设置记事本显示位置
3.简单计算器(该java源文件的名称是simplecalculator.java)
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);
JFrameframe=newJFrame("
计算器"
result.setEditable(false);
result.setText("
ResultState="
窗口空"
;
JPanelForResult=newJPanel();
JPanelForButton7_clear=newJPanel();
JPanelForButton4_mul=newJPanel();
JPanelForButton1_sub=newJPanel();
JPanelForButton0_equal=newJPanel();
FlowLayoutFLO=newFlowLayout();
ForResult.add(result);
ForButton7_clear.setLayout(FLO);
ForButton7_clear.add(seven);
ForButton7_clear.add(eight);
ForButton7_clear.add(nine);
ForButton7_clear.add(div);
ForButton7_clear.add(clear);
ForButton4_mul.setLayout(FLO);
ForButton4_mul.add(four);
ForButton4_mul.add(five);
ForButton4_mul.add(six);
ForButton4_mul.add(mul);
ForButton4_mul.add(BaiFen);
ForButton1_sub.setLayout(FLO);
ForButton1_sub.add(one);
ForButton1_sub.add(two);
ForButton1_sub.add(three);
ForButton1_sub.add(sub);
ForButton1_sub.add(FenZhiYi);
ForButton0_equal.setLayout(FLO);
ForButton0_equal.add(zero);
ForButton0_equal.add(QuFan);
ForButton0_equal.add(Dian);
ForButton0_equal.add(add);
ForButton0_equal.add(equal);
frame.getContentPane().setLayout(FLO);
frame.getContentPane().add(ForResult);
frame.getContentPane().add(ForButton7_clear);
frame.getContentPane().add(ForButton4_mul);
frame.getContentPane().add(ForButton1_sub);
frame.getContentPane().add(ForButton0_equal);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setBounds(250,250,245,245);
frame.setResizable(false);
frame.setVisible(true);
clear.addActionListener(newActionListener()
result.setText("
ZERO="
ONE="
TWO="
THREE="
FOUR="
FIVE="
SIX="
SEVEN="
EIGHT="
NINE="
ResultState="
point="
i=0;
zero.addActionListener(newActionListener()
publicvoidactionPerformed(ActionEvente)
ZERO="
已经点击"
ResultState="
窗口不为空"
if(ONE=="
||TWO=="
||THREE=="
||FOUR=="
||FIVE=="
||SIX=="
||SEVEN=="
||EIGHT=="
||NINE=="
)
{
result.append("
}
if(ResultState=="
result.setText("
one.addActionListener(newActionListener()
ONE="
if(point=="
||ZERO!
||ONE=="
&
result.getText()!
two.addActionListener(newActionListener()
TWO="
窗口不为空
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 程序 源代码