?? frame.java
字號:
StringTokenizer f2=new StringTokenizer(s1,"\\"); String ff=null; while(f2.hasMoreTokens()) { ff=f2.nextToken(); } diclabel.setText("當前詞庫:"+ff); index=new RandomAccessFile(file.toString(),"r"); int i=file.lastIndexOf("."); file.insert(i,"word"); words=new RandomAccessFile(file.toString(),"r"); file.replace(i,i+4,"trans"); trans=new RandomAccessFile(file.toString(),"r");// String s4="."+System.getProperty("file.separator")+"longindex.asm";// String s5="."+System.getProperty("file.separator")+"index2.asm"; // longindex=new RandomAccessFile(s4,"r");// index2=new RandomAccessFile(s5,"r");// LongIndexBasic basic=new LongIndexBasic(); // basic.longindex2=longindex;// basic.getLongIndex(); indexin.getindex(index);}catch(FileNotFoundException e){ System.out.println("File Not Found"+e);} } private void jbInit() throws Exception { String s1="."+System.getProperty("file.separator")+"default.dic"; loadfile(s1); s1="."+System.getProperty("file.separator")+"user.dat"; users=new RandomAccessFile(s1,"rw"); s1="."+System.getProperty("file.separator")+"usertrans.dat"; usertrans=new RandomAccessFile(s1,"rw"); userwords.getindex(users); // ImageIcon m_ico=new ImageIcon(".\\menu.ico"); contentPane = (JPanel) this.getContentPane(); //contentPane.setSize(1024,768); InputField.setBackground(new Color(245, 251, 255)); InputField.setForeground(Color.blue); InputField.setSelectionColor(SystemColor.windowText); InputField.setBounds(new Rectangle(139, 37, 421, 22)); InputField.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(CaretEvent e) { InputField_caretUpdate(e); } }); InputField.addKeyListener(this); icon=getToolkit().getImage("ico.gif"); ImageIcon img2=new ImageIcon("ico2.gif"); ImageIcon img3=new ImageIcon(".\\ico3\\ico3sta.jpg"); Mico1.setIcon(img2); Animate.setIcon(img3); this.setIconImage(icon); InputField.addInputMethodListener(new java.awt.event.InputMethodListener() { public void inputMethodTextChanged(InputMethodEvent e) { InputField_inputMethodTextChanged(e); } public void caretPositionChanged(InputMethodEvent e) { } }); this.setDefaultCloseOperation(3); this.setResizable(false); this.setSize(new Dimension(635, 508)); this.setTitle("ok"); contentPane.setLayout(null); contentPane.setBackground(new Color(226, 245, 255)); contentPane.setAlignmentX((float) 1.0); contentPane.setAlignmentY((float) 1.0); contentPane.setToolTipText(""); contentPane.setActionMap(null); StartCheck.setBackground(new Color(188, 244, 224)); StartCheck.setBounds(new Rectangle(198, 77, 82, 22)); StartCheck.setFont(new java.awt.Font("SansSerif", 0, 12)); StartCheck.setText("查詢解釋"); StartCheck.addActionListener(new java.awt.event.ActionListener(){ public void actionPerformed(ActionEvent e) { StartCheck_actionPerformed(e); } }); ChooseList1.setBackground(new Color(245, 251, 255)); ChooseList1.setBounds(new Rectangle(21, 93, 114, 355)); ChooseList1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { ChooseList_mouseClicked(e); } }); OutputArea.setBackground(new Color(245, 251, 255)); OutputArea.setEditable(false); OutputArea.setFont(new java.awt.Font("SansSerif", 0, 14)); OutputArea.setForeground(Color.blue); OutputArea.setLocale(new java.util.Locale("zh", "", "")); OutputArea.setText(""); OutputArea.setBounds(new Rectangle(151, 122, 462, 206)); InputLabel.setFont(new java.awt.Font("SansSerif", 0, 14)); InputLabel.setText("查找"); InputLabel.setBounds(new Rectangle(82, 35, 44, 26)); think.addActionListener(new java.awt.event.ActionListener(){ public void actionPerformed(ActionEvent e) { think_actionPerformed(e); } }); think.setText("聯(lián)想"); think.setFont(new java.awt.Font("SansSerif", 0, 12)); think.setActionCommand(""); think.setBackground(new Color(188, 244, 224)); think.setBounds(new Rectangle(335, 77, 88, 22)); jFile.setBackground(new Color(226, 245, 255)); jFile.setFont(new java.awt.Font("SansSerif", 0, 12)); jFile.setText("文件"); jInputDict.setBackground(new Color(188, 244, 224)); jInputDict.setFont(new java.awt.Font("SansSerif", 0, 12)); jInputDict.setText("載入詞庫"); jInputDict.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jInputDict_actionPerformed(e); } }); jMenu.setBackground(new Color(226, 245, 255)); jMenu.setFont(new java.awt.Font("SansSerif", 0, 12)); ExitMenu.setBackground(new Color(188, 244, 224)); ExitMenu.setFont(new java.awt.Font("SansSerif", 0, 12)); ExitMenu.setText("退出"); ExitMenu.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ExitMenu_actionPerformed(e); } }); find.setBounds(new Rectangle(481, 77, 104, 22)); find.setBackground(new Color(188, 244, 224)); find.setActionCommand(""); find.setFont(new java.awt.Font("SansSerif", 0, 12)); find.setText("?通配符查找"); find.addActionListener(new java.awt.event.ActionListener(){ public void actionPerformed(ActionEvent e) { find_actionPerformed(e); } }); jRadioButton1.setBackground(new Color(226, 245, 255)); jRadioButton1.setFont(new java.awt.Font("SansSerif", 0, 12)); jRadioButton1.setSelected(true); jRadioButton1.setText("單詞識別模式"); jRadioButton1.setBounds(new Rectangle(198, 353, 133, 26)); jRadioButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jRadioButton1_actionPerformed(e); } }); jRadioButton2.setBackground(new Color(226, 245, 255)); jRadioButton2.setFont(new java.awt.Font("SansSerif", 0, 12)); jRadioButton2.setText("句子識別模式"); jRadioButton2.setBounds(new Rectangle(198, 395, 133, 26)); jRadioButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jRadioButton2_actionPerformed(e); } }); Mico1.setBounds(new Rectangle(26, 28, 55, 43)); Animate.setBounds(new Rectangle(364, 330, 225, 129)); jInputWords.setBackground(new Color(188, 244, 224)); jInputWords.setFont(new java.awt.Font("SansSerif", 0, 12)); jInputWords.setText("加入單詞"); jInputWords.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jInputWords_actionPerformed(e); } }); jHelp.setBackground(new Color(226, 245, 255)); jHelp.setFont(new java.awt.Font("SansSerif", 0, 12)); jHelp.setText("幫助"); jMenuAbout.setBackground(new Color(188, 244, 224)); jMenuAbout.setFont(new java.awt.Font("SansSerif", 0, 12)); jMenuAbout.setText("關(guān)于"); jMenuAbout.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jMenuAbout_actionPerformed(e); } }); diclabel.setFont(new java.awt.Font("SansSerif", 0, 12)); diclabel.setText("當前詞庫:default"); diclabel.setBounds(new Rectangle(471, 463, 145, 30)); contentPane.add(OutputArea, null); contentPane.add(jRadioButton2, null); contentPane.add(jRadioButton1, null); contentPane.add(InputField, null); contentPane.add(InputLabel, null); contentPane.add(Mico1, null); contentPane.add(Animate, null); contentPane.add(ChooseList1, null); contentPane.add(StartCheck, null); contentPane.add(think, null); contentPane.add(find, null); contentPane.add(diclabel, null); jMenu.add(jFile); jMenu.add(jHelp); jFile.add(jInputDict); jFile.add(jInputWords); jFile.add(ExitMenu); jHelp.add(jMenuAbout); this.setJMenuBar(jMenu); InputField_inputMethodTextChanged(null); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e){ if (e.getID() == WindowEvent.WINDOW_CLOSING) { try{ userwords.setusers(users); usertrans.close(); users.close(); index.close(); words.close(); trans.close();}catch (IOException z){} } super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void StartCheck_actionPerformed(ActionEvent e) { try{ String m=InputField.getText(); int te=indexin.findindexnum(m); long bol=indexin.wordblock[te].transpoint; wordsin.getwordsblock(words,bol); bol=wordsin.findword(m); showtrans(bol); int i=0; for(i=0;i<250;i++) { if(m.compareTo(userwords.wordblock[i].toString(userwords.wordblock[i]))==0) { OutputArea.append("\n自定義詞庫:\n"+m+"\n"); StringBuffer my=new StringBuffer(); usertrans.seek(userwords.wordblock[i].transpoint); char ap; ap=usertrans.readChar(); while(ap!=0) { my.append(ap); ap=usertrans.readChar(); } OutputArea.append(my.toString()); } } }catch (IOException x){} // OutputArea.setText("clicked"); } void InputField_caretUpdate(CaretEvent e) { } void ChooseList_mouseClicked(MouseEvent e) { if(iswordmodel) { if(ChooseList1.getAnchorSelectionIndex()>=0) { InputField.setText(List1con.elementAt(ChooseList1.getAnchorSelectionIndex()).toString()); StartCheck.doClick(); } } else { try{ String m=List1con.elementAt(ChooseList1.getAnchorSelectionIndex()).toString(); int te=indexin.findindexnum(m); long bol=indexin.wordblock[te].transpoint; wordsin.getwordsblock(words,bol); bol=wordsin.findword(m); showtrans(bol); }catch (IOException x){} } } void InputField_inputMethodTextChanged(InputMethodEvent e) { try{ if(iswordmodel) { String m=InputField.getText(); int te=indexin.findindexnum(m); long bol=indexin.wordblock[te].transpoint; wordsin.getwordsblock(words,bol); int to=wordsin.findwordind(m); wordsinnext.getwordsblock(words,indexin.wordblock[te+1].transpoint); showlist(to); }else { StringBuffer k=new StringBuffer(InputField.getText()); int i=k.lastIndexOf(" "); i=Math.max(i,k.lastIndexOf("?")); i=Math.max(i,k.lastIndexOf(",")); i=Math.max(i,k.lastIndexOf("!")); String m=k.substring(i); System.out.print(" "+m); int te=indexin.findindexnum(m); long bol=indexin.wordblock[te].transpoint; wordsin.getwordsblock(words,bol); bol=wordsin.findword(m); showtrans(bol); }}catch (IOException x){} } public void keyPressed(KeyEvent e) { if(e.getKeyCode()==e.VK_ENTER) { StartCheck.doClick(); } } public void keyReleased(KeyEvent e) { try{ if(iswordmodel) { if(e.getKeyCode()!=e.VK_ENTER) { String m=InputField.getText(); int te=indexin.findindexnum(m); long bol=indexin.wordblock[te].transpoint; wordsin.getwordsblock(words,bol); int to=wordsin.findwordind(m); wordsinnext.getwordsblock(words,indexin.wordblock[te+1].transpoint); showlist(to); } }else { StringBuffer k=new StringBuffer(InputField.getText()); int i=k.lastIndexOf(" "); i=Math.max(i,k.lastIndexOf("?")); i=Math.max(i,k.lastIndexOf(",")); i=Math.max(i,k.lastIndexOf("!")); // if(i<0) // i=0; String m=k.substring(i+1); //System.out.print(" "+m); int te=indexin.findindexnum(m); long bol=indexin.wordblock[te].transpoint; wordsin.getwordsblock(words,bol); bol=wordsin.findword(m); showtrans(bol); }}catch (IOException x){} } public void keyTyped(KeyEvent e) { } void think_actionPerformed(ActionEvent e) { mohu m=new mohu(); m.nowframe=this; if(iswordmodel) { m.s1 =InputField.getText(); } else { StringBuffer k=new StringBuffer(InputField.getText()); int i=k.lastIndexOf(" "); i=Math.max(i,k.lastIndexOf("?")); i=Math.max(i,k.lastIndexOf(",")); i=Math.max(i,k.lastIndexOf("!")); m.s1=k.substring(i+1); } m.Init(); m.start(); } void find_actionPerformed(ActionEvent e) { //查找過程添于此 tong m_tong=new tong(); m_tong.s1=InputField.getText(); m_tong.Init(); m_tong.nowframe=this; m_tong.ismohu=false; m_tong.start(); } void ExitMenu_actionPerformed(ActionEvent e) { processWindowEvent(new WindowEvent(this,WindowEvent.WINDOW_CLOSING)); } void jRadioButton1_actionPerformed(ActionEvent e) { iswordmodel=true; jRadioButton1.setSelected(true); jRadioButton2.setSelected(false); think.setEnabled(true); find.setEnabled(true); StartCheck.setEnabled(true); } void jRadioButton2_actionPerformed(ActionEvent e) { iswordmodel=false; List1con.removeAllElements(); ChooseList1.setListData(List1con); jRadioButton2.setSelected(true); jRadioButton1.setSelected(false); //think.setEnabled(false); find.setEnabled(false); StartCheck.setEnabled(false); } void jInputDict_actionPerformed(ActionEvent e) { JFileChooser OpenDialog=new JFileChooser("."+System.getProperty("file.separator"));// OpenDialog.setFont(new java.awt.Font("SansSerif", 0, 12)); int retopen=OpenDialog.showOpenDialog(this); if(retopen==JFileChooser.APPROVE_OPTION) { try{ index.close(); words.close(); trans.close(); loadfile(OpenDialog.getSelectedFile().toString()); InputField_inputMethodTextChanged(null); }catch (IOException z){} } } boolean packFrame = false; JMenu jHelp = new JMenu(); JMenuItem jMenuAbout = new JMenuItem(); Label diclabel = new Label(); void jInputWords_actionPerformed(ActionEvent e) { AddWordsFrame frame = new AddWordsFrame(); frame.icon=icon; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); frameSize.height=(int)(frameSize.height*1.05); frame.setSize(frameSize); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); } void jMenuAbout_actionPerformed(ActionEvent e) { AboutFrame frame = new AboutFrame(this); frame.icon=icon; Dimension frmSize = getSize(); frame.setSize(320,240); frame.setTitle("關(guān)于"); frame.setResizable(false); Dimension frameSize = frame.getSize(); frameSize.height=(int)(frameSize.height*1.05); frame.setSize(frameSize); if (frameSize.height > frmSize.height) { frameSize.height = frmSize.height; } if (frameSize.width > frmSize.width) { frameSize.width = frmSize.width; } Point loc = getLocation(); frame.setLocation((frmSize.width - frameSize.width) / 2+loc.x, (frmSize.height - frameSize.height) / 2+loc.y); frame.setModal(true); frame.show(); }}class Animate implements Runnable{ StartFrame nowstartframe=null; frame nowframe=null; AboutFrame nowaboutframe=null; int aninum=0; boolean gook=true; Thread AnimateThread=null; int cycle=18; public void start() { switch(aninum) { case 0: cycle=18; break; case 1: case 2: cycle=10; break; default: } if(AnimateThread==null) { AnimateThread=new Thread(this,"Animate"); AnimateThread.start(); } } String getfilename(int i) { switch(aninum) { case 0: return ".\\ico3\\ico3"+i+".jpg"; // break; case 1: case 2: return ".\\about\\about"+i+".jpg"; //break; default: return ".\\ico3\\ico3"+i+".jpg"; } } public void run() { int i=0; Image img=Toolkit.getDefaultToolkit().getImage(getfilename(i)); ImageIcon ico3=new ImageIcon(img); while(gook&&AnimateThread!=null) { img=Toolkit.getDefaultToolkit().getImage(getfilename(i)); ico3.setImage(img); switch(aninum) { case 0: nowframe.Animate.setIcon(ico3); nowframe.Animate.repaint(); break; case 1: nowaboutframe.Animate.setIcon(ico3); nowaboutframe.Animate.repaint(); break; case 2: nowstartframe.Animate.setIcon(ico3); nowstartframe.Animate.repaint(); break; default: } i++; if(i>=cycle) { i=i-cycle; try{ AnimateThread.sleep(800);}catch( InterruptedException e){} } try{ AnimateThread.sleep(120);}catch( InterruptedException e){} } if(aninum==0) { ImageIcon img3=new ImageIcon(".\\ico3\\ico3sta.jpg"); nowframe.Animate.setIcon(img3); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -