|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
用java开发web只要两本书:一本是关于java基础的,一本是关于jsp、servlet的就可以了。开发周期长,我就来讲句题外话,现在有很多思想都是通过java来展现。学了JAVA一个月.就写了个NotePad.因为工夫干系.要实训了,良多功效没加上往,只完成了复杂的界面和最基础上的功效.
今后偶然间再完美吧..
=================================================================================
/*猫猫..第一个Java程序
*
*
*copyright猫猫
*/
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjavax.swing.event.*;
importjava.io.*;
publicclassNotepadextendsJFrame
{
StringopenFilePath;
StringopenFileName;
Stringtitle="ERRORMESSAGE";
inttype=JOptionPane.ERROR_MESSAGE;
publicNotepad()
{
super("记事本");
finalJTextAreatext=newJTextArea();
text.setToolTipText("请键进内容");
//界面
//加入事务
this.addWindowListener(newWindowAdapter()
{
publicvoidwindowClosing(WindowEvente)
{
System.exit(0);
}
});
//复杂的结构
finalJPanelpanel=newJPanel();
panel.setLayout(newGridLayout(1,1));
panel.add(newJScrollPane(text));
this.getContentPane().add(panel);
//菜单项
JMenuBarMbar=newJMenuBar();
this.setJMenuBar(Mbar);
JMenufile=newJMenu("文件");
JMenuedit=newJMenu("编纂");
JMenuhelp=newJMenu("匡助");
Mbar.add(file);
Mbar.add(edit);
Mbar.add(help);
JMenuItemnewFile=newJMenuItem("新建");
newFile.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
text.setText("");
}
});
//结构停止
//新建文件
newFile.setMnemonic(N);
newFile.setAccelerator(KeyStroke.getKeyStroke(N,java.awt.Event.CTRL_MASK,true));
//翻开文件
JMenuItemopen=newJMenuItem("翻开");
open.setMnemonic(O);
open.setAccelerator(KeyStroke.getKeyStroke(O,java.awt.Event.CTRL_MASK,true));
open.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
JFileChooseropenfile=newJFileChooser();
openfile.setDialogTitle("翻开文件");
openfile.setApproveButtonText("翻开");
openfile.showOpenDialog(panel);
Filefilename=openfile.getSelectedFile();
StringBufferstrBF=newStringBuffer();
Stringerror_message="Error";
FileInputStreaminputfile=null;
try{
charbuffer[]=newchar[1024];
inputfile=newFileInputStream(filename);
intlen=0;
FileReaderin=newFileReader(filename.getAbsoluteFile());
while((len=in.read(buffer))!=-1)
{
strBF.append(buffer,0,len);
}
inputfile.close();
text.setText(strBF.toString());
Stringopenfilename=filename.getName();
setTitle(openfilename);
}
catch(IOExceptionioEX)
{
JOptionPane.showMessageDialog(panel,error_message,title,type);
}
}});
//保留文件
JMenuItemsave=newJMenuItem("保留");
save.setMnemonic(S);
save.setAccelerator(KeyStroke.getKeyStroke(S,java.awt.Event.CTRL_MASK,true));
save.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
JFileChoosersavefile=newJFileChooser();
savefile.setApproveButtonText("保留");
savefile.setDialogTitle("保留文件");
savefile.showSaveDialog(panel);
Filefilesa=savefile.getSelectedFile();
Stringfile_notfound_message="找不到文件";
FileOutputStreamoutputfile=null;
//处置非常入手下手
try
{
outputfile=newFileOutputStream(filesa);
}
catch(FileNotFoundExceptionfe)
{
JOptionPane.showMessageDialog(panel,file_notfound_message,title,type);
}
Stringfilecontent=text.getText();
Stringwrite_error_message="写文件毛病";
try
{
outputfile.write(filecontent.getBytes());
}
catch(IOExceptionioEx)
{
JOptionPane.showMessageDialog(panel,write_error_message,title,type);
}
Stringcmessage="封闭毛病";
try
{
outputfile.close();
}
catch(IOExceptionioEx)
{
JOptionPane.showMessageDialog(panel,cmessage,title,type);
}
}
}
);
//加入
JMenuItemexit=newJMenuItem("加入");
exit.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
System.exit(0);
}
});
exit.setMnemonic(Q);
exit.setAccelerator(KeyStroke.getKeyStroke(Q,java.awt.Event.CTRL_MASK,true));
//查找
JMenuItemfind=newJMenuItem("查找");
find.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
//由于课程太紧.以是查找功效没工夫加上往了.^_^
}
});
find.setMnemonic(F);
find.setAccelerator(KeyStroke.getKeyStroke(F,java.awt.Event.CTRL_MASK,true));
//剪切
JMenuItemcut=newJMenuItem("剪切");
cut.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
text.cut();
}
});
cut.setMnemonic(C);
cut.setAccelerator(KeyStroke.getKeyStroke(C,java.awt.Event.CTRL_MASK,true));
//复制
JMenuItemcopy=newJMenuItem("复制");
copy.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
text.copy();
}
});
copy.setMnemonic(o);
copy.setAccelerator(KeyStroke.getKeyStroke(O,java.awt.Event.CTRL_MASK,true));
//粘贴
JMenuItempaste=newJMenuItem("粘贴");
paste.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
text.paste();
}});
paste.setMnemonic(P);
paste.setAccelerator(KeyStroke.getKeyStroke(P,java.awt.Event.CTRL_MASK,true));
JMenuItemabout=newJMenuItem("关于");
about.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEvente){
inttype=JOptionPane.INFORMATION_MESSAGE;
Stringtitle="关于";
Stringmessage="Makebycatlee";
JOptionPane.showMessageDialog(panel,message,title,type);
}});
file.add(newFile);
file.add(open);
file.add(save);
file.addSeparator();
file.add(exit);
edit.add(cut);
edit.add(copy);
edit.add(paste);
edit.add(find);
help.add(about);
}
publicstaticvoidmain(String[]args){
Notepadnotepad=newNotepad();
notepad.setSize(640,480);
notepad.setVisible(true);
notepad.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
大型的应用一般不会用这些框架(因为性能考虑);开发人员根据需要选择用一些框架,也可以不选用框架;不用框架并不代表要自己写框架;修改框架的可能性更小。 |
|