Results 1 to 5 of 5
  1. #1
    nightmare is offline Member
    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0

    Default Web Service Client and GUI

    hi guys.

    I want a little help.
    I write code for a web service client.
    I use dom parser but I have problem with my gui.
    My gui has 2 panels, first is a jlist.
    I want to fill up the jlist with the elements from the xml but I can't fill it
    I store the xml elements into a string array.Is it wrong?
    What I should do, so to pass the data from the string array to jlist?
    in then second panel I try to display the data from the mouse listener of the jlist.
    After many tries, I succeed to display the data with JTextArea but I can't display in columns.
    I want it like this:
    x1
    x2
    x3
    but my code displays these like this:
    x1 x2 x3.
    What I should do?
    Any suggestions?
    Is it better to use something other than a JTextArea?

    Many thanks!!

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: Web Service Client and GUI

    No code = no help.

    What layout managers have you been using?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    nightmare is offline Member
    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0

    Default Re: Web Service Client and GUI

    you are right.

    here, my sample code

    Java Code:
    public class WebServiceClient extends JFrame {
        
        String test1;
        String test2;
        String[] test1_1;
        String[] test1_2;
        JPanel panel_2;
        JList list=new JList();
        int i,counter;
        String link;
        JTextArea label_test1;
        JTextArea label_test2;
       
       
        
        
        public WebServiceClient(){
            
           
             
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setTitle("Web Service Client");
            setResizable(false);
            setSize(600,400);
            setLocationRelativeTo(null);
            
                  
         
            label_test1=new JTextArea();
            label_test2=new JTextArea();
              
            
            panel_2=new JPanel();
            panel_2.setSize(400,400);
            
                   
            String[] labels={"test1","test2"};
            JList list=new JList(labels);
            list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
            JScrollPane panel_1=new JScrollPane(list);
             panel_1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            
            
            JSplitPane splitFrame = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true, panel_1, panel_2);
            
            splitFrame.setOneTouchExpandable(true);
            splitFrame.setDividerLocation(150);
            getContentPane().add(splitFrame);
            
            
            
            
            
        MouseListener mouseListener = new MouseAdapter() {
          public void mouseClicked(MouseEvent mouseEvent) {
            JList theList = (JList) mouseEvent.getSource();
            if (mouseEvent.getClickCount() == 2) {
              int index = theList.locationToIndex(mouseEvent.getPoint());
              if (index >= 0) {
                Object o = theList.getModel().getElementAt(index);
                
                  switch (o.toString())
                          {
                      case "test1":
                           link="...";
                           Parser1(link);
                           
                                      
                           break;
                       
                      case "test2":
                          link="...";
                          Parser1(link);
                          break;
                          
    
                  }
                          
                  }
              }
            }
          
    
    
       private void Parser1(String link) {
                try {
    
        
        
        URL url = new URL(link);
    URLConnection conn = url.openConnection();
    
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(conn.getInputStream());
    
    
    doc.getDocumentElement().normalize();
    
    
    
    NodeList nodes2 = doc.getElementsByTagName("xml");
    
    
    for (int i = 0; i < nodes2.getLength(); i++) {
    Node node = nodes2.item(i);
    
    if (node.getNodeType() == Node.ELEMENT_NODE) {
    Element element = (Element) node;
    
    
    test1=(element.getAttribute("test1").toString());
    test2=(element.getAttribute("test2"));
    
    
    
    label_test1.append(test1.toString());
    panel_2.add(label_test1);
     
           
    
    }
    
    }
    
    } 
    
    catch (Exception e) {
    	e.printStackTrace();
    }
    
    
    }    
                
          
        };
    
         list.addMouseListener(mouseListener);  
             
               
            
        }
        
    
        public void Parser2() {
    try {
    
        URL url = new URL("...");
    URLConnection conn = url.openConnection();
    
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(conn.getInputStream());
    
    
    doc.getDocumentElement().normalize();
    NodeList nodes = doc.getElementsByTagName("xml2");
    
    
    
    for (int i = 0; i < nodes.getLength(); i++) {
    Node node = nodes.item(i);
    
    if (node.getNodeType() == Node.ELEMENT_NODE) {
    Element element = (Element) node;
    
    
    test1_1[i]=getValue("test1_1", element);
    
    
    test1_2[i]=element.getAttribute("test1_2");
    
    }
    }
    } catch (Exception e) {
    	e.printStackTrace();
    }
    }
    
    private static String getValue(String tag, Element element) {
    NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes();
    Node node = (Node) nodes.item(0);
    return node.getNodeValue();
    }
    
         
        
        
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
           WebServiceClient gui_test = new WebServiceClient();
           gui_test.setVisible(true);
           
     
             
            
        }
    
        
    }
    thanks!!

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: Web Service Client and GUI

    The Swing GUI code would have been enough. So basically you are using the default BorderLayout of the frame and FlowLayout of the panel. Have you played around with layout managers yet? If not: you should, because they are responsible for performing the layout. Generally when you build a Swing gui, you apply nested components (JPanels) and different layout managers to get components where you want them to be.

    A Visual Guide to Layout Managers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    nightmare is offline Member
    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0

    Default Re: Web Service Client and GUI

    hi.
    thanks for your reply.

    unfortunately, I don't have experience in layout managers.
    I will read the tutorials from the link.
    thanks.

    Finally, I take the output I want.

    now, the main problem is to display the output of the parser2 into the jlist.

Similar Threads

  1. How to get client ip address from Web Service hosted on OAS 10.1.2
    By l.najm@acteos.com in forum Advanced Java
    Replies: 2
    Last Post: 10-06-2011, 03:47 PM
  2. Unmanaged web service client error
    By nyucebag in forum Other IDEs
    Replies: 0
    Last Post: 03-16-2011, 08:09 AM
  3. web service client
    By uthpalaw in forum Java Servlet
    Replies: 0
    Last Post: 03-30-2010, 07:57 AM
  4. Web service client
    By Tshegofatsom in forum New To Java
    Replies: 1
    Last Post: 09-09-2009, 02:31 PM
  5. Update Web Service Client
    By gio in forum Advanced Java
    Replies: 0
    Last Post: 09-26-2008, 10:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •