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

📄 spellcheckerframe.java

📁 用java 编写的快速编写程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        jMenu2.add(jMenuItem3);

        jMenuItem4.setText("Paste");
        //=======================
        jMenuItem4.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
            		Transferable clipData =clipbd.getContents(SpellCheckerFrame.this);
					try {
						String clipString = 
						(String)clipData.
						getTransferData(
						DataFlavor.stringFlavor);
						jTextPane1.replaceSelection(clipString);
						} catch(Exception ex) {
						System.out.println("not String flavor");
						}
          }
        });
        //=======================
        jMenu2.add(jMenuItem4);

        jMenuItem8.setText("Cut");
        //===============
        jMenuItem8.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                 String selecttext=jTextPane1.getSelectedText();
   				 StringSelection clipString = new StringSelection(selecttext);     
   				 clipbd.setContents(clipString, clipString); 
   				 jTextPane1.replaceSelection("");
            }
        });
        //===============
        jMenu2.add(jMenuItem8);

        jMenuItem9.setText("Chage dictionary");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                path.setFile("*.txt");
                path.setDirectory("c:\\");
                path.setVisible(true);
                String a = path.getDirectory();
                a = a + path.getFile();
                a = a.replaceAll("\\", "\\\\");
                dicPath = a;
            }
        });
        jMenu2.add(jMenuItem9);

        jMenuBar1.add(jMenu2);

        jMenu3.setText("Help");
        jMenu3.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jMenu3ActionPerformed(evt);
            }
        });

        jMenuItem5.setText("Help");
        jMenu3.add(jMenuItem5);

        jMenuItem6.setText("About");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
              //add  
            }
        });
        jMenu3.add(jMenuItem6);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        setLocation(300, 200);

        pack();
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
    {
        // TODO add your handling code here:
        String result;
        String textPane = jTextPane1.getText();
        try
        {
            SpellChecker checker = new SpellChecker(dicPath, textPane);
            result = checker.getResult();
            jTextField1.setText(result);
            String[] chack = checker.getText();
            showTextPane(chack);
        } catch (IOException e)
        {
        }
    }

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt)
    {
        // TODO add your handling code here:
        path.setFile("*.txt");
        path.setDirectory("c:\\");
        path.setVisible(true);
        try
        {
            File mf = new File(path.getDirectory(), path.getFile());
            String stitle = path.getDirectory() + path.getFile();
            BufferedReader in = new BufferedReader(new FileReader(mf));
            String text = "";
            jTextPane1.setText("");
            while (in.ready())
            {
                //jTextArea1.append(in.readLine() + "\n");
                text = text + in.readLine() + "\n";
            }
            jTextPane1.setText(text);
            in.close();
        } catch (IOException ioe)
        {
            System.err.println(ioe.toString());
        }	//第二次捕捉异常处理取消按键
        catch (Exception ioee)
        {
        }
    }

    private void jMenu3ActionPerformed(java.awt.event.ActionEvent evt)
    {
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(null, "JAVA记快速拼写程序V1.01BETA1");
    }

    private void showTextPane(String[] chack)
    {
        jTextPane1.setText("");
        
        doc = jTextPane1.getStyledDocument();
        addStylesToDocument(doc);
        try
        {
            for (int i = 0; i < chack.length; i++)
            {
                if (chack[i] == null)
                    break;
                if (chack[i].charAt(chack[i].length() - 1) == '*')
                {
                    String mid = chack[i].substring(0, chack[i].length() - 1);
                    doc.insertString(doc.getLength(), mid, doc
                                    .getStyle(initStyles[1]));
                } else
                    doc.insertString(doc.getLength(), chack[i], doc
                                    .getStyle(initStyles[0]));
            }
            doc.insertString(doc.getLength(), " ", doc	//恢复字体
                            .getStyle(initStyles[0]));
        } catch (BadLocationException ble)
        {
            System.err.println("Couldn't insert initial text into text pane.");
        }
    }

    private JTextPane createTextPane()
    {
        jTextPane1 = new JTextPane();
        StyledDocument doc = jTextPane1.getStyledDocument();
        addStylesToDocument(doc);
        return jTextPane1;
    }

    protected void addStylesToDocument(StyledDocument doc)
    {
        //Initialize some styles.
        Style def = StyleContext.getDefaultStyleContext().getStyle(
                        StyleContext.DEFAULT_STYLE);

        Style regular = doc.addStyle("regular", def);
        StyleConstants.setFontFamily(def, "SansSerif");

        Style s = doc.addStyle("bold", regular);
        StyleConstants.setForeground(s, Color.RED);
        StyleConstants.setBold(s, true);
    }

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;

    private javax.swing.JButton jButton2;

    private javax.swing.JButton jButton3;

    private javax.swing.JButton jButton4;

    private javax.swing.JButton jButton5;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JMenu jMenu1;

    private javax.swing.JMenu jMenu2;

    private javax.swing.JMenu jMenu3;

    private javax.swing.JMenuBar jMenuBar1;

    private javax.swing.JMenuItem jMenuItem1;

    private javax.swing.JMenuItem jMenuItem2;

    private javax.swing.JMenuItem jMenuItem3;

    private javax.swing.JMenuItem jMenuItem4;

    private javax.swing.JMenuItem jMenuItem5;

    private javax.swing.JMenuItem jMenuItem6;

    private javax.swing.JMenuItem jMenuItem7;

    private javax.swing.JMenuItem jMenuItem8;

    private javax.swing.JMenuItem jMenuItem9;

    private javax.swing.JPanel jPanel2;

    private javax.swing.JPanel jPanel3;

    private javax.swing.JScrollPane jScrollPane1;

    private javax.swing.JScrollPane jScrollPane2;

    private javax.swing.JSplitPane jSplitPane1;

    private javax.swing.JTextField jTextField1;

    private javax.swing.JTextPane jTextPane1;

    private javax.swing.JToolBar jToolBar1;

    private javax.swing.JTree jTree1;

    // End of variables declaration

    private StringBuffer SBtext;

    private String Stext;

    private String dicPath = "WordList_6.txt";

    private JFrame jframe;

    private FileDialog path = new FileDialog(this, "Open...");
    private StyledDocument doc;
    
    private String[] initStyles = { "regular", "bold" };
    //=============
    Clipboard clipbd=getToolkit().getSystemClipboard();
    int newflag=1;
  	String stitle;
  	FileDialog fs=new FileDialog(this,"保存文件",FileDialog.SAVE);
    PrinterJob prtMe = PrinterJob.getPrinterJob(); 
    JFileChooser fc = new JFileChooser(); 
}

⌨️ 快捷键说明

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