第十四周课程总结&实验报告(简单记事本的实现)
2019-11-29 11:57 是拾柒啊 阅读(168) 评论(0) 编辑 收藏 举报JDBC驱动程序分为四类:
1)JDBC-ODBC桥驱动;
2)JDBA本地驱动;
3)JDBC网络驱动;
4)本地协议纯JDBC驱动;
JDBC的连接地址实际上是由以下的3个部分组成。
(1)jabc 协议:JDBC URL 中的协议总是 jdbc。
(2)子协议:驱动程序名或数据库连接机制(这种机制可由一个或多个驱动程序支持)的名称,如
MySQL。
(3)子名称: 种标识数据库的方法。必须遵循“//主机名:端口/子协议”的标准URL 命名约定,
如//localhost:3306/mldn
package jishiben;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.*;
public class Textpad implements ActionListener{
JFrame frame;
JTextArea text;
JMenu menu;
File file;
JMenuBar menubar;
JMenuItem newfile;
JMenuItem openfile;
JMenuItem savafile;
JMenuItem exitfile;
JFileChooser choose;
public Textpad() {
frame = new JFrame("记事本");
text = new JTextArea(30,40);
menu = new JMenu("文件");
menubar = new JMenuBar();
newfile = new JMenuItem("新建(N)",new ImageIcon("c:"+ File.separator + "Users" + File.separator + "hyl18" + File.separator + "Desktop" + File.separator + "newfile.jpg"));
openfile = new JMenuItem("打开(O)",new ImageIcon("c:"+ File.separator + "Users" + File.separator + "hyl18" + File.separator + "Desktop" + File.separator + "openfiel.jpg"));
savafile = new JMenuItem("保存(S)",new ImageIcon("c:"+ File.separator + "Users" + File.separator + "hyl18" + File.separator + "Desktop" + File.separator + "closefiel.jpg"));
exitfile = new JMenuItem("退出(E)",new ImageIcon("c:"+ File.separator + "Users" + File.separator + "hyl18" + File.separator + "Desktop" + File.separator + "exitfiel.jpg"));
newfile.setMnemonic('N');
openfile.setMnemonic('O');
savafile.setMnemonic('S');
exitfile.setMnemonic('E');
newfile.setAccelerator(KeyStroke.getKeyStroke('N',java.awt.Event.CTRL_MASK));
openfile.setAccelerator(KeyStroke.getKeyStroke('O',java.awt.Event.CTRL_MASK));
savafile.setAccelerator(KeyStroke.getKeyStroke('S',java.awt.Event.CTRL_MASK));
exitfile.setAccelerator(KeyStroke.getKeyStroke('E',java.awt.Event.CTRL_MASK));
menu.add(newfile);
menu.add(openfile);
menu.add(savafile);
menu.add(exitfile);
menubar.add(menu);
newfile.addActionListener(this);
openfile.addActionListener(this);
savafile.addActionListener(this);
exitfile.addActionListener(this);
frame.setJMenuBar(menubar);
frame.setVisible(true);
frame.setSize(400,300);
frame.setLocation(300, 200);
frame.add(text);
}
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if(obj instanceof JMenuItem) {
JMenuItem item = (JMenuItem)obj;
if(item == newfile) {
new Textpad();
}
else if(item == openfile) {
choose = new JFileChooser();
choose.showOpenDialog(null);
file = choose.getSelectedFile();
try {
FileInputStream fis = new FileInputStream(file);
byte b[] = new byte[fis.available()];
fis.read(b);
fis.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
else if(item == savafile) {
choose = new JFileChooser();
choose.showSaveDialog(null);
}
else if(item == exitfile) {
System.exit(1);
}
}
}
}
public class Jishiben {
public static void main(String args[]) {
new Textpad();
}
}