📄 quitdialog.java
字号:
/* //////////////////////////////////////////////////////////////////////////
QuitDialog.java
-------------------------------------------------------------------------
Copyright (c) 2003
Cisco Systems, Inc.
All rights reserved.
Confidential restricted material. This work contains confidential trade
secrets of Cisco Systems, Inc. Use, examination, copying, transfer and/or
disclosure to others are prohibited, except with the express written
agreement of Cisco Systems, Inc.
The JavaPhone sample is intended to serve as an example of opening an
AgentMode connection to CTIOS for a programmer using the CTIOS JavaCIL
to develop a client application such as an Agent Desktop.
This sample illustrates how to connect to the server, login an agent,
make calls, set a call variable, recieve events and look at their
contents, and other operations.
This is only a sample and is NOT intended to be a production quality
application and will not be supported as such. It is NOT guaranteed to
be bug free. It is merely provided as a guide for a programmer to see
how to establish a AgentMode connection, control an Agent, receive events,
and manipulate Session objects.
///////////////////////////////////////////////////////////////////////// */
import java.awt.*;
import java.awt.event.*;
///////////////////////////////////////////////////////////////////////////
/**
* The <code>QuitDialog</code> is just a Dialog class that is used to
* pop a confirmation dialog to the user in response to requesting to
* quit the app.
*/
///////////////////////////////////////////////////////////////////////////
public class QuitDialog extends Dialog
{
// Used for addNotify check.
protected boolean fComponentsAdjusted = false;
// Reference to main application frame
protected JavaPhoneFrame m_appFrame = null;
// Dialog buttons and message
protected java.awt.Button yesButton = new java.awt.Button();
protected java.awt.Button noButton = new java.awt.Button();
protected java.awt.Label label1 = new java.awt.Label();
public QuitDialog(JavaPhoneFrame parentFrame, boolean modal)
{
super(parentFrame, modal);
//Keep a local reference to the invoking frame
m_appFrame = parentFrame;
setLayout(null);
setSize(337,135);
setVisible(false);
yesButton.setLabel(" Yes ");
add(yesButton);
yesButton.setFont(new Font("Dialog", Font.BOLD, 12));
yesButton.setBounds(72,80,79,22);
noButton.setLabel(" No ");
add(noButton);
noButton.setFont(new Font("Dialog", Font.BOLD, 12));
noButton.setBounds(185,80,79,22);
label1.setText("Do you really want to exit?");
label1.setAlignment(java.awt.Label.CENTER);
add(label1);
label1.setBounds(78,33,180,23);
setTitle("Java CIL Application - Exit");
JavaPhoneWindow rJavaPhoneWindow = new JavaPhoneWindow();
this.addWindowListener(rJavaPhoneWindow);
JavaPhoneAction rJavaPhoneAction = new JavaPhoneAction();
noButton.addActionListener(rJavaPhoneAction);
yesButton.addActionListener(rJavaPhoneAction);
}
///////////////////////////////////////////////////////////////////////////
public void addNotify()
{
// Record the size of the window prior to calling parents addNotify.
Dimension d = getSize();
super.addNotify();
if (fComponentsAdjusted)
return;
// Adjust components according to the insets
setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
Component components[] = getComponents();
for (int i = 0; i < components.length; i++)
{
Point p = components[i].getLocation();
p.translate(getInsets().left, getInsets().top);
components[i].setLocation(p);
}
fComponentsAdjusted = true;
} // addNotify
///////////////////////////////////////////////////////////////////////////
/**
* Shows or hides the component depending on the boolean flag b.
* @param b if true, show the component; otherwise, hide the component.
* @see java.awt.Component#isVisible
*/
///////////////////////////////////////////////////////////////////////////
public void setVisible(boolean b)
{
if(b)
{
Rectangle bounds = getParent().getBounds();
Rectangle abounds = getBounds();
setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
bounds.y + (bounds.height - abounds.height)/2);
Toolkit.getDefaultToolkit().beep();
}
super.setVisible(b);
} // setVisible
///////////////////////////////////////////////////////////////////////////
/**
* Class to handle GUI button events
*/
///////////////////////////////////////////////////////////////////////////
class JavaPhoneAction implements java.awt.event.ActionListener
{
///////////////////////////////////////////////////////////////////////////
/**
* Handler for a button clicked event
*/
///////////////////////////////////////////////////////////////////////////
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object o = event.getSource();
if (o == yesButton)
yesButton_ActionPerformed(event);
else if (o == noButton)
noButton_ActionPerformed(event);
} // GUI Event handler method
} // JavaPhoneAction
///////////////////////////////////////////////////////////////////////////
/**
* Handler for user clicking the "Yes" button
*/
///////////////////////////////////////////////////////////////////////////
void yesButton_ActionPerformed(java.awt.event.ActionEvent event)
{
m_appFrame.Disconnect();
try
{
m_appFrame.setVisible(false); // Hide the invoking frame
m_appFrame.dispose(); // Free system resources
this.dispose(); // Free system resources
System.exit(0); // close the application
}
catch (Exception e)
{
}
} // yesButton_ActionPerformed
///////////////////////////////////////////////////////////////////////////
/**
* Handler for user clicking the "No" button
*/
///////////////////////////////////////////////////////////////////////////
void noButton_ActionPerformed(java.awt.event.ActionEvent event)
{
try
{
this.dispose(); // Free system resources + close window
}
catch (Exception e)
{
}
} // noButton_ActionPerformed
///////////////////////////////////////////////////////////////////////////
/**
* Class to handle Window events
*/
///////////////////////////////////////////////////////////////////////////
class JavaPhoneWindow extends java.awt.event.WindowAdapter
{
///////////////////////////////////////////////////////////////////////////
/**
* Handler for Window Closing event
*/
///////////////////////////////////////////////////////////////////////////
public void windowClosing(java.awt.event.WindowEvent event)
{
Object o = event.getSource();
if (o == QuitDialog.this)
QuitDialog_WindowClosing(event);
} // windowClosing
} // class JavaPhoneWindow
///////////////////////////////////////////////////////////////////////////
/**
* Handler for closing the QuitDialog
*/
///////////////////////////////////////////////////////////////////////////
void QuitDialog_WindowClosing(java.awt.event.WindowEvent event)
{
try
{
this.dispose(); // Free system resources + close window
}
catch (Exception e)
{
}
} // QuitDialog_WindowClosing
} // class QuitDialog
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -