📄 voteserviceclient.java
字号:
// VoteServiceClient.java
// VoteServiceClient display the survey window.
package com.deitel.jws1.jaxrpc.voteclient;
// Java core packages
import java.awt.*;
import java.awt.event.*;
// Java extension packages
import javax.swing.*;
// Java XML packages
import javax.xml.rpc.*;
// client packages
import vote.*;
public class VoteServiceClient extends JFrame
{
// VoteServiceClient constructor
public VoteServiceClient()
{
super( "Vote Service Client" );
// create JButton for getting Vote service
JButton voteButton = new JButton( "Get Vote Service" );
voteButton.addActionListener(
new ActionListener() {
// action for the voteButton
public void actionPerformed( ActionEvent event )
{
String[] languages =
{ "C", "C++", "Java", "VB", "Python" };
String selectedLanguage = ( String )
JOptionPane.showInputDialog(
VoteServiceClient.this,
"Select Language", "Language Selection",
JOptionPane.QUESTION_MESSAGE,
null, languages, "" );
showVotes( selectedLanguage );
} // end method actionPerformed
} // end ActionListener
); // end call to addActionListener
JPanel buttonPanel = new JPanel();
buttonPanel.add( voteButton );
getContentPane().add( buttonPanel, BorderLayout.CENTER );
} // end VoteServiceClient constructor
// connect to Vote Web service and get vote information
public void showVotes( String languageName )
{
// connect to web service and get vote information
try {
// get web service stub
Stub stub = ( Stub )
( new VoteService_Impl().getVotePort() );
// cast stub to service interface
Vote vote = ( Vote ) stub;
// get vote information from web service
VoteBean[] voteBeans = vote.addVote( languageName );
StringBuffer results = new StringBuffer();
results.append( "Vote result: \n" );
// get vote information from voteBeans
for ( int i = 0; i < voteBeans.length ; i++) {
results.append( " "
+ voteBeans[ i ].getLanguageName() + ":" );
results.append( voteBeans[ i ].getCount() );
results.append( "\n" );
}
// display Vote information
JOptionPane.showMessageDialog( this, results );
} // end try
// handle exceptions communicating with remote object
catch ( Exception exception ) {
exception.printStackTrace();
}
} // end method showVotes
// execute VoteServiceClient
public static void main( String args[] )
{
// configure and display application window
VoteServiceClient client = new VoteServiceClient();
client.setDefaultCloseOperation( EXIT_ON_CLOSE );
client.pack();
client.setSize( 250, 65 );
client.setVisible( true );
} // end main
} // end class VoteServiceClient
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -