📄 mainframe.java
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.BufferedReader;
import java.io.StringReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.FileReader;
import java.util.Date;
import java.sql.*;
public class MainFrame extends JFrame implements ActionListener
{
private JMenuBar menu=null;
private JMenu file=null;
private JMenuItem revomecon=null;
private JMenuItem open=null;
private JMenuItem insave=null;
private JMenuItem outsave=null;
private JMenuItem exit=null;
private JMenu edit=null;
private JMenuItem cut=null;
private JMenuItem copy=null;
private JMenuItem parse=null;
private JMenuItem all=null;
private JMenuItem clear=null;
private JMenu work=null;
private JMenuItem execute=null;
private JMenu help=null;
private JMenuItem right=null;
JToolBar bar=null;
private JButton btnremovecon=null;
private JButton btnexecute=null;
private JButton btninsave=null;
private JButton btnoutsave=null;
private JButton btnhelp=null;
private JTextArea txtinare=null;
private JTextArea txtoutare=null;
LoginBean log=null;
Conn conn=null;
public MainFrame(LoginBean log,Conn conn)
{
this.log=log;
this.conn=conn;
menu=new JMenuBar();
file=new JMenu("文件(F)");
revomecon=new JMenuItem("改变数据库连接...");
open=new JMenuItem("打开...");
insave=new JMenuItem("将输入另存为...");
outsave=new JMenuItem("将输出另存为...");
exit=new JMenuItem("退出");
revomecon.addActionListener(this);
open.addActionListener(this);
insave.addActionListener(this);
outsave.addActionListener(this);
exit.addActionListener(this);
file.add(revomecon);
file.add(open);
file.add(insave);
file.add(outsave);
file.add(exit);
menu.add(file);
edit=new JMenu("编辑(E)");
cut=new JMenuItem("剪切");
copy=new JMenuItem("复制");
parse=new JMenuItem("粘贴");
all=new JMenuItem("全选");
clear=new JMenuItem("全部清除");
cut.addActionListener(this);
copy.addActionListener(this);
parse.addActionListener(this);
all.addActionListener(this);
clear.addActionListener(this);
edit.add(cut);
edit.add(copy);
edit.add(parse);
edit.add(all);
edit.add(clear);
menu.add(edit);
work=new JMenu("WorkSheet");
execute=new JMenuItem("执行");
execute.addActionListener(this);
work.add(execute);
menu.add(work);
help=new JMenu("帮助(H)");
right=new JMenuItem("关于...");
right.addActionListener(this);
help.add(right);
menu.add(help);
bar=new JToolBar();
btnremovecon=new JButton(new ImageIcon("images/connect.gif"));
btnremovecon.addActionListener(this);
btnexecute=new JButton(new ImageIcon("images/execute.gif"));
btnexecute.addActionListener(this);
btninsave=new JButton(new ImageIcon("images/previous.gif"));
btninsave.addActionListener(this);
btnoutsave=new JButton(new ImageIcon("images/next.gif"));
btnoutsave.addActionListener(this);
btnhelp=new JButton(new ImageIcon("images/help.gif"));
btnhelp.addActionListener(this);
btnremovecon.setBorder(BorderFactory.createRaisedBevelBorder());
btnexecute.setBorder(BorderFactory.createRaisedBevelBorder());
btninsave.setBorder(BorderFactory.createRaisedBevelBorder());
btnoutsave.setBorder(BorderFactory.createRaisedBevelBorder());
btnhelp.setBorder(BorderFactory.createRaisedBevelBorder());
bar.add(btnremovecon);
bar.add(btnexecute);
bar.add(btninsave);
bar.add(btnoutsave);
bar.add(btnhelp);
bar.setBorder(BorderFactory.createLineBorder(Color.darkGray));
txtinare=new JTextArea(60,80);
txtinare.setBorder(BorderFactory.createEtchedBorder());
String pass=log.getUsername()+"/";
for(int i=0;i<log.getPassword().length();i++)
{
pass+="*";
}
txtinare.setText("connect "+pass);
JScrollPane jsp=new JScrollPane(txtinare);
jsp.setBorder(BorderFactory.createTitledBorder("输入窗口"));
jsp.setFont(new Font("楷体",Font.BOLD+Font.CENTER_BASELINE,28));
txtoutare=new JTextArea(60,80);
txtoutare.setBorder(BorderFactory.createEtchedBorder());
java.util.Date date=new Date();
txtoutare.setEditable(false);
String right="\n"+"SQL*Plus:Release 9.2.0.2.0 - Production on "+date;
right+="\n"+"Copyright (C) 1982,2002,Oracle Corporation. All rights reserved.";
right+="\n\n\n"+"已连接";
txtoutare.append(right);
//txtoutare.append("\n"+"已连接");
JScrollPane jsp1=new JScrollPane(txtoutare);
jsp1.setBorder(BorderFactory.createTitledBorder("输出窗口"));
jsp1.setFont(new Font("楷体",Font.BOLD+Font.CENTER_BASELINE,28));
JPanel p9=new JPanel();
p9.setLayout(new GridLayout(2,1));
p9.add(jsp);
p9.add(jsp1);
Container con=this.getContentPane();
con.add(bar,BorderLayout.NORTH);
con.add(p9,BorderLayout.CENTER);
this.setJMenuBar(menu);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(1000,600);
this.setTitle("SQL*Plus Worksheet");
ImageIcon image=new ImageIcon("images/vtw16.gif");
this.setIconImage(image.getImage());
//this.pack();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==exit)
{
System.exit(0);
}
if(e.getSource()==revomecon||e.getSource()==btnremovecon)
{
Login login=new Login(this);
//this.dispose();
}
//保存sql语句
if(e.getSource()==insave||e.getSource()==btninsave)
{
JFileChooser chooser = new JFileChooser(".");
FileFliter fliter=new FileFliter();
//File file=new File(txtinare.getText());
//fliter.accept(file);
chooser.addChoosableFileFilter(fliter);
//设置默认的文件管理器
chooser.setFileFilter(fliter);
int rs = chooser.showSaveDialog(this);
if(rs == JFileChooser.APPROVE_OPTION)
{
try {
BufferedReader br = new BufferedReader(new StringReader(
txtinare.getText()));
BufferedWriter bw = new BufferedWriter(new FileWriter(
chooser.getSelectedFile().getAbsolutePath()));
String line = null;
while ((line = br.readLine()) != null) {
bw.write(line);
bw.newLine();
}
bw.flush();
bw.close();
JOptionPane.showMessageDialog(null,"sql语句保存成功!","提示",JOptionPane.INFORMATION_MESSAGE);
//txtinare.setText("");
} catch (Exception ex) {
System.out.print(ex.getMessage());
}
}
}
//保存输出结果窗口的文本
if(e.getSource()==outsave||e.getSource()==btnoutsave)
{
JFileChooser chooser = new JFileChooser(".");
FileFliter fliter=new FileFliter();
//File file=new File(txtinare.getText());
//fliter.accept(file);
chooser.addChoosableFileFilter(fliter);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -