standaloneclient.java

来自「java web services how to program」· Java 代码 · 共 83 行

JAVA
83
字号
// Fig. 11.6: StandaloneClient.java// StandaloneClient is a standalone JAXM application that// uses BookTitlesProxy to invoke the Book Titles Web service.package com.deitel.jws1.jaxm.client;// Java core packagesimport java.awt.*;import java.awt.event.*;// Java extension packagesimport javax.swing.*;// initialize GUI for StandaloneClientpublic class StandaloneClient extends JFrame {   private final static int FRAME_WIDTH = 450;   private final static int FRAME_HEIGHT = 300;   public StandaloneClient( String title )   {      super( title );      // JList to display results from Web-service invocation      final JList resultsList = new JList();      resultsList.setSelectionMode(          ListSelectionModel.SINGLE_SELECTION );      // JButton invokes remote Web service      JButton serviceButton = new JButton( "Invoke Service" );      serviceButton.addActionListener(         new ActionListener() {            // invoked when user presses JButton            public void actionPerformed( ActionEvent event )            {               // invoke Web service and store results in JList               try {                  // invoke Web service via BookTitlesProxy                  BookTitlesProxy service =                      new BookTitlesProxy();                  String response[] = service.getBookTitles();                  // store results in JList                  resultsList.setListData( response );               }               // handle exception in Web-service invocation               catch ( java.io.IOException exception ) {                  exception.printStackTrace();               }            }         }      );      // store JButton on JPanel      JPanel userPanel = new JPanel();      userPanel.add( serviceButton );      // add JList and JPanel to GUI      getContentPane().add( new JScrollPane( resultsList ) );      getContentPane().add( userPanel, BorderLayout.SOUTH );   } // end constructor   // return size of StandaloneClient frame   public Dimension getPreferredSize()   {      return new Dimension( FRAME_WIDTH, FRAME_HEIGHT );   }   // instantiate StandaloneClient GUI   public static void main( String args[] )   {      StandaloneClient client =          new StandaloneClient( "Book Title Service" );      client.setDefaultCloseOperation( EXIT_ON_CLOSE );      client.pack();      client.setVisible( true );   }} // end class StandaloneClient

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?