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

📄 searchframe.java

📁 这是用java写的c++扫描程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * SearchFrame.java
 *
 * Created on 2007年3月12日, 下午9:05
 */

package CCodeSearch;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.JFileChooser;

/**
 *
 * @author  Administrator
 */
public class SearchFrame extends javax.swing.JFrame {
    
    /** Creates new form SearchFrame */
    public SearchFrame() {
        initComponents();
        flag=false;
        isID=false;
        hasEmpty=false;
        searchC =new SearchC();
        setLocation(200,100);
        v =new Vector();
        InputArea.setFocusable(true);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        TitleLabel = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        InputScroll = new javax.swing.JScrollPane();
        InputArea = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        OutputScroll = new javax.swing.JScrollPane();
        OutputArea = new javax.swing.JTextArea();
        SearchBT = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        ExitBT = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        MainMenu = new javax.swing.JMenuBar();
        FileMenu = new javax.swing.JMenu();
        OpenFileItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        SaveFileItem = new javax.swing.JMenuItem();
        SysSetMenu = new javax.swing.JMenu();
        CodeSetItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("C++\u6e90\u4ee3\u7801\u626b\u63cf\u7a0b\u5e8f");
        setResizable(false);
        TitleLabel.setFont(new java.awt.Font("宋体", 1, 36));
        TitleLabel.setText("C++\u6e90\u4ee3\u7801\u626b\u63cf\u7a0b\u5e8f");

        InputScroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        InputArea.setBackground(new java.awt.Color(255, 255, 204));
        InputArea.setColumns(20);
        InputArea.setLineWrap(true);
        InputArea.setRows(5);
        InputArea.setToolTipText("C++\u7a0b\u5e8f\u7f16\u5199\u533a");
        InputArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                InputAreaKeyPressed(evt);
            }
        });

        InputScroll.setViewportView(InputArea);

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, InputScroll, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, InputScroll, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
        );

        jPanel2.setFocusable(false);
        OutputScroll.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        OutputScroll.setFocusable(false);
        OutputArea.setBackground(new java.awt.Color(204, 255, 255));
        OutputArea.setColumns(20);
        OutputArea.setEditable(false);
        OutputArea.setLineWrap(true);
        OutputArea.setRows(5);
        OutputArea.setFocusable(false);
        OutputScroll.setViewportView(OutputArea);

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(OutputScroll, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(OutputScroll, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
        );

        SearchBT.setText("\u626b  \u63cf");
        SearchBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchBTActionPerformed(evt);
            }
        });

        jLabel1.setText("\u626b\u63cf\u7ed3\u679c\u5982\u4e0b\uff1a");

        ExitBT.setText("\u9000  \u51fa");
        ExitBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitBTActionPerformed(evt);
            }
        });

        jButton1.setText("\u6e05\u7a7a\u7ed3\u679c");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("\u6e05\u7a7a\u8f93\u5165\u533a");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        FileMenu.setText("\u6587\u4ef6");
        OpenFileItem.setText("\u6253\u5f00\u6587\u4ef6");
        OpenFileItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OpenFileItemActionPerformed(evt);
            }
        });

        FileMenu.add(OpenFileItem);

        FileMenu.add(jSeparator1);

        SaveFileItem.setText("\u4fdd\u5b58\u8f93\u51fa\u7ed3\u679c");
        SaveFileItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveFileItemActionPerformed(evt);
            }
        });

        FileMenu.add(SaveFileItem);

        MainMenu.add(FileMenu);

        SysSetMenu.setText("\u8bbe\u7f6e");
        CodeSetItem.setText("\u6e90\u4ee3\u7801\u8bbe\u7f6e");
        CodeSetItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CodeSetItemActionPerformed(evt);
            }
        });

        SysSetMenu.add(CodeSetItem);

        MainMenu.add(SysSetMenu);

        setJMenuBar(MainMenu);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(SearchBT)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jButton1)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jButton2)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(ExitBT))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel1))
                        .addContainerGap())
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(TitleLabel)
                        .add(126, 126, 126))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(14, 14, 14)
                .add(TitleLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(SearchBT)
                    .add(jButton1)
                    .add(ExitBT)
                    .add(jButton2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CodeSetItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CodeSetItemActionPerformed
// TODO 将在此处添加您的处理代码:
        setFilterF =new SetFilterFrame();
        setFilterF.setVisible(true);
    }//GEN-LAST:event_CodeSetItemActionPerformed

    private void SaveFileItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveFileItemActionPerformed
// TODO 将在此处添加您的处理代码:
        String saveFileName="",context;
        StringTokenizer fenxiResult=new StringTokenizer(OutputArea.getText(),"\n");
        JFileChooser chooser=new JFileChooser();
        int returnVal = chooser.showSaveDialog(this);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
            saveFileName=chooser.getSelectedFile().getPath();
            //System.out.println("You chose to open this file: " +saveFileName);
            try{
                BufferedWriter out =new BufferedWriter(new FileWriter(saveFileName));
                while(fenxiResult.hasMoreTokens()){
                    context=fenxiResult.nextToken();
                    out.write(context,0,context.length());
                    out.newLine();
                }
                out.close();
            }catch(IOException e){
                e.printStackTrace();
            }
        }
    }//GEN-LAST:event_SaveFileItemActionPerformed

    private void OpenFileItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenFileItemActionPerformed
// TODO 将在此处添加您的处理代码:
        String fileFullName="",context;
        JFileChooser chooser=new JFileChooser();
        int returnVal = chooser.showOpenDialog(this);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
            fileFullName=chooser.getSelectedFile().getAbsolutePath();
            //System.out.println("You chose to open this file: " +fileFullName);
            try{
                BufferedReader in =new BufferedReader(new FileReader(fileFullName));
                InputArea.setText("");
                hasEmpty=false;
                flag=false;
                text="";
                while((context=in.readLine())!=null){
                    InputArea.append(context);
                    InputArea.append("\n");
                }
                in.close();

⌨️ 快捷键说明

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