import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import java.awt.Component;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import com.bbdsoft.LicenseEnforcer.BBDLicenseSentry;
import com.bbdsoft.LicenseEnforcer.UDPLicenseSentry;
import com.bbdsoft.LicenseEnforcer.BBDLicenseHandler;
/**
* @author BBD SOFT, UAB
*
* Demo user application with a floating license protection.
* It implements a BBDLicenseHandler interface.
* Let's say our license hash is "John Smith&DEMOLICENSEKEY"
* and only one instance of a program can be run with this license
* (a single user license).
*/
public class Demo extends JDialog
implements ActionListener
, WindowListener
, BBDLicenseHandler
{
// user license name
static String theLicenseName = "John Smith";
// user license key
static String theLicenseKey = "DEMOLICENSEKEY";
// a single user license
static int theLicenseNumber = 1;
// our BBD license sentry
static BBDLicenseSentry aSentry;
JPanel pnMain;
JLabel lbMessageLabel;
JButton btClose;
//------------------------------------------------------------------------------
public static void main( String args[] )
{
new Demo();
} // end main()
//------------------------------------------------------------------------------
public Demo()
{
super();
setTitle("BBD SOFT License-Enforcer DEMO");
pnMain = new JPanel();
lbMessageLabel = new JLabel( "< html>The program is licensed to < b>"
+ theLicenseName
+ "< /b>.< br>License key is < b>"
+ theLicenseKey
+ "< /b>.< br>No more than "
+ theLicenseNumber
+ " instance of this program can be run at a time.< br>"
+ "Try running it on another computer on your LAN.< br>"
+ "< b>Note:< /b> Unlimited number of program instances can be run on the same computer!"
+ "< /html>" );
pnMain.add( lbMessageLabel );
btClose = new JButton( "Close" );
pnMain.add( btClose );
btClose.addActionListener( this );
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(this);
setContentPane( pnMain );
pack();
// create our UDP license sentry
aSentry = new UDPLicenseSentry();
// register our license handler with a license sentry
aSentry.setLicenseHandler(this);
show();
} // end Demo()
//------------------------------------------------------------------------------
public void actionPerformed(ActionEvent arg0)
{
System.exit(0);
}
// Inherited from WindowListener
public void windowOpened(WindowEvent arg0) {}
public void windowClosed(WindowEvent arg0) {}
public void windowIconified(WindowEvent arg0) {}
public void windowDeiconified(WindowEvent arg0) {}
public void windowActivated(WindowEvent arg0) {}
public void windowDeactivated(WindowEvent arg0){}
// Inherited from WindowListener
public void windowClosing(WindowEvent arg0)
{
System.exit(0);
}
//------------------------------------------------------------------------------
// Inherited from BBDLicenseHandler interface
public String getLicenseHash()
{
// Make some unique license hash of license name and key.
return theLicenseName+"&"+theLicenseKey;
}
//------------------------------------------------------------------------------
// Inherited from BBDLicenseHandler interface
public int getLicenseNumber()
{
return theLicenseNumber;
}
//------------------------------------------------------------------------------
// Inherited from BBDLicenseHandler interface
public void lock()
{
JOptionPane.showMessageDialog(
this,
"No more instances with this license can be run. Program will exit...");
System.exit(0);
}
} // end class Demo