twitter
rss


   1:  /* 
   2:   * @author  Hariraj
   3:   * Calculate your love by entering your name and the people you have crush upon. 
   4:   * It predicts your relationship with them using FLAMES - Friends, Love, Affection, Marriage, Enemy, SweetHearts.
   5:   * This Love/FLAMES calculator is just a fun game to delight the young and old lovers in the world. 
   6:   * This is for fun, don't take anything serious. Enjoy the Game.
   7:   */
   8:  package com.ll.flames;
   9:   
  10:  import java.applet.Applet;
  11:  import java.awt.Button;
  12:  import java.awt.Color;
  13:  import java.awt.Font;
  14:  import java.awt.Label;
  15:  import java.awt.Rectangle;
  16:  import java.awt.TextField;
  17:  import java.util.ArrayList;
  18:  import java.util.List;
  19:   
  20:  public class FlamesApp extends Applet {
  21:   
  22:      private static final long serialVersionUID = 1L;
  23:      private Label name1Label = null;
  24:      private Label name2Label = null;
  25:      private TextField name1textField = null;
  26:      private TextField name2textField = null;
  27:      private Button calculatebutton = null;
  28:      private Label relationLabel = null;
  29:      private Label headinglabel = null;
  30:      private Label relnlabel = null;
  31:      private Label copyrtLabel = null;
  32:      private Label namesLabel = null;
  33:   
  34:      /**
  35:       * This is the default constructor
  36:       */
  37:      public FlamesApp() {
  38:          super();
  39:      }
  40:   
  41:      /**
  42:       * Calculate relationship.
  43:       * 
  44:       * @return the string
  45:       */
  46:      public String calculateRelationship() {
  47:          List<Character> letterList = new ArrayList<Character>();
  48:          String name1, name2;
  49:          name1 = name1textField.getText().trim().toUpperCase();
  50:          name2 = name2textField.getText().trim().toUpperCase();
  51:          for (int i = 0; i < name1.length(); i++) {
  52:              letterList.add(name1.charAt(i));
  53:          }
  54:          for (int i = 0; i < name2.length(); i++) {
  55:              if (!letterList.contains(name2.charAt(i))) {
  56:                   letterList.add(name2.charAt(i));
  58:              } 
  59:                 
  60:          }
  61:          int matchcnt = letterList.size();
  62:          List<Character> flamesArrayList = new ArrayList<Character>();
  63:          flamesArrayList.add('F');
  64:          flamesArrayList.add('L');
  65:          flamesArrayList.add('A');
  66:          flamesArrayList.add('M');
  67:          flamesArrayList.add('E');
  68:          flamesArrayList.add('S');
  69:          int i = 0;
  70:          int temp = 0;
  71:          if (matchcnt != 0) {
  72:              while (i < 5) {
  73:                  i++;
  74:                  temp = (temp + (matchcnt - 1) % flamesArrayList.size())
  75:                          % flamesArrayList.size();
  76:                  flamesArrayList.remove(temp);
  77:              }
  78:          }
  79:          String output[] = { "FRIENDS", "LOVE", "AFFECTION", "MARRIAGE",
  80:                  "ENEMY", "SWEETHEARTS" };
  81:          String tmpString = "FLAMES";
  82:          int index = tmpString.indexOf(flamesArrayList.get(0));
  83:          return output[index];
  84:      }
  85:   
  86:      /**
  87:       * This method initializes this
  88:       * 
  89:       * @return void
  90:       */
  91:      public void init() {
  92:          namesLabel = new Label();
  93:          namesLabel.setBounds(new Rectangle(5, 195, 357, 23));
  94:          namesLabel.setAlignment(Label.CENTER);
  95:          namesLabel.setForeground(Color.blue);
  96:          namesLabel.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 12));
  97:          namesLabel.setText("");
  98:          copyrtLabel = new Label();
  99:          copyrtLabel.setBounds(new Rectangle(276, 222, 102, 23));
 100:          copyrtLabel.setText("© Lioking Labs");
 101:          relnlabel = new Label();
 102:          relnlabel.setBounds(new Rectangle(89, 222, 181, 23));
 103:          relnlabel.setForeground(new Color(51, 150, 51));
 104:          relnlabel.setAlignment(Label.CENTER);
 105:          relnlabel.setText("");
 106:          headinglabel = new Label();
 107:          headinglabel.setBounds(new Rectangle(101, 5, 156, 23));
 108:          headinglabel.setForeground(Color.red);
 109:          headinglabel.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 12));
 110:          headinglabel.setText("FLAMES CALCULATOR");
 111:          relationLabel = new Label();
 112:          relationLabel.setBounds(new Rectangle(6, 169, 360, 22));
 113:          relationLabel.setForeground(Color.red);
 114:          relationLabel.setAlignment(Label.CENTER);
 115:          relationLabel.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 12));
 116:          relationLabel.setText("");
 117:          name2Label = new Label();
 118:          name2Label.setBounds(new Rectangle(16, 96, 113, 23));
 119:          name2Label.setText("Enter Name 2 :");
 120:          name1Label = new Label();
 121:          name1Label.setBounds(new Rectangle(17, 41, 112, 23));
 122:          name1Label.setText("Enter Name 1 :");
 123:          this.setLayout(null);
 124:          this.setSize(380, 255);
 125:   
 126:          this.setBackground(Color.white);
 127:          this.add(name1Label, null);
 128:          this.add(name2Label, null);
 129:          this.add(getName1textField(), null);
 130:          this.add(getName2textField(), null);
 131:          this.add(getCalculatebutton(), null);
 132:          this.add(relationLabel, null);
 133:          this.add(headinglabel, null);
 134:          this.add(relnlabel, null);
 135:          this.add(copyrtLabel, null);
 136:          this.add(namesLabel, null);
 137:      }
 138:   
 139:      /**
 140:       * This method initializes name1textField
 141:       * 
 142:       * @return java.awt.TextField
 143:       */
 144:      private TextField getName1textField() {
 145:          if (name1textField == null) {
 146:              name1textField = new TextField();
 147:              name1textField.setBounds(new Rectangle(149, 42, 159, 29));
 148:          }
 149:          return name1textField;
 150:      }
 151:   
 152:      /**
 153:       * This method initializes name2textField
 154:       * 
 155:       * @return java.awt.TextField
 156:       */
 157:      private TextField getName2textField() {
 158:          if (name2textField == null) {
 159:              name2textField = new TextField();
 160:              name2textField.setBounds(new Rectangle(147, 91, 160, 29));
 161:          }
 162:          return name2textField;
 163:      }
 164:   
 165:      /**
 166:       * This method initializes calculatebutton
 167:       * 
 168:       * @return java.awt.Button
 169:       */
 170:      private Button getCalculatebutton() {
 171:          if (calculatebutton == null) {
 172:              calculatebutton = new Button();
 173:              calculatebutton.setBounds(new Rectangle(105, 129, 149, 32));
 174:              calculatebutton.setLabel("Calculate Relationship");
 175:              calculatebutton
 176:                      .addMouseListener(new java.awt.event.MouseListener() {
 177:                          public void mouseClicked(java.awt.event.MouseEvent e) {
 178:                              String relation = calculateRelationship();
 179:                              relationLabel.setText("RelationShip between ");
 180:                              namesLabel.setText(name1textField.getText().trim()
 181:                                      + " and " + name2textField.getText().trim()
 182:                                      + " is ");
 183:                              relnlabel.setText(relation);
 184:                          }
 185:   
 186:                          public void mousePressed(java.awt.event.MouseEvent e) {
 187:                          }
 188:   
 189:                          public void mouseReleased(java.awt.event.MouseEvent e) {
 190:                          }
 191:   
 192:                          public void mouseEntered(java.awt.event.MouseEvent e) {
 193:                          }
 194:   
 195:                          public void mouseExited(java.awt.event.MouseEvent e) {
 196:                          }
 197:                      });
 198:          }
 199:          return calculatebutton;
 200:      }
 201:   
 202:  }

0 comments:

Post a Comment