📄 the autoanswergui.java file.txt
字号:
/*Import required JTAPI classes*/
import javax.telephony.*;
import javax.telephony.events.*;
import javax.telephony.media.*;
import javax.telephony.media.events.*;
import javax.swing.*;
/*Import required swing and awt classes*/
import java.awt.event.*;
import javax.swing.event.*;
import java.awt.*;
/*
This class extends the JFrame class and provides the GUI for the Auto Answer application.
Class:AutoAnswerGUI-GUI for the Auto Answer application
Methods:
buildGUI():Used to create GUI
terminate():Closes the application.
*/
public class AutoAnswerGUI extends JFrame implements ActionListener
{
/*Declaring the GUI variables.*/
Container cont = null;
JButton getProvider_button, onoff_button, addlist_button, removelist_button, exit;
JComboBox lines_combo;
JMenu file_menu;
JMenuItem exit_menuitem;
String audioFilePath = null;
/*Declaring the JTAPI variables.*/
AutoAnswerObserver replyObserver = null;
Provider myprovider = null;
JtapiPeer peer = null;
Terminal terminal = null;
/*
Public constructor takes the title string as parameter.
Public constructor takes the String parameter.
AutoAnswerGUI():
Parameters:
title:Title of window
Return Type:NA
*/
public AutoAnswerGUI(String title)
{
super(title);
setSize(380, 310);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
terminate();
}
});
replyObserver = new AutoAnswerObserver(this);
lines_combo = new JComboBox();
/*
Creating the provider by obtaining the XTAPI implementation of JTAPI.
*/
try
{
peer = JtapiPeerFactory.getJtapiPeer("net.xtapi.XJtapiPeer");
/*
Obtaining the default provider of the selected implementation.
*/
myprovider =peer.getProvider(null);
Terminal []terminals = myprovider.getTerminals();
System.out.println("Terminal"+terminals);
for(int i = 0; i <terminals.length; i++)
{
lines_combo.insertItemAt(terminals[ i], i);
lines_combo.setSelectedIndex(0);
terminal = (Terminal)lines_combo.getSelectedItem();
}
//getProvider_button.setEnabled(false);
}
catch (Exception excp)
{
excp.printStackTrace();
JOptionPane.showMessageDialog(this, "Unable to get the provider.");
}
buildGUI();
setVisible(true);
}
/*
This method is used to build the GUI of the Auto Answer application.
Parameters:NA
Return Value:void
*/
public void buildGUI()
{
cont = getContentPane();
cont.setLayout(null);
cont.setBackground(Color.white);
JLabel label = new JLabel("Select a provider from the given list");
label.setBounds(10,10,380,20);
cont.add(label); lines_combo.setBounds(10,35, 235,20);
lines_combo.addActionListener(this);
cont.add(lines_combo);
onoff_button = new JButton("Start Service");
onoff_button.addActionListener(this);
exit=new JButton("Exit");
exit.setBounds(230, 220, 130, 20);
onoff_button.setBounds(230, 180, 130, 20);
exit.addActionListener(this);
cont.add(onoff_button);
cont.add(exit);
}
/*
This method invokes when end user clicks on any button provided in the user interface.
*/
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == exit)
{
System.exit(0);
}
else if (ae.getSource() == lines_combo)
{
try
{
if (terminal != null)
{
/*
Removing the call observer object associated with that terminal.
*/ terminal.removeCallObserver(replyObserver);
}
/*Instantiate the terminal object.*/
terminal = (Terminal)lines_combo.getSelectedItem();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, "Unable to add the call observer to the selected
terminal.");
}
}
/*
Checking if user clicks the Start Service or Stop Service button.
*/
else if (ae.getSource() == onoff_button)
{
try
{
if (onoff_button.getText().equals("Start Service"))
{
if (terminal == null)
{
JOptionPane.showMessageDialog(this, "Please select a provider.", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
terminal.addCallObserver(replyObserver);
System.out.println("Service Started");
}
else
{
/*
If user clicks the Stop Service button, then remove the call observer from the selected
terminal and set the text of the button to Start Service.
*/ terminal.removeCallObserver(replyObserver);
onoff_button.setText("Start Service");
System.out.println("Service Stopped");
}
}
catch (Exception ex)
{
System.out.println("Exception occurred while add and removing the call observer to
the selected terminal." + ex.toString());
}
}
}
/* Used to terminate the application.
Parameters:NA
Return Value:Void
*/
public void terminate()
{
System.exit(0);
}
/*Main method.*/
public static void main(String[] args)
{
AutoAnswerGUI frame = new A utoAnswerGUI("Auto Answer Application");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -