📄 db_dialog.java
字号:
package psa;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class DB_Dialog extends JDialog {
JPanel panel1 = new JPanel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
GridBagLayout gridBagLayout1 = new GridBagLayout();
public DB_Dialog(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
pack();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
public DB_Dialog() {
this(null, "", false);
}
private void jbInit() throws Exception {
panel1.setLayout(gridBagLayout1);
jButton1.setFont(new java.awt.Font("DialogInput", 0, 12));
jButton1.setText("数据库备份");
jButton1.addActionListener(new DB_Dialog_jButton1_actionAdapter(this));
jButton2.setFont(new java.awt.Font("DialogInput", 0, 12));
jButton2.setText("数据库恢复");
jButton2.addActionListener(new DB_Dialog_jButton2_actionAdapter(this));
jLabel1.setFont(new java.awt.Font("DialogInput", 0, 12));
jLabel1.setText("备份数据库,防止数据丢失");
jLabel2.setFont(new java.awt.Font("DialogInput", 0, 12));
jLabel2.setText("从数据库备份中恢复所有数据,");
jLabel3.setFont(new java.awt.Font("DialogInput", 0, 12));
jLabel3.setOpaque(false);
jLabel3.setText("恢复时会覆盖已有数据,可能会");
jLabel4.setFont(new java.awt.Font("DialogInput", 0, 12));
jLabel4.setText("造成数据丢失,小心使用!");
this.setResizable(false);
this.setTitle("数据库管理");
getContentPane().add(panel1);
panel1.add(jLabel3, new GridBagConstraints(1, 1, 1, 2, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(58, 30, 47, 35), 11, 7));
panel1.add(jButton2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(49, 59, 0, 0), 0, 0));
panel1.add(jLabel2, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(34, 30, 9, 35), 12, 16));
panel1.add(jLabel4, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 30, 32, 70), 0, 0));
panel1.add(jLabel1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(40, 33, 0, 45), 22, 15));
panel1.add(jButton1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(40, 59, 0, 0), 0, 0));
}
void jButton1_actionPerformed(ActionEvent e) {
File fBak = new File(".\\bak\\db.bak");
File fDb = new File(".\\data\\psa.mdb");
FileInputStream fin= null;
FileOutputStream fout = null;
try{
if(!fBak.exists()) fBak.createNewFile();
fin=new FileInputStream(fDb);
fout = new FileOutputStream(fBak);
int r;
while((r = fin.read()) != -1){
fout.write((byte)r);
}
JOptionPane.showMessageDialog(this,"备份成功!","提示",JOptionPane.INFORMATION_MESSAGE);
}catch(Exception ex)
{
JOptionPane.showMessageDialog(this,ex.toString(),"提示",JOptionPane.ERROR_MESSAGE);
}finally
{
try{
if(fin!=null) fin.close();
if(fout!=null) fout.close();
}
catch(Exception ex){}
}
}
void jButton2_actionPerformed(ActionEvent e) {
File fBak = new File(".\\bak\\db.bak");
File fDb = new File(".\\data\\psa.mdb");
FileInputStream fin= null;
FileOutputStream fout = null;
try{
if(!fBak.exists())
{
JOptionPane.showMessageDialog(this, "目前还没有备份!", "提示",
JOptionPane.ERROR_MESSAGE);
return;
}
fin=new FileInputStream(fBak);
fout = new FileOutputStream(fDb);
int r;
while((r = fin.read()) != -1){
fout.write((byte)r);
}
JOptionPane.showMessageDialog(this,"数据库恢复成功!","提示",JOptionPane.INFORMATION_MESSAGE);
}catch(Exception ex)
{
JOptionPane.showMessageDialog(this,ex.toString(),"提示",JOptionPane.ERROR_MESSAGE);
}finally
{
try{
if(fin!=null) fin.close();
if(fout!=null) fout.close();
}
catch(Exception ex){}
}
}
}
class DB_Dialog_jButton1_actionAdapter implements java.awt.event.ActionListener {
DB_Dialog adaptee;
DB_Dialog_jButton1_actionAdapter(DB_Dialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class DB_Dialog_jButton2_actionAdapter implements java.awt.event.ActionListener {
DB_Dialog adaptee;
DB_Dialog_jButton2_actionAdapter(DB_Dialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -