Question subject: JSpeakerPh code got from source forge
Posted: Thu Jun 16, 2011 5:22 am
Joined: Tue Jun 14, 2011 10:25 am Posts: 3 Has thanked: 1 time Have thanks: 0 time
when i run the code below I can't call because I got a mgs that Unknown callChangedEvent....pls help me why this????
Code:
package exa.tel;
/* * JSpeakerPhone.java * * Created on July 14, 2002, 8:38 AM */ import javax.telephony.*; import javax.telephony.events.*; import javax.telephony.media.*; /* * XTAPI JTapi implementation * Copyright (C) 2002 Steven A. Frare * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * @author Steven A. Frare * @version .01 * * This example is derived from the JSoftPhone example. * This is not the simplest way to make a speaker phone with JTapi. For the * simplest speaker phone see the DesktopCall example in the JTapi 1.2 spec. * Source for DesktopCall is also in the XTAPI CVS at: * http://sourceforge.net/projects/xtapi */
// Provider around line 584 public class JSpeakerPhone extends javax.swing.JFrame implements CallObserver {
/** Creates new form JSpeakerPhone */ public JSpeakerPhone() { initComponents(); btnCall.setMnemonic('c'); btnAnswer.setMnemonic('a'); btnHangup.setMnemonic('h'); pack();
java.awt.Rectangle r = getBounds(); setBounds(r); setResizable(false);
/** 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 FormEditor. */ private void initComponents() {//GEN-BEGIN:initComponents jPanel1 = new javax.swing.JPanel(); btn1 = new javax.swing.JButton(); btn2 = new javax.swing.JButton(); btn3 = new javax.swing.JButton(); btn4 = new javax.swing.JButton(); btn5 = new javax.swing.JButton(); btn6 = new javax.swing.JButton(); btn7 = new javax.swing.JButton(); btn8 = new javax.swing.JButton(); btn9 = new javax.swing.JButton(); btnPound = new javax.swing.JButton(); btn0 = new javax.swing.JButton(); btnStar = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); lstLines = new javax.swing.JComboBox(); jPanel9 = new javax.swing.JPanel(); txtPhone = new javax.swing.JTextField(); lblMisc = new javax.swing.JLabel(); jPanel3 = new javax.swing.JPanel(); btnCall = new javax.swing.JButton(); btnAnswer = new javax.swing.JButton(); btnHangup = new javax.swing.JButton(); jPanel4 = new javax.swing.JPanel(); jPanel7 = new javax.swing.JPanel(); lblOrigConnState = new javax.swing.JLabel(); jPanel8 = new javax.swing.JPanel(); lblOrigTConnState = new javax.swing.JLabel(); jPanel5 = new javax.swing.JPanel(); lblConnState = new javax.swing.JLabel(); jPanel6 = new javax.swing.JPanel(); lblTermConnState = new javax.swing.JLabel(); addWindowListener(new java.awt.event.WindowAdapter() {
@Override public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); }
@Override public void windowActivated(java.awt.event.WindowEvent evt) { formWindowActivated(evt); } });
// Take a nap for an arbitrary amount of time and see if we get any events. int timeOut = 0; while (timeOut < 10) { try { Thread.currentThread().sleep(20); timeOut++; } catch (Exception excp) { System.out.println("Event wait error: " + excp.toString()); } }
/** * @param args the command line arguments */ public static void main(String args[]) { JSpeakerPhone o = new JSpeakerPhone(); java.awt.Cursor cursor = o.getCursor(); o.show();
for (int loop = 0; loop < t.length; loop++) { System.out.println(t[loop]); lstLines.insertItemAt(t[loop], loop); } } catch (Exception excp) { javax.swing.JOptionPane.showMessageDialog( this, "Can not get a provider."); } }
/** * Reports all events associated with the Call object. This method passes * an array of CallEv objects as its arguments which correspond to the list * of events representing the changes to the Call object as well as changes * to all of the Connection and TerminalConnection objects associated with * this Call. * <p> * @param eventList The list of Call events. */ public void callChangedEvent(CallEv[] eventList) { if (m_call == null) { bOrig = false; setMVars(eventList[0].getCall()); } //System.out.println("callChangedEvent");
} /** * This assumes you are using a full duplex Service * Provider such as XOpenH323! If not ... */ mtc.useDefaultMicrophone(); mtc.startPlaying(); mtc.useDefaultSpeaker(); mtc.startRecording();
if (bOrig == false) { m_call.addObserver(this); tc = m_connections[0].getTerminalConnections(); m_terminalConnection = tc[0]; Terminal t = m_terminalConnection.getTerminal(); t.addCallObserver(this); }
// We already have the m_terminalConnection var, we now need the // remote terminal connection. Since m_call had to be null for us // to get here we did not place this call. So the remote connection // is the origination connection which is always the first connection // the the m_connections array. tc = m_connections[1].getTerminalConnections(); m_destTerminalConnection = tc[0];
private void setConnectionLabel(boolean orig, int state) { switch (state) { case ConnAlertingEv.ID: if (!orig) { lblConnState.setText("ALERTING"); } else { lblOrigConnState.setText("ALERTING"); } break;
case ConnInProgressEv.ID: if (!orig) { lblConnState.setText("INPROGRESS"); } else { lblOrigConnState.setText("INPROGRESS"); } break;
case ConnConnectedEv.ID: if (!orig) { lblConnState.setText("CONNECTED"); } else { lblOrigConnState.setText("CONNECTED"); } break;
case ConnDisconnectedEv.ID: if (!orig) { lblConnState.setText("DISCONNECTED"); } else { lblOrigConnState.setText("DISCONNECTED"); m_call = null; } break;
case ConnUnknownEv.ID: if (!orig) { lblConnState.setText("UNKNOWN"); } else { lblOrigConnState.setText("UNKNOWN"); m_call = null; } break;
// Connections start out in the IDLE state when they // are created. case ConnCreatedEv.ID: if (!orig) { lblConnState.setText("IDLE"); } else { lblOrigConnState.setText("IDLE"); } break;
@SuppressWarnings("static-access") private void setTerminalConnLabel(boolean orig, int state) { switch (state) { case TermConnActiveEv.ID: if (!orig) { lblTermConnState.setText("ACTIVE"); } else { lblOrigTConnState.setText("ACTIVE"); } break;
case TermConnRingingEv.ID:
if (!orig) { lblTermConnState.setText("RINGING");
/** * Caller ID: * Caller ID in the US comes between the first and second * ring. There is no guarantee that the provider will send * it then so just set the label on every ring. * * Even though XTAPI sends multiple ringing events that is * not within the JTAPI 1.2 spec. and will eventually be * removed. How to get it then? I don't know use a timer * I suppose or implement the phone package which has a * method that can be called to return the current ring * count. */ try { // With the H323 Provider we only get one shot at // grabbing caller id, lets not miss it so wait a moment // and grab it! Thread.currentThread().sleep(100); } catch (Exception e) { } Terminal t = m_terminalConnection.getTerminal(); Address a[] = t.getAddresses();
// For the callers name setTitle(t.getName());
// For the callers phone number lblMisc.setText(a[0].getName()); } else { lblOrigTConnState.setText("RINGING"); } break;
case TermConnDroppedEv.ID: if (!orig) { lblTermConnState.setText("DROPPED"); } else { lblOrigTConnState.setText("DROPPED"); } break;
case TermConnUnknownEv.ID: if (!orig) { lblTermConnState.setText("UNKNOWN"); } else { lblOrigTConnState.setText("UNKNOWN"); } break;
// Terminal Connections start out in the IDLE state when they // are created. case TermConnCreatedEv.ID: if (!orig) { lblTermConnState.setText("IDLE"); } else { lblOrigTConnState.setText("IDLE"); } break;