2012-06-18 4 views
1

알았습니다. 이에 대한 많은 질문과 답변을 알고 있지만 실제로는 그 중 어떤 것에도 행운이 없었습니다. 나 또한 여러 외부 라이브러리 (jar 파일)를 사용하는 다중 클래스, 다중 패키지 프로그램을 가지고있다. 내 프로젝트를 jar 파일로 내보냈습니다. 아래는 필요한 라이브러리와 jar 파일을 참조하는 "index.html"입니다. 그 모든 파일은 같은 디렉토리에 넣어하고 난 내 웹 페이지에 애플릿을 볼 수 http://easlnx01.eas.muohio.edu/~whitetc2/Twitter%20Mining%202/애플릿이 브라우저에서 작동하지 않습니다.

<html> 
<head> 
<title>Java Example</title> 
</head> 

<body> 
<center> 
This is my page<br> 
Below you see an applet<br> 
<br> 
<applet codebase ="." code="main.BasicGUI.class" 
    archive="twitter.jar, jsch-0-1.1.48.jar, twitter4j-core-2.2.5.jar, sftp.jar" 
    height="600" width="450"/> 
</applet> 
</center> 
</body> 
</html> 

내 주요 클래스 (BasicGUI.java)는 JApplet에를 확장하고 입력을 기반으로 다른 클래스의 다양한 호출합니다. 공개 무효 init()도 있습니다. 아무도 이것이 왜 완전히 작동하지 않는지 말해 줄 수 있습니까? 다음은 업로드 된 내 사이트에 대한 링크입니다. http://easlnx01.eas.muohio.edu/~whitetc2/Twitter%20Mining%202/

애플릿이 표시되지만 파일 탭의 옵션 패널은 작동하지 않으며 프로그램 자체가 실제로 작동하지 않습니다.

package main; 

import javax.swing.*; 
import javax.swing.event.ListSelectionEvent; 
import javax.swing.event.ListSelectionListener; 
import javax.swing.JApplet; 

import com.jscape.inet.sftp.SftpException; 

import Twitter.SearchTweets; 
import java.awt.*; 
import java.awt.event.*; 
import java.io.File; 
import java.io.IOException; 
import java.io.OutputStream; 
import java.io.PrintStream; 

/** 
* The GUI for our Twitter Widget. Plans are to eventually 
* set this up with a Java Applet to run straight from the 
* CC teams website. 
* @author Taylor White and Alex Meyer 
*/ 
public class BasicGUI extends JApplet{ 

    //Auto-generated 
    private static final long serialVersionUID = 1L; 

    //Aesthetic options, have getters and setters to allow for communication across GUIs 
    private static int opposite; 
    private static int maxTweets = 100; 
    private static boolean sortByLocation = false; 
    private static boolean isOptionsOpen = false; 

    // Options GUI, initiated here to avoid multiple open windows 
    //private OptionsGUI options; 

    // Initialize all swing objects. 
    private JPanel northSubPnl1; 
    private JPanel northSubPnl2; 
    private JPanel northSubPnl3; 
    private JPanel northPnl; 
    private JPanel eastPnl; 
    private JPanel westPnl; 
    private JLabel myQuery; 

    /** TWITTER INITILIAZATIONS **/ 
    private static Twitter.TwitterDataList tweets; 
    /** END TWITTER INITIALIZATIONS **/ 

    // Buttons 
    private JButton queryBtn; // Submits the query 
    private JButton uploadBtn; 

    // TextField Query 
    private JTextField txtQuery; // USER Query 

    // Menu 
    private JMenuBar mb; // Menu bar 
    private JMenu mnuFile; // File Entry on Menu bar 
    private JMenuItem mnuFileOpen; 
    private JMenuItem mnuFileSave; 
    private JMenuItem mnuFileOptions; 
    private JMenuItem mnuItemQuit; // Quit sub item 
    private JMenu mnuHelp; // Help Menu entry 
    private JMenuItem mnuItemAbout; // About Entry 

    //West Panel stuff 
    private static JList list; 
    private JScrollPane listScroller; 
    private JLabel uploadText; 
    private JCheckBox uploadHTML; 
    private JCheckBox uploadXML; 
    private JCheckBox uploadJSON; 

    //East Panel stuff 
    private JTextArea user; 
    private static JTextArea sysStatus; 
    private JScrollPane statusScroll; 
    private static JTextArea settings; 
    private static String keywords; 

    /* 
    * Getters and setters for aesthetic options 
    */ 
    public static boolean isSortedByLocation() { 
     return sortByLocation; 
    } 

    public static void setSortedByLocation(boolean toSort) { 
     sortByLocation = toSort; 
    } 

    public static int getMaxTweets() { 
     return maxTweets; 
    } 

    public static void setMaxTweets(int num) { 
     maxTweets = num; 
    } 

    public static boolean isOptionsOpen() { 
     return isOptionsOpen; 
    } 

    public static void setOptionsOpen(boolean option) { 
     isOptionsOpen = option; 
    } 

    /* 
    * CONSTRUCTOR 
    */ 
    public void init() { 
     sysStatus = new JTextArea (1, 20); 
     sysStatus.setEditable(false); 
     northSubPnl1 = new JPanel(); 
     northSubPnl2 = new JPanel(); 
     northSubPnl3 = new JPanel(); 
     northPnl = new JPanel(); 
     eastPnl = new JPanel(); 
     westPnl = new JPanel(); 
     myQuery = new JLabel ("You have no queries yet"); 

     // TwitterDataList 
     tweets = new Twitter.TwitterDataList(); 

     // Buttons 
     queryBtn = new JButton("Submit Query"); // Submits the query 
     uploadBtn = new JButton("Upload Tweets"); // Uploads both XML and HTML files. 

     // TextField Query 
     txtQuery = new JTextField(); // USER Query 

     // Menu 
     mb = new JMenuBar(); // Menu bar 
     mnuFile = new JMenu("File"); 
     mnuFileOpen = new JMenuItem("Open"); 
     mnuFileSave = new JMenuItem("Save"); 
     mnuFileOptions = new JMenuItem("Options"); 
     mnuItemQuit = new JMenuItem("Quit"); 
     mnuHelp = new JMenu("Help"); 
     mnuItemAbout = new JMenuItem("About"); 

     //West Panel stuff 
     String[] tweetsString = new String[2000]; 
     list = new JList (tweetsString); 
     uploadText = new JLabel("Upload as:"); 
     uploadHTML = new JCheckBox("HTML", false); 
     uploadXML = new JCheckBox("XML", false); 
     uploadJSON = new JCheckBox("JSON", false); 

     //East Panel stuff 
     user = new JTextArea("Username: "); 
     keywords = new String(); 
     statusScroll = new JScrollPane(sysStatus); 
     statusScroll.setPreferredSize(new Dimension(200, 150)); 
     statusScroll.getVerticalScrollBar().setValue(statusScroll.getVerticalScrollBar().getMaximum()); 
     settings = new JTextArea(1, 20); 


     // Set menu bar 
     this.setJMenuBar(mb); 

     //Build Menus 
     this.buildMenus(); 
     // West Panel 
     this.westPnlSetup(); 
     // East Panel 
     this.eastPnlSetup(); 
     // Add objects to respective panels 
     this.northPnlSetup(); 
     // Setup Main Frame 
     this.setLayout(); 
     // Add Listeners 
     this.addListeners(); 

     //Finish Launch 
     Toolkit toolkit = Toolkit.getDefaultToolkit(); 
     Dimension dim = toolkit.getScreenSize(); 
     int width = (int)dim.getWidth(); 
     int height = (int)dim.getHeight();;      //worry about location later. This is fine for testing purposes 
     this.setBounds(width/2-400, height/2-400, 500, 800); //Arbitrarily chosen for a 1600 by 900 screen 
     this.setVisible(true); 
    } 

    public class ButtonListener implements ActionListener { 
     public void actionPerformed(ActionEvent e) { 
      if (e.getSource() == queryBtn) {   
       if (txtQuery.getText().length() > 2) { 
        myQuery.setText("Your current query: " + txtQuery.getText()); 
        tweets = Twitter.SearchTweets.customSearch(txtQuery.getText()); // SEARCH 
        if (SearchTweets.getKeywords() != null) { 
         if (tweets.getSize() > 0) 
          tweets = Twitter.SearchTweets.sortByKeyword(tweets, SearchTweets.getKeywords()); // Sort right after. 
         else { 
          print("No tweets found!"); 
          System.out.println("No tweets found!"); 
         } 
        } 
        if (tweets.getSize() > 0) { 
         list.setListData(tweets.toArray(maxTweets)); 
         sysStatus.append("Top Tweet: " + tweets.get(0).getTweet()); 
         System.out.println("Top Tweet: " + tweets.get(0).getTweet()); 
         //tweets.saveHTML(txtQuery.getText()); NOT SAVING BY DEFAULT ANY MORE 
        } 
        else { 
         print("No tweets found!"); 
         System.out.println("No tweets found!"); 
        } 
       } 
       else { 
        print("Please input at least a 3 letter word to begin a query."); 
        System.out.println("Please input at least a 3 letter word to begin a query."); 
       } 
      } 

      // Not sure how to make directory path independent of system. change path to your local project to get open and save to work 
      else if (e.getSource() == mnuFileOpen) { 
       final JFileChooser fc = new JFileChooser("C:/Users/Meyer/Desktop/YATE/DataCollection"); 
       int returnVal = fc.showOpenDialog(mnuFile); 
       if (returnVal == JFileChooser.APPROVE_OPTION) { 
        File file = fc.getSelectedFile(); 
        tweets = Twitter.TwitterDataList.load(file.getName()); 
        if (SearchTweets.getKeywords() != null) { 
         tweets = Twitter.SearchTweets.sortByKeyword(tweets, SearchTweets.getKeywords()); 
        } 
        list.setListData(tweets.toArray(maxTweets)); 
        myQuery.setText("Your current query: " + file.getName()); 
       } 
      } 

      else if (e.getSource() == mnuFileSave) { 
       final JFileChooser fc = new JFileChooser("C:/Users/Meyer/Desktop/YATE/DataCollection"); 
       int returnVal = fc.showSaveDialog(mnuFile); 
       if (returnVal == JFileChooser.APPROVE_OPTION) { 
        File file = fc.getSelectedFile(); 
        tweets.writeHTML(file.getName()); 
       } 
      } 

      else if (e.getSource() == mnuFileOptions) { 
       if (!isOptionsOpen()) { 
        new OptionsGUI(); 
        setOptionsOpen(true); 
       }   
      } 

      else if (e.getSource() == uploadBtn) { 
       if (uploadHTML.isSelected() || 
         uploadXML.isSelected() || uploadJSON.isSelected()) { 
        try { 
         tweets.saveAll(txtQuery.getText(), uploadHTML.isSelected(), 
           uploadXML.isSelected(), uploadJSON.isSelected()); 
        } catch (SftpException exception) { 
         System.out.println("Could not upload. Try another time."); 
         print("Could not upload. Try another time."); 
        } 
       } 
       else if (tweets.getSize() ==0) { 
        JOptionPane.showMessageDialog(null, "There are no tweets to upload!"); 
       } 
       else { 
        JOptionPane.showMessageDialog(null, "You need to select a file type in order to upload."); 
       } 
      } 
     } 
    } 

    public class KeyChecker implements KeyListener { 
     public void keyPressed(KeyEvent e) { 
      if (e.getKeyCode() == KeyEvent.VK_ENTER) 
       queryBtn.doClick(); 
     } 

     public void keyReleased(KeyEvent arg0) { 
      //ignore 
     } 

     public void keyTyped(KeyEvent arg0) { 
      //ignore 
     } 
    } 

    public class ListListener implements ListSelectionListener { 
     public void valueChanged(ListSelectionEvent e) {  
      try { 
       user.setText(tweets.get(list.getSelectedIndex()).toString()); 
      } catch (ArrayIndexOutOfBoundsException error) { 
       user.setText(tweets.get(list.getFirstVisibleIndex()).toString()); 
      } 
     } 
    } 

    public class ListenMenuQuit implements ActionListener{ 
     public void actionPerformed(ActionEvent e){ 
      System.exit(0);   
     } 
    } 

    public class ListenCloseWdw extends WindowAdapter{ 
     public void windowClosing(WindowEvent e){ 
      System.exit(0);   
     } 
    } 

    public void buildMenus() { 
     mnuFile.add(mnuFileOpen); 
     mnuFile.add(mnuFileSave); 
     mnuFile.add(mnuFileOptions); 
     mnuFile.add(mnuItemQuit); // Create Quit line 
     mnuHelp.add(mnuItemAbout); // Create About line 
     mb.add(mnuFile);  // Add Menu items to form 
     mb.add(mnuHelp); 
    } 


    /** 
    * North Panel 
    */ 
    public void northPnlSetup() { 
     northPnl.setLayout(new BoxLayout (northPnl, BoxLayout.Y_AXIS)); 
     northSubPnl1.add(txtQuery); 
     northSubPnl1.add(queryBtn); 
     txtQuery.setColumns(20); 
     northPnl.add(northSubPnl1); 

    } 
    /** 
    * Sets Layout of GUI 
    */ 

    public void setLayout() { 
     // Setup Main Frame 
     this.getContentPane().setLayout(new BorderLayout()); 
     this.getContentPane().add(northPnl, BorderLayout.NORTH); 
     this.getContentPane().add(westPnl, BorderLayout.WEST); 
     this.getContentPane().add(eastPnl, BorderLayout.EAST); 
    } 

    /* 
    * Adds action listeners  
    */ 
    public void addListeners(){ 
     mnuItemQuit.addActionListener(new ListenMenuQuit()); 
     mnuFileOpen.addActionListener(new ButtonListener()); 
     mnuFileSave.addActionListener(new ButtonListener()); 
     mnuFileOptions.addActionListener(new ButtonListener()); 
     queryBtn.addActionListener(new ButtonListener()); 
     uploadBtn.addActionListener(new ButtonListener()); 
     list.addListSelectionListener(new ListListener()); 
     txtQuery.addKeyListener(new KeyChecker()); 

    } 

    public void westPnlSetup() { 
     westPnl.add(new JLabel ("Tweets")); 
     westPnl.add(new JLabel("-------")); 
     westPnl.setLayout(new BoxLayout (westPnl, BoxLayout.Y_AXIS)); 
     listScroller = new JScrollPane(list); 
     listScroller.setPreferredSize(new Dimension(200, 100)); 
     list.setListData(tweets.toArray(maxTweets)); 
     list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); 
     list.setLayoutOrientation(JList.VERTICAL); 
     list.setVisibleRowCount(10); 
     westPnl.add(listScroller); 
     // setup upload button and panel for check boxes 
     northSubPnl2.setLayout(new BoxLayout(northSubPnl2, BoxLayout.Y_AXIS)); 
     northSubPnl2.add(uploadBtn); 
     uploadBtn.setAlignmentX(CENTER_ALIGNMENT); 
     northSubPnl2.add(uploadText); 
     uploadText.setAlignmentX(CENTER_ALIGNMENT); 
     northSubPnl2.add(northSubPnl3); 
     // setup check boxes 
     northSubPnl3.setLayout(new BoxLayout(northSubPnl3, BoxLayout.X_AXIS)); 
     northSubPnl3.add(uploadHTML); 
     northSubPnl3.add(uploadXML); 
     northSubPnl3.add(uploadJSON); 
     westPnl.add(northSubPnl2); 
    } 

    public void eastPnlSetup() { 
     eastPnl.setLayout(new BoxLayout (eastPnl, BoxLayout.Y_AXIS)); 
     eastPnl.add(new JLabel("Metadata")); 
     eastPnl.add(new JLabel("-------")); 
     user = new JTextArea(1, 20); 
     user.setPreferredSize(new Dimension (200,50)); 
     user.setEditable(false); 
     user.append("User: \n"); 
     user.append("Date: \n"); 
     user.append("Location: \n"); 
     user.append("Relevance: \n"); 
     user.append("Tweet: "); 
     user.setWrapStyleWord(true); 
     user.setLineWrap(true); 
     eastPnl.add(user); 
     eastPnl.add(new JLabel("Settings")); 
     eastPnl.add(new JLabel(new JLabel("-------").getText())); 
     String keywords = ""; 
     for (int i = 0; i < SearchTweets.getKeywords().size(); i++) { 
      keywords = SearchTweets.getKeywords().get(i) + ", "; 
     } 
     try { 
      keywords = keywords.substring(0, keywords.length()-2); 
     } catch (StringIndexOutOfBoundsException e) { 
      keywords = ""; // There are no keywords if this happens. 
     } 

     /* 
     * || THIS IS IF IN WHITE || 
     * ||      || 
     * VV      VV 
     */ 
     settings.setPreferredSize(new Dimension (200,50)); 
     settings.setEditable(false); 
     BasicGUI.setSettingsPaneValues(); 
     settings.setWrapStyleWord(true); 
     settings.setLineWrap(true); 
     eastPnl.add(settings); 

     sysStatus.append(">"); 
     eastPnl.add(new JLabel("System Status  ")); 
     eastPnl.add(new JLabel(new JLabel("-------").getText()+"----")); 
     sysStatus.setWrapStyleWord(true); 
     sysStatus.setLineWrap(true); 
     eastPnl.add(statusScroll); 
     //this.redirectSystemStreams(); // REDIRECTS the text of console to the sysStatus box. NOT REAL TIME. 

     /* END WHITE */ 
    } 


    public static void setSettingsPaneValues() { 
     keywords = new String(); 
     for (int i = 0; i < SearchTweets.getKeywords().size(); i++) { 
      keywords += SearchTweets.getKeywords().get(i) + ", "; 
     } 
     if (SearchTweets.getKeywords().size()== 0) { 
      keywords = "none"; 
     } 
     else { 
      try { 
       keywords = keywords.substring(0, keywords.length()-2); 
      } catch (StringIndexOutOfBoundsException e) { 
       keywords = ""; // There are no keywords if this happens. 
      } 
     } 

     settings.setText("Sort by location: " + isSortedByLocation() + 
       "\nTimeout (in seconds): " + SearchTweets.getTimeout() + 
       "\nMaximum tweets shown: " + getMaxTweets() + 
       "\nKeywords: " + keywords); 
     if (SearchTweets.getKeywords() != null && tweets.getSize() > 0) { 
      tweets = Twitter.SearchTweets.sortByKeyword(tweets, SearchTweets.getKeywords()); 
     } 
     list.setListData(tweets.toArray(maxTweets)); 
     list.repaint(); 
    } 


    /** 
    * returns string value of the keywords used 
    * @return returns instance variable keywords 
    * @author Taylor 
    */ 
    public static String getKeywords() { 
     return keywords; 
    } 
    /** 
    * Updates the sysStatus textArea 
    * @param text 
    */ 
    private void updateTextArea(final String text) { 
     SwingUtilities.invokeLater(new Runnable() { 
      public void run() { 
       opposite++; 
       opposite = opposite%2; 
       if (!text.equalsIgnoreCase(".")){ // So I can do the ". . ." sequence to signify waiting. 
        if (opposite%2 == 1) { 
         sysStatus.append("\n>" + text); 
        } 
        else sysStatus.append(text); 
       } 
       else sysStatus.append(text); 
      } 
     }); 
    } 


    /** 
    * Allows other classes to print to sysStatus 
    */ 
    public static void print (String text) { 
     opposite++; 
     opposite = opposite%2; 
     if (!text.equalsIgnoreCase(".")){ // So I can do the ". . ." sequence to signify waiting. 
      //if (opposite%2 == 1) { 
      sysStatus.append("\n\n>" + text); 
      sysStatus.repaint(); 
      //} 
      //else sysStatus.append("\n" + text); 
     } 
     else sysStatus.append(text); 

     sysStatus.invalidate(); 
     sysStatus.repaint(); 
    } 

    /** 
    * Redirects all console output to the textarea. 
    */ 
    @SuppressWarnings("unused") 
    private void redirectSystemStreams() { 
     OutputStream out = new OutputStream() { 
      @Override 
      public void write(int b) throws IOException { 
       updateTextArea(String.valueOf((char) b)); 
      } 

      @Override 
      public void write(byte[] b, int off, int len) throws IOException { 
       updateTextArea(new String(b, off, len)); 
      } 

      @Override 
      public void write(byte[] b) throws IOException { 
       write(b, 0, b.length); 
      } 
     }; 

     System.setOut(new PrintStream(out, true)); 
     System.setErr(new PrintStream(out, true)); 
    } 
} 
+0

호출을 확인합니다. –

+0

방금 ​​추가했습니다. 감사합니다. 그것은 정상에 실제로 있었다. 그리고 나는 그것을 아래로 움직였다. –

답변

2

시작 여기 :

Exception in thread "AWT-EventQueue-2" java.lang.AssertionError: java.lang.reflect.InvocationTargetException 
    at twitter4j.TwitterFactory.<clinit>(TwitterFactory.java:76) 
    ... 
Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    ... 42 more 
Caused by: java.lang.ExceptionInInitializerError 
    at twitter4j.internal.http.HttpClientWrapper.<init>(HttpClientWrapper.java:48) 
    ... 47 more 
Caused by: java.security.AccessControlException: access denied 
     (java.util.PropertyPermission twitter4j.http.httpClient read) 
    at java.security.AccessControlContext.checkPermission(Unknown Source) 
    at java.security.AccessController.checkPermission(Unknown Source) 

는 일반적으로 애플릿은 제한적인 보안 샌드 박스에서 작동

여기 내 주요 BasicGUI.java 클래스입니다. 모든 속성을 가져 오거나 사이트 전체에 접근하려면 애플릿이 사용자가 디지털 서명하고 최종 사용자가 신뢰할 수 있어야합니다 ('확인을 누르면 확인').

일반 팁 : Java 콘솔이 때 애플릿로드를 팝업하는

  1. 구성. 당신은 순간에 '날지 못한다'고합니다.
  2. 깨진 코드의 경우, 그 모든 캐치 내가 링크가없는 생각 Throwable.printStackTrace();
+0

와우는 무엇이 오류인지를 알기 좋습니다. 그래서 내 문제를 해결할 수있는 '내 앱에 서명'한다면? 우리는 온라인으로 장님 비행을한다는 것을 알고 있었는데, 콘솔을 볼 수있는 방법을 알 수 없었습니다. 그렇게 할 수있는 방법이 있습니까? 내 자신의 PrintStream을 만들고 콘솔 출력을 리디렉션하려고했지만 작동하지 않았습니다. –

+0

나는 대답을 얻을 것이라고 생각했다. 앤드류 감사합니다. –

관련 문제