📄 rafswingclient.java
字号:
/*
* Project: RAFrameRA Resource Adaptor Framework - An example Resource Adaptor
* for Mobicents - the open source JAIN SLEE implementation.
* See www.mobicents.org for more detailed information on Mobicents.
*
* File: RAFSwingClient.java
* Author: Michael Maretzke
* License: Distributable under LGPL license - see terms of license at gnu.org
* Created: 9th August 2005, 10:56
* Version: 1.0
*/
package com.maretzke.raframe.test.client;
import java.io.IOException;
import javax.swing.UIManager;
import javax.swing.JFrame;
import org.apache.log4j.Logger;
import com.maretzke.raframe.stack.RAFStackListener;
import com.maretzke.raframe.stack.RAFStack;
/**
* RAFSwingClient is a graphical version to communicate with the RAFrame resource
* adaptor executed inside the Mobicents JAIN SLEE implementation in a bit more
* convenient way .<br>
* Every input from the command line will be send to the
* resource adaptor. Communication is done via TCP/IP.<br>
*
* @author Michael Maretzke
*/
public class RAFSwingClient extends JFrame implements RAFStackListener {
// the address of the resource adaptor's socket
private final static String REMOTEHOST = "localhost";
private final static int REMOTEPORT = 40000;
// the address of the sending socket
private final static int LOCALPORT = 40001;
private static Logger logger = Logger.getLogger(RAFSwingClient.class);
private RAFStack stack;
public RAFSwingClient() {
// stack initialisation
try {
stack = new RAFStack(LOCALPORT, REMOTEHOST, REMOTEPORT);
stack.addListener(this);
stack.start();
}
catch (IOException ioe) {
logger.error("Caught IOException. Could not create server port! Terminating. " + ioe);
System.exit(1);
}
// UI initialisation
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception cnfe) {}
// NetBeans generated code is called.
initComponents();
// NetBeans generated code was called.
inputField.grabFocus();
setSize(new java.awt.Dimension(600,400));
getRootPane().setDefaultButton(sendBtn);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
id100Btn = new javax.swing.JButton();
id101Btn = new javax.swing.JButton();
id102Btn = new javax.swing.JButton();
cmdInitBtn = new javax.swing.JButton();
cmdAnyBtn = new javax.swing.JButton();
cmdEndBtn = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
inputField = new javax.swing.JTextField();
sendBtn = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
outputArea = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Resource Adapter Framework - Swing Test Client");
jPanel1.setLayout(new java.awt.GridLayout(2, 6));
id100Btn.setText("ID: 100");
id100Btn.setFocusable(false);
id100Btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
id100BtnActionPerformed(evt);
}
});
jPanel2.add(id100Btn);
id101Btn.setText("ID: 101");
id101Btn.setFocusable(false);
id101Btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
id101BtnActionPerformed(evt);
}
});
jPanel2.add(id101Btn);
id102Btn.setText("ID: 102");
id102Btn.setFocusable(false);
id102Btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
id102BtnActionPerformed(evt);
}
});
jPanel2.add(id102Btn);
cmdInitBtn.setText("Command: INIT");
cmdInitBtn.setFocusable(false);
cmdInitBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdInitBtnActionPerformed(evt);
}
});
jPanel2.add(cmdInitBtn);
cmdAnyBtn.setText("Command: ANY");
cmdAnyBtn.setFocusable(false);
cmdAnyBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdAnyBtnActionPerformed(evt);
}
});
jPanel2.add(cmdAnyBtn);
cmdEndBtn.setText("Command: END");
cmdEndBtn.setFocusable(false);
cmdEndBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdEndBtnActionPerformed(evt);
}
});
jPanel2.add(cmdEndBtn);
jPanel1.add(jPanel2);
inputField.setColumns(60);
inputField.setMinimumSize(new java.awt.Dimension(30, 20));
jPanel3.add(inputField);
sendBtn.setText("Send");
sendBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sendBtnActionPerformed(evt);
}
});
jPanel3.add(sendBtn);
jPanel1.add(jPanel3);
getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
outputArea.setEditable(false);
jScrollPane1.setViewportView(outputArea);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
pack();
}
// </editor-fold>//GEN-END:initComponents
private void cmdEndBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdEndBtnActionPerformed
String text;
if (inputField.getText().length() == 0)
text = "END";
else
text = inputField.getText() + " END";
inputField.setText(text);
}//GEN-LAST:event_cmdEndBtnActionPerformed
private void sendBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendBtnActionPerformed
stack.send(inputField.getText());
outputArea.setText(outputArea.getText() + "Send -----> " + inputField.getText() + '\n');
inputField.setText("");
inputField.grabFocus();
}//GEN-LAST:event_sendBtnActionPerformed
private void cmdAnyBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdAnyBtnActionPerformed
String text;
if (inputField.getText().length() == 0)
text = "ANY";
else
text = inputField.getText() + " ANY";
inputField.setText(text);
}//GEN-LAST:event_cmdAnyBtnActionPerformed
private void cmdInitBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdInitBtnActionPerformed
String text;
if (inputField.getText().length() == 0)
text = "INIT";
else
text = inputField.getText() + " INIT";
inputField.setText(text);
}//GEN-LAST:event_cmdInitBtnActionPerformed
private void id101BtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_id101BtnActionPerformed
String text;
if (inputField.getText().length() == 0)
text = "101";
else
text = inputField.getText() + " 101";
inputField.setText(text);
}//GEN-LAST:event_id101BtnActionPerformed
private void id100BtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_id100BtnActionPerformed
String text;
if (inputField.getText().length() == 0)
text = "100";
else
text = inputField.getText() + " 100";
inputField.setText(text);
}//GEN-LAST:event_id100BtnActionPerformed
private void id102BtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_id102BtnActionPerformed
String text;
if (inputField.getText().length() == 0)
text = "102";
else
text = inputField.getText() + " 102";
inputField.setText(text);
}//GEN-LAST:event_id102BtnActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new RAFSwingClient().setVisible(true);
}
});
}
public void onEvent(String incomingData) {
outputArea.setText(outputArea.getText() + "Received -> " + incomingData + '\n' );
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cmdAnyBtn;
private javax.swing.JButton cmdEndBtn;
private javax.swing.JButton cmdInitBtn;
private javax.swing.JButton id100Btn;
private javax.swing.JButton id101Btn;
private javax.swing.JButton id102Btn;
private javax.swing.JTextField inputField;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea outputArea;
private javax.swing.JButton sendBtn;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -