import java.awt.*;
import java.net.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import sun.audio.*;
import javax.swing.JOptionPane;
class DataWindow extends JFrame implements ActionListener
{
JFrame topFrame;
JDesktopPane desktop;
FileDialog filedialog_save; //声明文件对话框
JTextField englishtext;
JTextArea chinesetext;
JButton b1,b2,b3,b4,b5;
JLabel label;
JMenuBar mbar;
JMenu mfile,medit,mhelp;
JMenuItem edic,cdic,back_data,quit,addedit,modedit,deledit,hhelp,about;
DataWindow()
{
super("英汉小词典");
this.setBounds(250,250,600,400);
this.setVisible(true);
getContentPane().add(new JScrollPane(chinesetext));
mbar = new JMenuBar();
setJMenuBar(mbar);
mbar.setOpaque(true);
mfile = new JMenu("文件");
medit = new JMenu("编辑");
mhelp = new JMenu("帮助");
mbar.add(mfile);mbar.add(medit);mbar.add(mhelp);
edic = new JMenuItem("英汉词典");
cdic = new JMenuItem("汉英词典");
back_data = new JMenuItem("备份词库");
quit = new JMenuItem(" 退出");//文件菜单
addedit = new JMenuItem("添加词汇");
modedit = new JMenuItem("修改词汇");
deledit = new JMenuItem("删除词汇");//编辑菜单
hhelp = new JMenuItem("帮助");
about = new JMenuItem("关于...");//帮助菜单
mfile.add(edic);
mfile.add(cdic);
mfile.add(back_data);
mfile.addSeparator();
mfile.add(quit); //mfile
medit.add(addedit);
medit.add(modedit);
medit.add(deledit); //medit
mhelp.add(hhelp);
mhelp.add(about); //mhelp
edic.addActionListener(this);
cdic.addActionListener(this);
quit.addActionListener(this);
addedit.addActionListener(this);
modedit.addActionListener(this);
deledit.addActionListener(this);
hhelp.addActionListener(this);
about.addActionListener(this);
englishtext = new JTextField(16);
englishtext.setFont(new Font("",15,15));
chinesetext = new JTextArea(8,15);
chinesetext.setEditable(false);
chinesetext.setFont(new Font("",25,25));
b1 = new JButton("查询");
b2 = new JButton("添加");
b3 = new JButton("修改");
b4 = new JButton("刪除");
b5 = new JButton("发音");
JPanel p1 = new JPanel(),p2 = new JPanel();//添加面板
label = new JLabel("输入要查询的英语单词:");
label.setFont(new Font("隶书",20,20));
p1.add(label);
p1.add(englishtext);p1.add(b1);p1.add(b5);
p2.add(b2);p2.add(b3);p2.add(b4);
this.add(p1,"North");
this.add(p2,"South");
this.add(new JScrollPane(chinesetext),"Center");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
englishtext.addActionListener(this);
back_data.addActionListener(this);
filedialog_save = new FileDialog(this,"保存文件对话框",FileDialog.SAVE);
filedialog_save.addWindowListener(new WindowAdapter() //对话框增加适配器
{
public void windowClosing(WindowEvent e)
{
filedialog_save.setVisible(false);
}
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ System.exit(0); }
});
}
public void actionPerformed(ActionEvent e) //实现按钮监听
{
if(e.getSource()==b1||e.getSource()==englishtext)
{
chinesetext.setText("");
if(englishtext.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"查询对象不能为空!","警告",
JOptionPane.WARNING_MESSAGE);
}
else{
try{ Listwords(); }
catch(SQLException ee){ }
}
}
else if(e.getSource()==b2||e.getSource()==addedit)
{
AddWin add = new AddWin(); //AddWin是添加窗口的类
}
else if(e.getSource()==b3||e.getSource()==modedit)
{
ModifyWin modi = new ModifyWin(); //ModifyWin是修改窗口的类
}
else if(e.getSource()==b4||e.getSource()==deledit)
{
DelWin del = new DelWin(); //DelWin是删除窗口的类
}
else if(e.getSource()==b5)//发音
{
if(englishtext.getText()!=null)
{
try
{
InputStream is=getClass().getResource("sound//"+
englishtext.getText().trim()+".wav").openStream();
AudioPlayer.player.start(is);
}
catch(IOException e1){ }
}
}
else if(e.getSource()==edic) //英汉
{
label.setText("输入要查询的英语单词:");
b1.setVisible(true);
b5.setVisible(true);
}
else if(e.getSource()==cdic) //汉英
{
label.setText("输入要查询的汉语意思:");
b1.setVisible(true);
b5.setVisible(true);
}
else if(e.getSource()==back_data) //备份
{
File fromfile = new File("english\\english.mdb");
FileInputStream fis = null;
filedialog_save.setVisible(true);
try{
fis = new FileInputStream(fromfile);
int bytesRead; //定义变量来存储输入流中读取出来的文件
byte[] buf = new byte[4*1024]; //4K buffer
File tofile = new File(filedialog_save.getDirectory(),filedialog_save.getFile());
FileOutputStream fos = new FileOutputStream(tofile);
while((bytesRead = fis.read(buf))!=-1)
{
fos.write(buf,0,bytesRead);
}
fos.flush();
fos.close();
fis.close();
}
catch(IOException e2){ }
}
else if(e.getSource()==quit) //退出
{
System.exit(0);
}
else if(e.getSource()==about) //关于
{
final String AboutMsg = "A Electrical Dictionary 1.0 \n \n"
+"An application written to show off the function of dictionary.\n \n"
+"Written By Edith.\n \n"
+"Copyright (c) 2005 by Edith.All rights Reserved.";
JOptionPane.showMessageDialog(topFrame,AboutMsg);
}
else if(e.getSource()==hhelp) //帮助
{
HelpFrame help = new HelpFrame();
help.setVisible(true);
}
}
public void Listwords() throws SQLException //实现查询功能
{
String cname,ename;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
//建立桥接器
Connection Ex1Con = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=english\\english.mdb","","");
Statement Ex1Stmt = Ex1Con.createStatement();
if(label.getText().equals("输入要查询的英语单词:"))
{
ResultSet rs = Ex1Stmt.executeQuery("SELECT * FROM 表1");
while( rs.next())
{
ename = rs.getString("单词");
cname = rs.getString("解释");
if(ename.equals(englishtext.getText()))
{
chinesetext.append(cname+'\n');
}
}
Ex1Con.close(); //关闭数据库
if(chinesetext.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"查无此单词!","警告",
JOptionPane.WARNING_MESSAGE);
}
}
else if(label.getText().equals("输入要查询的汉语意思:"))
{
ResultSet rs=Ex1Stmt.executeQuery("SELECT * FROM 表1 WHERE 解释 LIKE '%"+englishtext.getText()+"%'");
while(rs.next())
{
ename = rs.getString("单词");
cname = rs.getString("解释");
chinesetext.append(ename+'\n');
}
Ex1Con.close(); //关闭数据库
if(chinesetext.getText().equals(""))
{
JOptionPane.showMessageDialog(this,"查无此单词!","警告",
JOptionPane.WARNING_MESSAGE);
}
}
} // end of Liststudent()
}
public class Dic
{
public static void main(String args[])
{
JFrame.setDefaultLookAndFeelDecorated(true);
DataWindow window = new DataWindow();
window.validate();
// AddWin add = new AddWin();
}
public void add()
{
}
}
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
qqzhal
- 粉丝: 17
- 资源: 39
最新资源
- 扒网站数据软件项目全套技术资料100%好用.zip
- 超智能体写的人工智能深度学习pdf
- 西门子840D HMI ADVANCED FOR PC 也可用于810D,840DSL中文版 1、软件可安装到台式机或笔记本上,可以连接到机床的NCU进行NC与PLC的数据备份与恢复,备份和恢复的数
- MATLAB代码:基于分布式ADMM算法的考虑碳排放交易的电力系统优化调度研究 关键词:分布式调度 ADMM算法 交替方向乘子法 碳排放 最优潮流 仿真平台:MATLAB+CPLEX GUROBI
- 基于二阶自抗扰ADRC的轨迹跟踪控制,对车辆的不确定性和外界干扰具有一定抗干扰性,基于carsim和simulink仿真 跟踪轨迹为双移线,效果良好,有对应复现资料,是学习自抗扰技术快速入门很好的资料
- 程序名称:转向设计计算程序 开发平台:基于matlab平台 计算内容:阿克曼转角,转弯半径,转向阻力矩,回正力矩,转向主参数,转向传动比,力矩波动,转向梯形,EPS匹配,HPS匹配,齿轮齿条传动比,循
- 基于python的网页自动化工具项目全套技术资料100%好用.zip
- MATLAB【逆变器二次调频模型】 微电网分布式电源逆变器DROOP控制二次调频模型,加入二次控制实现二次调频控制,及二次调压控制,程序可实现上图功能,工况有所改变 需要matlab2021A版
- 抢购软件:快速复制信息
- 纯电动汽车再生制动策略,Cruise和Simulink联合仿真,提供Cruise整车模型和simuink策略模型,有详细解析文档,可运行
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页