SSISO Community

시소당

JEditorPane과의 전쟁...


요즘  내가  만들고  있는  프로그램의  소스  이다..
웹  브라우져를  만들고  있는데  이건  도무지...
머랄까  일반  웹브라우져처럼  표기를  못해준다  ㅠ.ㅠ
머리  굴려  보고  있긴  한데...  CSS  처리를  안해서  그런가..
암튼  기필고  브라우져  만들어  본다!!
아래  소스를  붙여  놓는다..  코멘트는  없다~~~
왜냐고...  저소스도  간신히  살렸다...

코딩하다가  컴  따운  되서  리붓  되었더니  소스  날라가  버렸다  ㅠ.ㅠ  

import  java.awt.*;
import  java.awt.event.*;
import  javax.swing.*;
import  java.io.*;
import  java.net.*;
import  javax.swing.text.*;
import  javax.swing.text.html.*;
import  javax.swing.event.*;

public  class  m_Frame  extends  JFrame  implements  ActionListener,  HyperlinkListener  {
    
  public  m_Frame()  {
    set_Design();
  }
  JButton  test  =  new  JButton("나누어  보기");
  JTextField  tf_url  =  new  JTextField();
  
  JEditorPane  paneArea  =  new  JEditorPane();
  JTextArea  paneArea2  =  new  JTextArea();
  EditorKit  htmlKit  =  paneArea.getEditorKitForContentType("text/html");
  HTMLDocument  doc  =  (HTMLDocument)htmlKit.createDefaultDocument();
  JScrollPane  s_pan  =  new  JScrollPane(paneArea2);
        JScrollPane  s_pan2  =  new  JScrollPane(paneArea);
      
          private  void  set_Design()  {
    Container  con  =  this.getContentPane();
    con.setLayout(null);
    this.setTitle("Super");
    paneArea.setEditorKit(htmlKit);
    tf_url.setBounds(10,10,380,20);
    test.setBounds(400,  10,  80,  20);
  
      
    paneArea.setPreferredSize(new  Dimension(700,  400));
    /*paneArea.setContentType("text/html");
    htmlKit  =  new  HTMLEditorKit();
    paneArea.setEditorKit(htmlKit);
    StyleSheet  ssh  =  htmlKit.getStyleSheet();
    doc  =  new  HTMLDocument();*/
    //paneArea.setDocument(doc);
    //paneArea.addHyperlinkListener(listener);
    paneArea.setEditable(false);
    /*  이곳은  어느분의  소스에서  긁어  온  부분이라  주석  처리로  돌려  놓았다..
    helpContent  =  new  JEditorPane("text/html",  "");
                HTMLEditorKit  kit  =  new  HTMLEditorKit();
                helpContent.setEditorKit(kit);
                StyleSheet  ssh  =  kit.getStyleSheet();
                ssh.addRule(".menuitem  {  font-family:  Verdana;    }  ");
                ssh.addRule(".menuitem  {  font-weight:  bold;    }  ");
                ssh.addRule(".menuitem  {  color:  #003399;    }  ");
                */
    s_pan2.setBounds(10,40,800,330);
    s_pan.setBounds(10,400,700,200);
    //s_pan2.add(paneArea);
    try  {
      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    }  catch(Exception  ex)  {
      
    }
    
    this.add(tf_url);
    this.add(test);
    //this.add(span);
    this.add(s_pan2);
    this.add(s_pan);
    this.setSize(900,620);
    this.setLocation(100,  100);
    test.addActionListener(this);
    paneArea.addHyperlinkListener(this);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  public  void  hyperlinkUpdate(HyperlinkEvent  ev)  {
    if(ev.getEventType()  ==  HyperlinkEvent.EventType.ACTIVATED)  {
      try  {
        paneArea.setPage(ev.getURL());
      }  catch(Exception  ex)  {}
    }
  }
  public  void  actionPerformed(ActionEvent  ev)  {
    Object  ob  =  ev.getSource();
    if(ob  ==  test)  {
      String  url  =  tf_url.getText();
      show_Tag(url);
    }
  }
  
  private  void  show_Tag(String  url)  {
    try  {
      URL  aURL  =  new  URL(url);
      BufferedReader  br  =  new  BufferedReader(new  InputStreamReader(aURL.openStream()));
      String  line  =  null;
      int  co  =  0;
      String  sb  =  "javascript:show_id_layer(this,'";//      ','
      String  temp  =  null;
      String  u_id  =  null;
      //doc.setBase(aURL);
      paneArea.validate();
      paneArea.updateUI();
      //paneArea.setPage(aURL);
      InputStream  in  =  aURL.openStream();
      paneArea.read(in,  doc);
      System.out.println(aURL.getContent());
      //while(br.readLine()  !=  null)  {  
      //  line  =  br.readLine();
      //  paneArea2.append("\n"  +  line);
        
        
        //co  =  line.indexOf(sb);
        
        /*if(co  >  1)  {
          temp  =  line.substring(co+31);
          u_id  =  temp.substring(0,  temp.indexOf("'"));
          ta.append("u_id  =  "  +  u_id+"\n");
          
        }*/
      //}
    }  catch(MalformedURLException  e)  {
        
    }  catch(IOException  e)  {
        
    }  catch(Exception  ex)  {
      ex.printStackTrace();
      
    }
  }

}

[출처]  JEditorPane과의  전쟁...|작성자  이즈케이
http://blog.naver.com/ind4?Redirect=Log&logNo=10016933425

571 view

4.0 stars