📄 booktitleclient.java
字号:
// Fig. 7.14: BookTitleClient.java.
// BookTitleClient uses the WASP API for Java to access the
// Book Title Web service.
package com.deitel.jws1.wsdl.client;
// Java core packages
import java.awt.*;
import java.awt.event.*;
// Java extension packages
import javax.swing.*;
// WASP packages
import org.idoox.webservice.client.WebServiceLookup;
import org.idoox.webservice.client.WebServiceLookupException;
import org.idoox.wasp.Context;
// Deitel packages
import com.deitel.jws1.services.BookTitle;
public class BookTitleClient extends JFrame {
private final static int FRAME_WIDTH = 500;
private final static int FRAME_HEIGHT = 100;
// interface through which to invoke Book Title Web service
private BookTitle service;
// Web-service URL
private final static String SERVICE_URL =
"http://SCARAB:6060/BookTitleService/";
// WSDL-document URL
private final static String WSDL_URL =
"http://SCARAB:6060/BookTitleService/";
public BookTitleClient( String title )
{
super( title );
getContentPane().setLayout( new GridLayout( 2, 2 ) );
// JLabel to display book title from Web-service invocation
final JLabel resultsLabel = new JLabel();
// JComboBox for selecting ISBN to send to Web service
final JComboBox isbnComboBox = new JComboBox();
isbnComboBox.addItem( "0130895601" );
isbnComboBox.addItem( "0130895717" );
isbnComboBox.addItem( "0130293636" );
isbnComboBox.addItem( "0130284173" );
isbnComboBox.addItem( "0130923613" );
// JButton invokes remote Web Service
JButton serviceButton = new JButton( "Get Book Title" );
serviceButton.addActionListener(
new ActionListener() {
// invoked when user presses JButton
public void actionPerformed( ActionEvent event )
{
// use WASP APIs to access Web service
try {
// get object that performs Web-service lookup
WebServiceLookup serviceLookup =
( WebServiceLookup ) Context.getInstance(
Context.WEBSERVICE_LOOKUP );
// lookup Web service from registry
service = ( BookTitle ) serviceLookup.lookup(
WSDL_URL, BookTitle.class, SERVICE_URL );
// invoke Web service
String response = service.getBookTitle(
( String ) isbnComboBox.getSelectedItem() );
resultsLabel.setText( response );
}
// handle exception if unable to find Web service
catch ( WebServiceLookupException exception ) {
exception.printStackTrace();
}
} // end method actionPerformed
}
);
// store JLabel, JComboBox and JButton JFrame
getContentPane().add( new JLabel( "Select ISBN:" ) );
getContentPane().add( isbnComboBox );
getContentPane().add( resultsLabel );
getContentPane().add( serviceButton );
} // end constructor
// return size of BookTitleClient frame
public Dimension getPreferredSize()
{
return new Dimension( FRAME_WIDTH, FRAME_HEIGHT );
}
// instantiate BookTitleClient GUI
public static void main( String args[] )
{
BookTitleClient client =
new BookTitleClient( "Book Title Service" );
client.setDefaultCloseOperation( EXIT_ON_CLOSE );
client.pack();
client.setVisible( true );
}
} // end class BookTitleClient
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -