Minimal.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Minimal CertainTrust Demonstrator in Java
  3. *
  4. * Demonstrates the basic usage of the CertainTrust SDK.
  5. *
  6. * @author Florian Volk <florian.volk@cased.de>
  7. */
  8. import java.awt.FlowLayout;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. import javax.swing.JButton;
  12. import javax.swing.JFrame;
  13. import javax.swing.JOptionPane;
  14. import CertainTrust.CertainTrust;
  15. import CertainTrust.CertainTrustHTI;
  16. public class Minimal extends JFrame implements ActionListener {
  17. private static final long serialVersionUID = -447167281994322634L;
  18. // this object stores the trust data and implements the operators
  19. CertainTrust ctObject;
  20. public Minimal() {
  21. setTitle("Minimal CertainTrust SDK Demonstrator");
  22. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  23. setLayout(new FlowLayout());
  24. // display a single HTI
  25. ctObject = new CertainTrust(10); // first, we need a CertainTrust data object
  26. add(new CertainTrustHTI(ctObject));
  27. // add a button to read the CertainTrust values
  28. JButton button = new JButton("Read CertainTrust values");
  29. button.addActionListener(this);
  30. add(button);
  31. this.setSize(450, 250);
  32. this.setVisible(true);
  33. }
  34. @Override
  35. public void actionPerformed(ActionEvent arg0) {
  36. // whenever the button is clicked
  37. JOptionPane.showMessageDialog(this,
  38. "Values of the CertainTrust object:\n"
  39. + "\nInit. value: " + this.ctObject.getF()
  40. + "\nTrust: " + this.ctObject.getT()
  41. + "\nCertainty: " + this.ctObject.getC()
  42. + "\nExpectation: " + this.ctObject.getExpectation());
  43. }
  44. public static void main(String[] args) {
  45. new Minimal();
  46. }
  47. }