?? mainframe.java
字號(hào):
package com.gpdi.www.ws.client;
import java.awt.*;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
import javax.swing.event.*;
import org.apache.axis.wsdl.symbolTable.*;
public class MainFrame extends JFrame {
DynamicInvoker[] invoker = null;
String location = null;
String serviceName = null;
String portName = null;
String operationName = null;
Parameters parameters = null;
JTextField[] txtParameterValues = null;
JPanel contentPane;
Border border1;
BorderLayout borderLayout1 = new BorderLayout();
JPanel paneNorth = new JPanel();
JPanel paneSouth = new JPanel();
JButton btnExit = new JButton();
JButton btnAbout = new JButton();
JButton btnTest = new JButton();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField txtLocation = new JTextField();
JButton btnFind = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
Border border2;
JLabel jLabel4 = new JLabel();
JComboBox comboService = new JComboBox();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JComboBox comboOperation = new JComboBox();
JLabel jLabel7 = new JLabel();
GridBagLayout gridBagLayout1 = new GridBagLayout();
GridLayout gridLayout1 = new GridLayout();
Border border3;
JPanel paneCenter = new JPanel();
GridLayout gridLayoutCenter = new GridLayout();
Border border4;
JTextField txtTimes = new JTextField();
// 測(cè)試模式--選中是傳送的是文件內(nèi)容。不選則說明傳送的是文件或一個(gè)目錄下的所有文件。
JCheckBox chbModel = new JCheckBox("by values");
// 選中說明每個(gè)文件都需要傳送室每臺(tái)服務(wù)器;反之則說明一個(gè)文件只需要傳送到一個(gè)服務(wù)器上即可。
JCheckBox chbAll = new JCheckBox("All Files");
// 是否保存返回的文件標(biāo)記
JCheckBox chb = new JCheckBox("save");
// 當(dāng)用戶選擇的是單個(gè)文件時(shí)的內(nèi)容
String fileContent = "";
// 當(dāng)用戶選擇的是一個(gè)目錄時(shí)里面的所有文件集合
File[] fileList = null;
Collection fileListContent = null;
// 用來標(biāo)識(shí)當(dāng)前發(fā)送的是第幾個(gè)文件.
private static int fileNum;
// Construct the frame
public MainFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
// Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
border1 = BorderFactory.createEmptyBorder(10, 10, 10, 10);
border2 = BorderFactory.createEmptyBorder(5, 5, 5, 5);
border3 = BorderFactory.createEmptyBorder(0, 3, 0, 5);
border4 = BorderFactory.createEmptyBorder(5, 5, 5, 5);
contentPane.setBorder(border2);
contentPane.setMinimumSize(new Dimension(800, 600));
contentPane.setPreferredSize(new Dimension(800, 600));
contentPane.setLayout(borderLayout1);
this.setContentPane(contentPane);
this.setResizable(false);
this.setSize(new Dimension(800, 600));
this.setState(Frame.NORMAL);
this.setTitle("SOAPClient");
paneNorth.setLayout(gridBagLayout1);
paneSouth.setLayout(gridLayout1);
btnExit.setText("Exit");
btnExit.addActionListener(new MainFrame_btnExit_actionAdapter(this));
btnAbout.setText("About");
btnAbout.addActionListener(new MainFrame_btnAbout_actionAdapter(this));
btnTest.setText("Invoke");
btnTest.addActionListener(new MainFrame_btnTest_actionAdapter(this));
jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
jLabel1.setText("Invoke Times:");
jLabel2.setRequestFocusEnabled(true);
jLabel2.setToolTipText("");
jLabel2.setText("");
jLabel3.setToolTipText("");
jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
jLabel3.setText("Concurrent Threads:");
txtLocation.setMinimumSize(new Dimension(350, 22));
txtLocation.setPreferredSize(new Dimension(350, 22));
txtLocation.setText("1");
btnFind.setText("Set Servers");
btnFind.addActionListener(new MainFrame_btnFind_actionAdapter(this));
borderLayout1.setHgap(5);
borderLayout1.setVgap(5);
jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
jLabel4.setText("Service:");
comboService.setMinimumSize(new Dimension(350, 22));
comboService.setPreferredSize(new Dimension(350, 22));
comboService.setEditable(false);
comboService
.addActionListener(new MainFrame_comboService_actionAdapter(
this));
jLabel6.setHorizontalAlignment(SwingConstants.CENTER);
jLabel6.setText("Operation:");
comboOperation.setMinimumSize(new Dimension(350, 22));
comboOperation.setPreferredSize(new Dimension(350, 22));
comboOperation.setEditable(false);
comboOperation
.addActionListener(new MainFrame_comboOperation_actionAdapter(
this));
jLabel5.setText("");
jLabel7.setText("");
gridLayout1.setColumns(7);
gridLayout1.setHgap(10);
paneCenter.setLayout(gridLayoutCenter);
gridLayoutCenter.setColumns(1);
gridLayoutCenter.setHgap(3);
gridLayoutCenter.setRows(1);
gridLayoutCenter.setVgap(3);
paneCenter.setBackground(Color.white);
paneCenter.setBorder(border4);
txtTimes.setText("1");
txtTimes.setHorizontalAlignment(SwingConstants.RIGHT);
paneSouth.add(btnAbout, null);
paneSouth.add(jLabel1, null);
paneSouth.add(txtTimes, null);
paneSouth.add(chb, null);
paneSouth.add(btnTest, null);
paneSouth.add(jLabel2, null);
contentPane.add(paneNorth, BorderLayout.NORTH);
contentPane.add(paneSouth, BorderLayout.SOUTH);
contentPane.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(paneCenter, null);
paneNorth.add(jLabel3, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
0, 0, 3), 30, 9));
paneNorth.add(txtLocation, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 5, 0), 400, 3));
paneNorth.add(btnFind, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
0, 5, 5, 5), 30, 0));
paneNorth.add(jLabel4, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
0, 0, 0), 30, 9));
paneNorth.add(comboService, new GridBagConstraints(1, 1, 2, 1, 1.0,
0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 5, 0), 400, 3));
paneNorth.add(jLabel5, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
0, 0, 1), 50, 25));
paneNorth.add(jLabel6, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
0, 0, 0), 30, 9));
paneNorth.add(comboOperation, new GridBagConstraints(1, 2, 2, 1, 1.0,
0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0), 400, 3));
paneNorth.add(jLabel7, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
0, 0, 1), 50, 25));
paneNorth.add(chbModel, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
0, 5, 5, 5), 30, 0));
paneNorth.add(chbAll, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
0, 5, 5, 5), 30, 0));
paneSouth.add(btnExit, null);
}
// Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void btnExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
void btnAbout_actionPerformed(ActionEvent e) {
MainFrame_AboutBox dlg = new MainFrame_AboutBox(this);
dlg.setVisible(true);
}
void btnFind_actionPerformed(ActionEvent e) {
try {
Collection servers = getServers();
Iterator it = servers.iterator();
System.out.println(servers.size());
invoker = new DynamicInvoker[servers.size()];
int s = 0;
while (it.hasNext()) {
String string = (String) it.next();
invoker[s] = new DynamicInvoker(string);
s++;
System.out.println(string);
}
Vector v = invoker[0].enumServiceNames();
comboService.removeAllItems();
comboOperation.removeAllItems();
serviceName = portName = operationName = null;
if (v.size() == 0) {
JOptionPane.showMessageDialog(this,
"No Service found at this location.", "WARNING",
JOptionPane.WARNING_MESSAGE);
return;
}
Object[] ss = v.toArray();
Arrays.sort(ss);
int len = ss.length;
for (int i = 0; i < len; i++) {
comboService.addItem((String) ss[i]);
}
comboService.setSelectedIndex(0);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getClass().getName() + ": "
+ ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
// by shanben 2007/04/20 讀取服務(wù)器列表.
private Collection getServers() {
Collection result = new ArrayList();
FileReader reader = null;
BufferedReader br = null;
try {
reader = new FileReader("Servers.txt");
br = new BufferedReader(reader);
String str = "";
while ((str = br.readLine()) != null) {
result.add(str);
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
reader.close();
br.close();
} catch (IOException ex1) {
ex1.printStackTrace();
}
}
return result;
}
private String selectEntry(Vector v, String entryName) {
if (v.size() == 0) {
return null;
} else if (v.size() > 1) {
SelectDialog dlg = new SelectDialog(this, entryName, v, "Select a "
+ entryName + " from this list:");
dlg.setVisible(true);
return dlg.result;
} else {
return (String) v.elementAt(0);
}
}
void comboService_actionPerformed(ActionEvent e) {
try {
serviceName = (String) comboService.getSelectedItem();
if (serviceName == null) {
return;
}
Vector v = invoker[0].enumPortNames(serviceName);
portName = selectEntry(v, "Port");
if (portName == null) {
JOptionPane.showMessageDialog(this, "No port found in service "
+ serviceName, "WARNING", JOptionPane.WARNING_MESSAGE);
return;
}
v = invoker[0].enumOperationNames(serviceName, portName);
comboOperation.removeAllItems();
Object[] ss = v.toArray();
Arrays.sort(ss);
int len = ss.length;
for (int i = 0; i < len; i++) {
comboOperation.addItem((String) ss[i]);
}
comboOperation.setSelectedIndex(0);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getClass().getName() + ": "
+ ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
void comboOperation_actionPerformed(ActionEvent e) {
try {
operationName = (String) comboOperation.getSelectedItem();
if (serviceName == null || operationName == null
|| portName == null) {
return;
}
parameters = invoker[0].enumParameters(serviceName, portName,
operationName);
if (parameters == null) {
return;
}
Vector v = parameters.list;
int size = v.size();
if (size == 0) {
paneCenter.removeAll();
gridLayoutCenter.setRows(10);
paneCenter.add(new JLabel("This operation has no parameter."));
} else {
paneCenter.removeAll();
gridLayoutCenter.setRows(Math.max(size, 10));
txtParameterValues = new JTextField[size];
for (int i = 0; i < size; i++) {
Parameter para = (Parameter) v.elementAt(i);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -