我的JAVA 学习

package com.resume.sky;

import java.io.File;
import javax.swing.filechooser.FileFilter;

public class GenericFileFilter extends FileFilter {

 private String[] extension;

 public GenericFileFilter(String[] extension) {
  this.extension = extension;
 }

 public boolean accept(File file) {
  if (file.isDirectory()) {
   return false;
  }

  String name = file.getName();
  // find the last
  int idx = name.lastIndexOf(".");
  if (idx == -1) {
   return false;
  } else if (idx == name.length() - 1) {
   return false;
  } else {
   for(int i=0;i<extension.length;i++)
    if(extension[i].equals(name.substring(idx + 1).toLowerCase()))
      return true;
   return false;
  }
 }
 
 public String getDescription()
 {
  return "网页(*.html; *.htm File)";
 }
}
------------------------------------------------

package com.resume.sky;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.sunking.jni.jwebbrowser.Test;

/**
 * 简历下载器主界面
 * @author qKF9319
 *
 */
public class MainFrame extends JFrame implements ActionListener,ChangeListener{
 
 private ResumeMenu rmenu;
 private Test ieBrowser;
 private ManualDownLoadPanel dlPanel;
 private AutoDownLoadPanel adlPanel;
 private MyResumePanel mrPanel;
 private JTabbedPane jTabPane;
 private JPanel jButtomPanel;
 private JButton exitButton;
 private JButton optimizeButton;
 
 public MainFrame()
 {
  try
  {
   jbInit();
  }
  catch(Exception e)
  {
   e.printStackTrace();
  }
 }
 
 public void jbInit()
 {
  Container cont=this.getContentPane();
  this.setLayout(new BorderLayout(5,15));
  rmenu=new ResumeMenu();
  cont.add(rmenu,BorderLayout.NORTH);
  jTabPane=new JTabbedPane();
  ieBrowser = new Test();
  mrPanel=new MyResumePanel();
  dlPanel=new ManualDownLoadPanel();
  adlPanel=new AutoDownLoadPanel(mrPanel.getStoreRootPath());
  
  /*由于ChangeEvent是属于Swing的事件,而不是AWT的事件,因此import Swing的事件类来处理
  *ChangeEvent事件。
  */
  jTabPane.addChangeListener(this);
  jTabPane.add("浏览器", ieBrowser);
  jTabPane.add("简历自动下载", adlPanel);
  jTabPane.add("简历手动下载", dlPanel);
  jTabPane.add("简历库查询", mrPanel);
  cont.add(jTabPane,BorderLayout.CENTER);
  
  optimizeButton=new JButton("优化下载速度");
  exitButton=new JButton("退 出");
  jButtomPanel=new JPanel();
  
  exitButton.addActionListener(this);
  optimizeButton.addActionListener(this);
  jButtomPanel.add(optimizeButton);
  jButtomPanel.add(exitButton);
  cont.add(jButtomPanel,BorderLayout.SOUTH);
  
  //cont.setVisible(true);
 }
 
 public void actionPerformed(ActionEvent e)
 {
  if(e.getSource()==exitButton)
  //if(JOptionPane.showConfirmDialog(this,"您确定要退出吗?","提示",JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
  {
   System.exit(0);
  }
  else
  {
   if(e.getSource()==optimizeButton)
   {
    try
    {
     Runtime rt = Runtime.getRuntime(); //Time and Date.
     rt.exec("cmd /c start " +System.getProperty("user.dir")+"/clear.bat");
     //("cmd.exe /c [b]start[/b] e://test.bat");
     //Process child = rt.exec("C:/Program Files/Internet Explorer/IEXPLORE.EXE");

    }
       catch(Exception e1)
       {
        e1.printStackTrace();
     JOptionPane.showMessageDialog(null, "运行出错,请检查出错原因!", "出错",
       JOptionPane.ERROR_MESSAGE);
       }

   }
  }
 }
 
 
 public void stateChanged(ChangeEvent e){
  if(jTabPane.getComponent(jTabPane.getSelectedIndex()) instanceof AutoDownLoadPanel)
  {
   adlPanel.setRootStorePath(mrPanel.getStoreRootPath());
  }
 }

 
 public static void main(String[] args) {
  MainFrame mframe = new MainFrame();
  mframe.setTitle("简历自动下载器");
  mframe.setBounds(300, 100, 960, 820);
  mframe.validate();
  mframe.setVisible(true);
 }
}
--------------------------- -------------------------

package com.resume.sky;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.Vector;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.filechooser.FileFilter;
import javax.swing.text.Document;


/**
 * 简历下载主界面类
 * @author qKF9319
 *
 */
public class ManualDownLoadPanel extends JPanel implements ActionListener {

 private String spath="";
 
 private String[] selectIndexArray;
 
 private String[] keyIdArray;
 
 private String selItem="第1条";//用户要查看的简历索引
 
 private SearchResultFile sFile;
 
 private JLabel dlNumLabel;
 
 private JLabel selIndexLabel;

 private JButton dlButton;

 private JButton rfreButton;

 private JButton resetButton;
 
 private JButton contentButton; 
 
 private JComboBox selectCombox;

 private JTextField dlTextField;

 private JPanel northJPanel;
 
 private JPanel northJPanel1;
 
 private JPanel northJPanel2;

 private JEditorPane editorPane;

 private JScrollPane scrollPane;
 
 private JTabbedPane jTabPane;

 public ManualDownLoadPanel() {
  jbInit();
 }

 public void jbInit() {
  dlNumLabel = new JLabel("简历下载数目(不超过4个)", JLabel.CENTER);
  dlButton = new JButton("下载");
  rfreButton = new JButton("刷新");
  resetButton = new JButton("重置");
  rfreButton.setEnabled(false);

  dlButton.addActionListener(this);
  rfreButton.addActionListener(this);
  resetButton.addActionListener(this);

  dlTextField = new JTextField("4", 6);
  this.setLayout(new BorderLayout(5, 10));

  northJPanel = new JPanel(); 
  northJPanel.setLayout(new GridLayout(1,2,5,10));
  northJPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory
    .createEtchedBorder(), "参数设置"));
  
  northJPanel1= new JPanel();
  northJPanel1.setBorder(BorderFactory.createTitledBorder(BorderFactory
    .createEtchedBorder(), ""));
  
  northJPanel2= new JPanel();
  northJPanel2.setBorder(BorderFactory.createTitledBorder(BorderFactory
    .createEtchedBorder(), ""));
  
  northJPanel1.add(dlNumLabel);
  northJPanel1.add(dlTextField);
  northJPanel1.add(dlButton);
  northJPanel1.add(rfreButton);
  northJPanel1.add(resetButton);
  northJPanel.add(northJPanel1);
    
  selectCombox=new JComboBox();
  selectCombox.setEnabled(false);
  selectCombox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JComboBox cb = (JComboBox)e.getSource();
                selItem = (String)cb.getSelectedItem();
            }
        });
  selIndexLabel=new JLabel("请选择相关简历", JLabel.CENTER);
  contentButton=new JButton("查看");
  contentButton.setEnabled(false);
  contentButton.addActionListener(this);
  
  northJPanel2.add(selIndexLabel);
  northJPanel2.add(selectCombox);
  northJPanel2.add(contentButton);
  northJPanel.add(northJPanel2);
  
  this.add(northJPanel, BorderLayout.NORTH);

  editorPane = new JEditorPane();
  editorPane.setBorder(BorderFactory.createTitledBorder(BorderFactory
    .createEtchedBorder(), "下载结果"));

  editorPane.setEditable(false);

  // 要能响应网页中的链接,则必须加上超链监听器
  //editorPane.addHyperlinkListener(this);

  scrollPane = new JScrollPane(editorPane);
  jTabPane=new JTabbedPane();
  jTabPane.add("简历概况", scrollPane);

  this.add(jTabPane, BorderLayout.CENTER);
 }

 public void actionPerformed(ActionEvent evt) {
  try {
   if (evt.getSource() == dlButton) {
    rfreButton.setEnabled(true);
    dlButton.setEnabled(false);

    int inputNum = Integer.parseInt(dlTextField.getText().trim());
    if (inputNum <= 0 || inputNum > 4) {
     JOptionPane.showMessageDialog(null, "输入不附合要求!", "提示",
       JOptionPane.INFORMATION_MESSAGE);
    } else {
     // int responseCode = -1;

     // 如果有代理服务器,需要设置代理服务器,否则将下2行注释掉
     /*
      * System.getProperties().put("proxySet", "true");
      * System.getProperties().put("proxyHost",
      * "proxy.huawei.com");// 代理服务器的ip或者名字
      * System.getProperties().put("proxyPort", "8080");//
      * 代理服务器端口 HttpURLConnection connection = null; String path =
      * "http://ehr.chinahr.com/Resume/ResumeCenter/ResumeSearch6.aspx";
      * URL website = new URL(path); String line = null; String
      * content = "";
      *
      * connection = (HttpURLConnection)
      * website.openConnection();
      *
      * //String auth ="Basic "+new
      * sun.misc.BASE64Encoder().encode(authString.getBytes()); //
      * con.setRequestProperty("Authorization", auth);
      * //InputStream is = con.getInputStream();
      *
      * //您必须调整 HTTP 标头以发出用户信息。这是通过调用 setRequestProperty() 来实现的。
      * //这种方法允许您在发出请求之前处理 HTTP 标头。HTTP 要求用 base64 对用户名和口令进行编码。
      *
      * String password = "w32641:Love0328"; BASE64Encoder bd =
      * new BASE64Encoder(); byte[] temp = password.getBytes();
      * String encodedPassword = "Basic " + bd.encode(temp);
      *
      * connection.setRequestProperty("Proxy-Authorization",
      * encodedPassword);
      *
      * BufferedReader in = new BufferedReader( new
      * InputStreamReader(connection.getInputStream()));
      *
      * while ((line = in.readLine()) != null) { if
      * (line.length() != 0) content += line + "/n"; }
      */

     // responseCode = connection.getResponseCode();
     // 接收应答代码,可以根据这个代码判断制定的URL是否可以连通
     spath = writeToHTM(inputNum);
     if (!spath.equals("")) {
      
      editorPane.setPage(spath);
      
      contentButton.setEnabled(true);
      selectCombox.setEnabled(true);
      selectIndexArray=new String[inputNum+1];
      for(int i=0;i<selectIndexArray.length-1;i++)
      {
       selectIndexArray[i]="第"+(i+1)+"条";
       selectCombox.addItem(selectIndexArray[i]);
      }   
      selectIndexArray[selectIndexArray.length-1]="全部简历";
      selectCombox.addItem(selectIndexArray[selectIndexArray.length-1]);
      selectCombox.setSelectedIndex(0);//默认显示第一条简历
     
     } else {
      JOptionPane.showMessageDialog(null,
        "没有下载到符合你要求的简历,请先运行测试脚本!", "提示",
        JOptionPane.INFORMATION_MESSAGE);
      dlButton.setEnabled(true);
      rfreButton.setEnabled(false);
     }
    }

   } else {
    if (evt.getSource() == rfreButton) {//刷新
     Document doc = editorPane.getDocument();
     doc.putProperty(Document.StreamDescriptionProperty, null);
     editorPane.setPage(spath);   
    } else { // 重置
     if (evt.getSource() == resetButton) {
      dlButton.setEnabled(true);
      rfreButton.setEnabled(false);
      selectCombox.setEnabled(false);
      selectCombox.removeAllItems();
      contentButton.setEnabled(false);
      
      Document doc = editorPane.getDocument();
      doc.putProperty(Document.StreamDescriptionProperty, null);
      editorPane.setText("");
      dlTextField.setText("4");
     }
     else
     {
      if(evt.getSource() ==contentButton)//查看简历详细信息
      {
       Vector<File> res=addResumeContentPanel(selItem,"DetailSingle[*].htm");
       if(!res.isEmpty())
       {
        String spath1="";
        final JFrame jPopFrame=new JFrame("简历查询");
        jPopFrame.getContentPane().setLayout(new BorderLayout());
        jPopFrame.setBounds(100,200,800, 600);
        final JTabbedPane jpTabPopPane1=new JTabbedPane();
        final JPanel operPanel=new JPanel();
        operPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory
          .createEtchedBorder(), "操相关作"));
        JButton exitButton=new JButton("退 出");
        exitButton.addActionListener(
          new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                     jPopFrame.dispose();
                    }
                });
        JScrollPane scrollPane1;

           for(int i=0;i<res.size();i++)
        {   
            final JEditorPane editorPane=new JEditorPane();        
            editorPane.setEditable(false);
         scrollPane1 = new JScrollPane(editorPane);
            if(res.size()==1)
            {          
             spath1 =ParseTxtContent.path +keyIdArray[Integer.parseInt(selItem.substring(1,2))-1]+".htm";
          writeToResumeHTM(res.elementAt(i), keyIdArray[Integer.parseInt(selItem.substring(1,2))-1]);//得到输出文件
          jpTabPopPane1.add("简历"+selItem.substring(1,2), scrollPane1);
          
          final JButton saveButton=new JButton("保存简历");
          final JButton editButton=new JButton("编辑简历");
          final JButton sureButton=new JButton("确定修改");
          
          sureButton.setEnabled(false);
          
          saveButton.addActionListener(
            new ActionListener() {
                      public void actionPerformed(ActionEvent e){
                       final SelefDefFileChooser jfc=new SelefDefFileChooser(new File("E://Resume Files"));
                           //add Filters
                          String htmlExts[] ={ "html", "htm" };          

                          // construct it giving it an array of file
                          // extensions and a description string
                          FileFilter filter = new GenericFileFilter(htmlExts);
                          jfc.addChoosableFileFilter(filter);

                       jfc.setDialogType(JFileChooser.SAVE_DIALOG);
                       int state=jfc.showSaveDialog(null);
                       
                       if(state == JFileChooser.APPROVE_OPTION) {
                        
                       if(jfc.storeSelection(editorPane.getText())==1)
                         JOptionPane.showMessageDialog(null,"保存成功!", "提示",
                JOptionPane.INFORMATION_MESSAGE );
                       }
                      }
                  });
          editButton.addActionListener(
            new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                       editButton.setEnabled(false);
                       sureButton.setEnabled(true);
                       editorPane.setEditable(true);
                      }
                  });
          sureButton.addActionListener(
            new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                       editButton.setEnabled(true);
                       sureButton.setEnabled(false);
                       editorPane.setEditable(false);
                      }
                  });
          operPanel.add(editButton);
          operPanel.add(sureButton);
          operPanel.add(saveButton);
          operPanel.add(exitButton);
    
            }
         else
         {
          spath1 = ParseTxtContent.path +keyIdArray[i]+".htm";  
             writeToResumeHTM(res.elementAt(i), keyIdArray[i]);//得到输出文件
          jpTabPopPane1.add("简历"+(i+1), scrollPane1);
          operPanel.add(exitButton);
         }
            editorPane.setPage(spath1);                   
        }
           jPopFrame.add(operPanel,BorderLayout.NORTH);
        jPopFrame.add(jpTabPopPane1,BorderLayout.CENTER);

        //jPopFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jPopFrame.validate();
        
        jPopFrame.setVisible(true);
       }
       else
       {
        JOptionPane.showMessageDialog(null,
          "对不起,访问出错,请重新下载!", "提示",
          JOptionPane.INFORMATION_MESSAGE);
       }
      }
     }
    }
   }
  } catch (Exception e) {
   e.printStackTrace();
   JOptionPane.showMessageDialog(null, "运行出错,请检查出错原因!spath"+this.spath, "出错",
     JOptionPane.ERROR_MESSAGE);
  }
 }

 public void hyperlinkUpdate(HyperlinkEvent e) {
  // TODO Auto-generated method stub
  /*
   * try { if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED)
   * editorPane.setPage(e.getURL()); } catch (Exception ex) {
   * ex.printStackTrace(); JOptionPane.showMessageDialog(null,
   * "运行出错,请检查出错原因!", "出错", JOptionPane.ERROR_MESSAGE); }
   */

 }

 /**
  * 得到过滤后的检索结果
  *
  * @param inputNum
  *            检索的结果数
  * @throws Exception
  */
 public String writeToHTM(int inputNum) throws Exception {
  // 读文本:C:/Documents and Settings/qkf9319/Local Settings/Temporary
  // Internet Files/Content.IE5/
  sFile = new SearchResultFile();
  String path = sFile.getTheLatestResFile("Result[*].htm");
  String spath = "";
  
  if (!path.equals("")) {

   File inputFile = new File(path);
   keyIdArray=new String[inputNum];
   ParseTxtContent ptContent = new ParseTxtContent();

   InputStream is = new FileInputStream(inputFile);
   String readRes = ptContent.readToBuffer(is);

   // System.out.println(readRes); // 将读到 buffer 中的内容写出来
   is.close();

   StringBuffer buffer = new StringBuffer();
   int searchContentTempIndex = readRes.indexOf("<!-- 现职位/链接 -->");
   int searchContentSIndex = readRes.indexOf("<a href",
     searchContentTempIndex);
   int totalRes = 1;
   while (searchContentTempIndex != -1)// 搜索符合要求的内容
   {
    int searchContentEIndex = readRes.indexOf("<!--  详细信息 tr -->",
      searchContentSIndex);
    String resTemp = "<tr><td>"
      + (totalRes)
      + ". "
      + readRes.substring(searchContentSIndex,
        searchContentEIndex) + "/n";
    resTemp = resTemp.replace("/n", "/r/n");// 注意改成/r/n
    buffer.append(resTemp);
    
    int stIndex=resTemp.indexOf("ResumeIDs=")+10;
    keyIdArray[totalRes-1]=resTemp.substring(stIndex,resTemp.indexOf("|",stIndex));//获取对应的ID
    
    
    searchContentTempIndex = readRes.indexOf("<!-- 现职位/链接 -->",
      searchContentEIndex);
    searchContentSIndex = readRes.indexOf("<a href",
      searchContentTempIndex);
    totalRes++;
    if (totalRes > inputNum)
     break;
   }
   readRes = null;
   // System.out.println(buffer); // 将读到 buffer 中的内容写出来
   // 写文本
   URL pathURL = ParseTxtContent.class.getResource("");
   spath = pathURL.toString() + "result.htm";
   File outPutFile = new File(new URI(spath));// 注意路径带//
   if (outPutFile.exists())
    outPutFile.delete();
   ptContent.writeFromBuffer(buffer.toString(), new FileOutputStream(
     outPutFile));
  }

  return spath;
 }
 
 /**
  * 得到过滤后的检索结果
  *
  * @param inputNum
  *            检索的结果数
  * @throws Exception
  */
 public void writeToResumeHTM(File inputFile,String keyID) throws Exception {
  // 读文本:C:/Documents and Settings/qkf9319/Local Settings/Temporary
  // Internet Files/Content.IE5/
  ParseTxtContent ptContent = new ParseTxtContent();
  String spath1= ParseTxtContent.path +keyID+".htm";
  InputStream is = new FileInputStream(inputFile);
        String readRes = ptContent.readToNormalBuffer(is);
        is.close();
        StringBuffer buffer = new StringBuffer();
  int searchContentSIndex =readRes.indexOf("<div id");
  int searchContentEIndex = readRes.indexOf("</TABLE></div>");

        buffer.append("<br><br>"+readRes.substring(searchContentSIndex,searchContentEIndex+14));
       
        String res=buffer.toString();
        if(res.contains("IMG SRC=/"http://"))
        {
         res=res.replace("IMG SRC=/"http://", "IMG SRC=/"");
        }
       
        if (res.contains("img src=/"http://")) {
   res = res
     .replace("img src=/"http://", "img src=/"");
  }
       
        res = res.replace("/n", "/r/n");// 注意改成/r/n
        buffer=null;
  File outPutFile = new File(new URI(spath1));
  if (outPutFile.exists())
   outPutFile.delete();
  ptContent.writeFromBuffer(res, new FileOutputStream(
    outPutFile)); 
  //return buffer.toString();
  
 }
 
 
 /**
  * 根据下拉框的选择,查看对应简历的详细信息
  * @param selItem
  * @throws IOException
  */
 public Vector<File> addResumeContentPanel(String selItem, String fileName) throws IOException
 {
  Vector<File> res;
  if(!selItem.equals("全部简历"))
  {
   selItem=selItem.substring(1,2);
   int selInTiem=Integer.parseInt(selItem)-1;
   res=sFile.getResumeContent(new String[]{keyIdArray[selInTiem]},fileName);   
  }
  else
  {
   res=sFile.getResumeContent(keyIdArray,fileName);
  }
  return res;
 }
 
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值