java 电子词典10版

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

自己写的小词典MainJFram.javaimportjava.awt.Color;importjava.awt.Graphics;importjava.awt.Image;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.GroupLayout;importjavax.swing.ImageIcon;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JMenu;importjavax.swing.JMenuBar;importjavax.swing.JMenuItem;importjavax.swing.JOptionPane;importjavax.swing.JScrollPane;importjavax.swing.JTextField;importjavax.swing.JTextPane;importjavax.swing.LayoutStyle;importjavax.swing.SwingUtilities;importjavax.swing.WindowConstants;/***Createdon2012-4-4,8:41:06*@authoryanghaiifeng*/publicclassMainJFrameextendsJFrame{privatestaticfinallongserialVersionUID=1L;privateJMenuBarjMenuBar1;privateJMenuItemaboutJMenuItem;privateJMenuItemcToEJMenuItem;privateJMenuItemeToCjMenuItem;privateJMenudictionJMenu;privateJMenuhelp;privateJLabelsearchJLabel1;privateJScrollPanejScrollPane1;staticJTextPaneresultJTextPane1;staticJTextFieldwordJTextField;privateJButtonsearch;privateImageIconimageIcon;/**CreatesnewformMainJFrame*/publicMainJFrame(){super(MiniDictionary);initComponents();}//构造函数初始化窗口privatevoidinitComponents(){searchJLabel1=newJLabel();search=newJButton();wordJTextField=newJTextField();jScrollPane1=newJScrollPane();jMenuBar1=newJMenuBar();dictionJMenu=newJMenu();eToCjMenuItem=newJMenuItem();cToEJMenuItem=newJMenuItem();help=newJMenu();aboutJMenuItem=newJMenuItem();//设置resultJTextPanel的背景Stringurl=E:\\workspace\\bk.jpg;imageIcon=newImageIcon(url);resultJTextPane1=newJTextPane(){Imageimage=imageIcon.getImage();{setOpaque(false);}@OverridepublicvoidpaintComponent(Graphicsg){g.drawImage(image,0,0,this);super.paintComponent(g);}};setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);searchJLabel1.setForeground(newColor(255,51,51));searchJLabel1.setText(Inputsomewords:);search.setText(search);resultJTextPane1.setEditable(false);jScrollPane1.setViewportView(resultJTextPane1);dictionJMenu.setText(词典);eToCjMenuItem.setText(英译汉);eToCjMenuItem.addActionListener(newActionListener(){//选择英译汉publicvoidactionPerformed(ActionEvente){search.setText(search);searchJLabel1.setText(Inputsomewords:);wordJTextField.setText();resultJTextPane1.setText();}});cToEJMenuItem.addActionListener(newActionListener(){//选择汉译英publicvoidactionPerformed(ActionEvente){searchJLabel1.setText(请输入字词:);search.setText(查询);wordJTextField.setText();resultJTextPane1.setText();}});aboutJMenuItem.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){//显示对话框JOptionPane.showOptionDialog(null,MiniDictionary+\n+杨海峰,英汉互译,JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null,null,null);}});search.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){resultJTextPane1.setText();if((Inputsomewords:).equals(searchJLabel1.getText().trim())){OperateUtils.searchWord();if(OperateUtils.searchWord()==false){JOptionPane.showOptionDialog(search,查询失败,出错了,JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null,null,null);}}elseif((请输入字词:).equals(searchJLabel1.getText().trim())){OperateUtils.searchChinese();if(OperateUtils.searchChinese()==false){JOptionPane.showOptionDialog(search,查询失败,出错了,JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null,null,null);}}}});//添加组件dictionJMenu.add(eToCjMenuItem);cToEJMenuItem.setText(汉译英);dictionJMenu.add(cToEJMenuItem);jMenuBar1.add(dictionJMenu);help.setText(帮助);aboutJMenuItem.setText(关于);help.add(aboutJMenuItem);jMenuBar1.add(help);setJMenuBar(jMenuBar1);//布局设置GroupLayoutlayout=newGroupLayout(getContentPane());getContentPane().setLayout(layout);layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(searchJLabel1,GroupLayout.PREFERRED_SIZE,108,GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(wordJTextField,GroupLayout.DEFAULT_SIZE,199,Short.MAX_VALUE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(search,GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE,Short.MAX_VALUE).addContainerGap()).addComponent(jScrollPane1,GroupLayout.DEFAULT_SIZE,384,Short.MAX_VALUE));layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(30,30,30).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(wordJTextField,GroupLayout.DEFAULT_SIZE,29,Short.MAX_VALUE).addComponent(searchJLabel1,GroupLayout.DEFAULT_SIZE,29,Short.MAX_VALUE).addComponent(search)).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jScrollPane1,GroupLayout.DEFAULT_SIZE,238,Short.MAX_VALUE).addContainerGap()));setLocation(300,200);pack();}publicstaticvoidmain(Stringargs[]){SwingUtilities.invokeLater(newRunnable(){publicvoidrun(){newMainJFrame().setVisible(true);}});}}//工具类OperateUtils.javaimportjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statem

1 / 7
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功