2014-05-19 1 views
0

를 확장 나는 식별자가이 토큰 후 예상되는 것을 말한다 "setVerticalScrollBarPolicy"에 구문 오류,내가 (내 GUI 클래스는 JFrame의 확장), 나는 다음과 같은 코드를 사용하여 추가하는 내 GUI에 JTextArea에이 JFrame의

JScrollPane displayOutputScroll = new JScrollPane(displayOutput); 
displayOutputScroll.setVericalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); 

을하지만 : 스크롤 JTextArea에에 바,이 라인을 추가하여이 일을 시도했다.

JScrollPane displayOutputScroll = new JScrollPane(displayOutput, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 

그러나 말한다 컴파일 오류가 얻을 :

나는 대신이 라인으로 스크롤을 추가 노력했다. "생성자가 JScrollPane (JTextArea에, INT가) 정의되지를

수있는 사람이 포인트를 ? 내가 여기 잘못 뭘하는지 나에게 어떻게 JTextArea에에 스크롤 막대를 추가 할 수 있습니다 여기에

내 구이 클래스의 전체 코드, 요청에 따라 :

package openDIS; 

import java.applet.*; 
import java.awt.*; 

import javax.swing.*; 

import java.awt.event.ActionListener; 
import java.awt.event.ActionEvent; 
import java.io.IOException; 
import java.net.UnknownHostException; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 

public class Gui extends JFrame{ 

public static String text = ""; 
public static int rows = 20; 
public static int columns = 5; 
public static JTextArea receivingNetworkInfo = new JTextArea(text, rows, columns); 
public static JTextArea sendingNetworkInfo = new JTextArea(text, rows, columns); 
public static JTextArea displayOutput = new JTextArea(text, rows, columns); 
public static JTextArea displayFilteredOutput = new JTextArea(text, rows, columns); 

/*Add scroll bars to the display areas */ 
JScrollPane displayOutputScroll = new JScrollPane(displayOutput); 
displayOutputScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); 

/*Create a JComboBox to display filter options, and JTextField to allow user to enter filter criteria */ 
public static String[] filterOptions = {"", "Site", "Application", "ID"}; 
public static JComboBox<String> filter1 = new JComboBox<String>(filterOptions); /*Adding the '<String>' parameters to JComboBox got rid of the warnings 29/04/2014 */ 
public static JTextField filter1Text = new JTextField(); 
public static JComboBox filter2 = new JComboBox(filterOptions); 
public static JTextField filter2Text = new JTextField(); 
public static JComboBox filter3 = new JComboBox(filterOptions); 
public static JTextField filter3Text = new JTextField(); 

public static boolean filterButtonClicked; 

/*Create an ExecutorService and then call shutdown in my ActionListener for stop */ 
public static final ExecutorService pool = Executors.newSingleThreadExecutor(); 

public Gui(){ 
    setTitle("DIS Filter"); 
    setSize(1000, 1000); 
    setLocation (10, 10); 
    setDefaultCloseOperation(EXIT_ON_CLOSE); 

    initGui(); 
} 

private void initGui(){ 
    //JFrame frame = new JFrame(); 
    JPanel panel = new JPanel(); 

    this.getContentPane().add(panel); 
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    this.setTitle("DIS Filter"); 
    this.setSize(1400, 1100); 

    EspduSender.initSocket(); 
    panel.setLayout(null); 

    /*Add JTextArea to display receivingNetwork info */ 
    receivingNetworkInfo.setBounds(10, 10,700, 60); 
    panel.add(receivingNetworkInfo); 
    receivingNetworkInfo.setEditable(false); 
    receivingNetworkInfo.setText("Default receiving broadcast address: " + Networks.DEFAULT_BROADCAST_ADDRESS_STRING + "\n" + 
          "Default receiving multicast group: " + Networks.DEFAULT_MULTICAST_GROUP_STRING + "\n" + 
          "Default receiving port: " + Networks.receivePORT); 

    /*Add a JTextArea to display the output DIS information */ 
    displayFilteredOutput.setBounds(10, 80, 700, 450); 
    panel.add(displayFilteredOutput); 
    displayFilteredOutput.setEditable(false); 

    /*Add JTextArea to display sendingNetwork info */ 
    sendingNetworkInfo.setBounds(10, 540, 700, 60); 
    panel.add(sendingNetworkInfo); 
    sendingNetworkInfo.setEditable(false); 
    sendingNetworkInfo.setText("Default sending broadcast address: " + Networks.DEFAULT_BROADCAST_ADDRESS_STRING + "\n" + 
           "Default sending multicast group: " + Networks.DEFAULT_MULTICAST_GROUP_STRING + "\n" + 
           "Default sending PORT: " + Networks.sendPORT); 


    /*Add displayFilteredOutput JTextArea */ 
    displayOutput.setBounds(10, 610, 700, 450); 
    panel.add(displayOutput); 
    displayOutput.setEditable(false); 
    add(panel); 
    //displayOutput.append("hello"); 

    /*The code underneath here will never be reached unless I specify how long to perform this method call for- */ 
    /*Since the receivePdu() method has no 'end' condition- it keeps looping continually until told to stop */ 
    /*Try using a timer to specify how long it should be called for */ 
    long start = System.currentTimeMillis(); 
    long end = start + 60*1000; /* 60 seconds * 1000 ms/sec */  

    /*Move pool ExecutorService to top of class, make it public so that it can be used in EspduReceiver.java (06/05/2014 @ 11:00) */ 
    /*Create an ExecutorService and then call shutdown in my ActionListener for stop */ 
// final ExecutorService pool = Executors.newSingleThreadExecutor(); 

    /*Create 'Quit' button and add it to the panel */ 
    JButton quitButton = new JButton("Quit"); 
    panel.add(quitButton); 
    quitButton.setBounds(1080, 500, 80, 30); /*Set the location of the button in the window, and its size */ 

    quitButton.addActionListener(new ActionListener(){ 
     @Override 
     public void actionPerformed(ActionEvent e){ 
      System.exit(0); 
      pool.shutdown(); 
     } 
    }); 

    setLocationRelativeTo(null); 
    panel.repaint(); 
    setDefaultCloseOperation(EXIT_ON_CLOSE);  

    /*Create 'StartCapture' button and add it to the panel */ 
    JButton startCaptureButton = new JButton("Start"); 
    panel.add(startCaptureButton); 
    startCaptureButton.setBounds(1080, 350, 80, 30); 

    startCaptureButton.addActionListener(new ActionListener(){ 
     public void actionPerformed(ActionEvent e){ 
      Filter.getFilterConditions(); 
      EspduReceiver.startCapture(); 
      EspduReceiver.stopCapture = false; 

      EspduSender.senderThread = new Thread(){ 

       public void run(){ 
        //FilteredPdu.displayFilteredPdu(); 
        /*Need to add a call to stop Filter.retrieveFilteredPdu() before calling the Filter.filterPDUs method (14/05/2014 @ 15:00) */ 
      /*  EspduReceiver.stopCapture = true; /*Setting 'stopCapture' to true will cause the capture to stop when the Filter button is 
                 pressed- use another boolean that will stop the call to Filter.retrieveFilteredPdu()*/ 
      /*  EspduReceiver.pauseCapture = true; 
        Filter.pauseCaptureForFilter(); /*Don't need a call to these two lines */ 
        try { 
         EspduSender.sendPdu(); 
        } catch (IOException e) { 
         // TODO Auto-generated catch block 
         System.out.println("UnknownHostException in call to EspduSender.sendPdu(); from startCaptureButton ActionListener"); 
         e.printStackTrace(); 
        } 
       /* Filter.filterPDUs(); /* Try commenting this line since it's now been added to the invokeLater() method in the main(), at end of 
    *          this class. It is now being called from the Filter.pauseCaptureForFilter() method (14/05/2014 @ 15:40) 
    */ 
       } 
      // EspduSender.senderThread.start(); 
      }; 
      EspduSender.senderThread.start(); 
     } 
    }); 


    /*Create 'StopCapture' button and add it to the panel */ 
    JButton stopCaptureButton = new JButton("Stop"); 
    panel.add(stopCaptureButton); 
    stopCaptureButton.setBounds(1080, 400, 80, 30); 

    stopCaptureButton.addActionListener(new ActionListener(){ 
     @Override 
     public void actionPerformed(ActionEvent e){ 
      EspduReceiver.stopCapture = true; 
     } 
    }); 

    /*Add the filters to the window */ 
    panel.add(filter1); 
    filter1.setBounds(720, 50, 100, 30); 
    panel.add(filter1Text); 
    filter1Text.setBounds(850, 50, 200, 30); 

    panel.add(filter2); 
    filter2.setBounds(720, 90, 100, 30); 
    panel.add(filter2Text); 
    filter2Text.setBounds(850, 90, 200, 30); 

    panel.add(filter3); 
    filter3.setBounds(720, 130, 100, 30); 
    panel.add(filter3Text); 
    filter3Text.setBounds(850, 130, 200, 30); 


    /*Add buttons that will call 'retrieve' functions from Filter.java, and display only the entities that match the filtered 
    * values in the GUI. */ 

    /*Get entities with matching site */ 
    JButton filterButton = new JButton("Filter"); 
    panel.add (filterButton); 
    filterButton.setBounds(900, 400, 80, 30); 

    filterButton.addActionListener(new ActionListener(){ 

     boolean filterButtonClicked = true; 
     @Override 
     public void actionPerformed(ActionEvent e){ 

      FilteredPdu.thread = new Thread(){ 

       public void run(){ 
        //FilteredPdu.displayFilteredPdu(); 
        /*Need to add a call to stop Filter.retrieveFilteredPdu() before calling the Filter.filterPDUs method (14/05/2014 @ 15:00) */ 
      /*  EspduReceiver.stopCapture = true; /*Setting 'stopCapture' to true will cause the capture to stop when the Filter button is 
                 pressed- use another boolean that will stop the call to Filter.retrieveFilteredPdu()*/ 
        EspduReceiver.pauseCapture = true; 
        Filter.pauseCaptureForFilter(); 
       /* Filter.filterPDUs(); /* Try commenting this line since it's now been added to the invokeLater() method in the main(), at end of 
    *          this class. It is now being called from the Filter.pauseCaptureForFilter() method (14/05/2014 @ 15:40) 
    */ 
       } 
      }; 
      FilteredPdu.thread.start(); 
     // EspduReceiver.receiveFilteredPdu(); 
      /*Need to check if there are any PDUs stored in 'entity' arrays first- if there aren't, then add a call to receivePdu() at 
      * the start of this method; if there are, then get the value entered into the text box, and search through the array for 
      * a matching value. */ 

      Filter.numMatchingAppsFound = 0; /*Reset this variable to 0 every time the button is clicked, so that the count doesn't carry over. */ 
      Filter.numMatchingSitesFound = 0; /*Reset this variable to 0 every time the button is clicked, so that the count doesn't carry over. */ 
               /*Reseting these values to 0 here doesn't seem to work for some reason. */ 
      //displayOutput.setText(null); /*Clear the display, so that the user only sees the results from the most recent button press. */ 

      /*Call 'displayFilteredPdu()' method here */ 
     // FilteredPdu.displayFilteredPdu(); 

      /*Get matching site values from Sites ArrayList */ 
      try{ 
       //EspduReceiver.receivePdu(); /*I don't necessarily want to call receivePdu() here */ 
       if(EspduReceiver.entitySite.get(0) == null){ 
       // EspduReceiver.receivePdu(); 
       // Filter.retrieveFilteredSite(Integer.parseInt(filter1Text.getText())); 
        System.out.println("Please enter a Site value. "); 
       } else { 
        /*Need to add code to retrieve value of 'filter1Text */ 
        Filter.retrieveFilteredSite(Integer.parseInt(filter1Text.getText())); 
        //Filter.numMatchingSitesFound++; 
       } 

       if((EspduReceiver.entityApplication.get(0) == null) || (filter2Text.getText() == null)){ 
       // Filter.retrieveFilteredApplication(Integer.parseInt(filter2Text.getText())); 
        System.out.println("Please enter an Application value. "); 
       } else { 
        Filter.retrieveFilteredApplication(Integer.parseInt(filter2Text.getText())); 
        //Filter.numMatchingAppsFound++; 
       } 

       if((EspduReceiver.entity.get(0) == null) || filter3Text.getText() == null){ 
        System.out.println("Please enter an ID value. "); 
       } else { 
        Filter.retrieveFilteredID(Integer.parseInt(filter3Text.getText())); 
       } 

      }catch(Exception ex){ 
       System.out.println("No PDUs have yet been received. You must receive at least one PDU before you can search for a matching site entity. " + ex.toString() + "\n" + 
      "or, you have selected a filter, but not entered a filter value. "); 
      } 

      /*Get matching applications from Application ArrayList. This code doesn't work- try adding it to the existing try/catch block instead 30/04/2014 @ 15:10 
      try{ 
       if(EspduReceiver.entityApplication.get(0) == null){ 
        EspduReceiver.receivePdu(); 
        Filter.retrieveFilteredApplication(Integer.parseInt(filter2Text.getText())); 
       } else { 
        Filter.retrieveFilteredApplication(Integer.parseInt(filter2Text.getText())); 
       } 
      }catch(Exception ex2){ 
       System.out.println("No PDUs have yet been received. You must receive at least one PDU before you can search for a matching application entity. "); 
      } */ 
      displayFilteredOutput.setText("Total number of entities with matching Site value: " + /* Filter.matchingSite.length */ Filter.numMatchingSitesFound + "\n" + 
        " Total number of entities with matching Application value: " + /* Filter.matchingApplication.length */ Filter.numMatchingAppsFound + "\n" + 
        " Total number of entities with matching ID value: " + /* Filter.matchingID.length */ Filter.numMatchingIDsFound); 

      /*Write a method that will only add the filtered PDUs to 'displayFilteredOutput' here, and call that method within these 
      * parenthesis. 01/05/2014 */ 
      //displayFilteredOutput.setText(""); 
     } 
    }); 

} 

public static void main(String[] args){ /* I also have a main in EspduSender.java- probably need to get rid of that one (14/05/2014) */ 
    SwingUtilities.invokeLater(new Runnable(){ 
     @Override 
     public void run(){ 
      Gui gui = new Gui(); 
      gui.setVisible(true); 
     /* if(filterButtonClicked == true){ 
       Filter.filterPDUs(); 
      } */ 

     } 
    }); 
} 




} 
+0

JScrollPane의이 (JTextArea에가, INT가)이 당신이 JScrollPane의를 사용할 수 있습니다 (JTextArea에, INT VSB, INT HSB) ..하지만 예상 식별자의 근본 문제에 도착하기 위해 .. 친절 게시하지 전체 클래스 – Sanjeev

+0

전체 요청에 따라 클래스가 추가되었습니다. – someone2088

답변

0

당신은 어떤 방법에서이 같은 문장을 넣을 수 없습니다

displayOutputScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); 

이동 문제를 해결할 수이 내부 initGUI()을.

편집

대신

displayOutput.setBounds(10, 610, 700, 450); 
panel.add(displayOutput); 

패널에 displayOutputScroll을 추가하려면 패널에 displayOutput를 추가.

displayOutputScroll.setBounds(10, 610, 700, 450); 
panel.add(displayOutputScroll); 
+0

답해 주셔서 고맙습니다. 저는 그 프로그램을 실행했을 때 JTextArea에 스크롤바가 없습니다 ... 왜 그런지 알고 싶습니다. – someone2088

+0

편집 된 답변 – Sanjeev

+0

을 참조하십시오. 대단히 감사합니다. – someone2088