⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datawindow.java

📁 这是一个用java编写的发音电子词典
💻 JAVA
字号:
/* * DataWindow.java * * Created on 2007年12月16日, 下午4:12 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package 电子词典;import java.awt.*;import java.net.*;import java.sql.*;import java.awt.event.*;import javax.swing.*;import java.io.*;/** * * @author baili */public class DataWindow extends JFrame implements ActionListener{        /** Creates a new instance of DataWindow */    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;    public DataWindow() {        super("英汉小词典");               mbar=new JMenuBar();        setJMenuBar(mbar);        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);                medit.add(addedit);        medit.add(modedit);         medit.add(deledit);                mhelp.add(hhelp);        mhelp.add(about);                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();        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);        Container ctnr=getContentPane();        ctnr.add(p1,"North");        ctnr.add(p2,"South");        ctnr.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);            }        });              this.setBounds(250,250, 600,400);        this.setVisible(true);    }    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)         {            new AddWin();        }        else if(e.getSource()==b3||e.getSource()==modedit)        {           new ModifyWin();        }        else if(e.getSource()==b4||e.getSource()==deledit)        {            new 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("F:/java/JavaApplication1/english.mdb");            FileInputStream fis=null;            filedialog_save.setVisible(true);            try            {                fis=new FileInputStream(fromfile);                int bytesTead;                byte[] buf=new byte[4*1024];                File tofile=new File(filedialog_save.getDirectory(), filedialog_save.getFile());                FileOutputStream fos=new FileOutputStream(tofile);                while((bytesTead=fis.read(buf))!=-1)                    fos.write(buf, 0, bytesTead);                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="An Electrical Dictionary 1.0\n\n"+"An application written to show off the function of dictionary.\n\n"+                    "Copyright(c) 2007.";            JOptionPane.showMessageDialog(this,AboutMsg);        }        else if(e.getSource()==hhelp)        {            JFrame 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 ExlCon=DriverManager.getConnection("jdbc:odbc:english;","","");        Statement ExlStmt=ExlCon.createStatement();                if(label.getText().equals("输入要查询的英语单词:"))        {            ResultSet rs=ExlStmt.executeQuery("SELECT *FROM 表1");            while(rs.next())            {                ename=rs.getString("单词");                cname=rs.getString("解释");                if(ename.equals(englishtext.getText()))                    chinesetext.append(cname+"\n");            }            ExlCon.close();            if(chinesetext.getText().equals(""))                 JOptionPane.showMessageDialog(this,"查无此单词!","警告",JOptionPane.WARNING_MESSAGE);        }        else if(label.getText().equals("输入要查询的汉语意思:"))        {            ResultSet rs=ExlStmt.executeQuery("SELECT *FROM 表1 WHERE 解释 LIKE '%"+englishtext.getText()+"%'");            while(rs.next())            {                ename=rs.getString("单词");                cname=rs.getString("解释");                chinesetext.append(ename+"\n");            }            ExlCon.close();            if(chinesetext.getText().equals(""))                 JOptionPane.showMessageDialog(this,"查无此单词!","警告",JOptionPane.WARNING_MESSAGE);        }    }    public static  void main(String[] args)    {        new DataWindow();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -