Example #1
0
 /**
  * Gets the list of the vnmrj users(operators) for the current unix user logged in
  *
  * @return the list of vnmrj users
  */
 protected Object[] getOperators() {
   String strUser = System.getProperty("user.name");
   User user = LoginService.getDefault().getUser(strUser);
   ArrayList<String> aListOperators = user.getOperators();
   if (aListOperators == null || aListOperators.isEmpty())
     aListOperators = new ArrayList<String>();
   Collections.sort(aListOperators);
   if (aListOperators.contains(strUser)) aListOperators.remove(strUser);
   aListOperators.add(0, strUser);
   return (aListOperators.toArray());
 }
Example #2
0
 void placeOrder(final User user, String cmd, Company comp, int qty, int id) {
   int cmdID = commID++;
   connect(user.getName(), user.getPassword());
   try {
     out.println(cmdID + ";" + cmd + ":" + comp.name + ":" + Integer.toString(qty) + ":" + id);
     out.flush();
     Shares pen = (Shares) receiveReply(cmdID);
     user.getPendingShares().add(pen);
     user.dataChanged();
   } catch (Exception r) {
     r.printStackTrace();
   }
 }
  private void drawBalance(Graphics g)
        //  POST: Draws the balance of the current player
      {

    Font font; // Font used to draw balance
    String message; // Message for balance
    Color oldColor; // Sets for color
    int x1; // Upper-left x coordinate
    int y1; // Upper-left y coordinate
    int x2; // Bottom-right x coordinate
    int y2; // Bottom-right y coordinate
    int width; // Width of the dialogue box
    int height; // Height of the dialogue box
    int offset; // Offset so the dialogue box is positioned
    int balance; // Offset so the dialogue box is positioned
    User player; // User value for the player

    player = usersArray[0];

    balance = player.getBalance();
    oldColor = g.getColor();

    x1 = ScaledPoint.scalerToX(0.72);
    y1 = ScaledPoint.scalerToY(0.81);
    x2 = ScaledPoint.scalerToX(0.88);
    y2 = ScaledPoint.scalerToY(0.86);
    width = x2 - x1;
    height = y2 - y1;
    message = "Balance:";
    font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE);
    offset = (width - getFontMetrics(font).stringWidth(message)) / 2;
    g.setColor(Color.WHITE);
    g.drawString(message, x1 + offset, y2);

    x1 = ScaledPoint.scalerToX(0.72);
    y1 = ScaledPoint.scalerToY(0.865);
    x2 = ScaledPoint.scalerToX(0.88);
    y2 = ScaledPoint.scalerToY(0.915);

    width = x2 - x1;
    height = y2 - y1;
    message = "$" + Integer.toString(balance);
    font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE);
    offset = (width - getFontMetrics(font).stringWidth(message)) / 2;
    g.drawString(message, x1 + offset, y2);

    g.setColor(oldColor);
  }
  public void actionPerformed(ActionEvent evt) {
    // Get button clicked
    JButton buttonClicked = (JButton) evt.getSource();
    String actionCommand = new String(buttonClicked.getActionCommand());

    if (actionCommand.equals("Submit")) {
      System.out.println(clientUser.getLogon() + ": updating ticket...");

      // Recover ticket and update it
      Ticket ticketToUpdate = ticket;
      ticketToUpdate.setDesc(clientTicketDialog.getSummaryDescriptionField());
      ticketToUpdate.setResolution(clientTicketDialog.getResolutionDescriptionField());

      // Call checkInTicket() on the RMI object to update the ticket on the server
      try {
        ticketServerObject.checkInTicket(ticketToUpdate);
        // Refresh the activeTickets HashMap
        owner.getActiveTickets();
      } catch (RemoteException re) {
        System.out.println(re.getMessage());
      }

      // Close the ClientTicketDialog
      clientTicketDialog.setVisible(false);
      clientTicketDialog.dispose();
    }
  }
Example #5
0
  public void actionPerformed(ActionEvent e) {
    try {
      FileInputStream fin = new FileInputStream(obj.f);
      ObjectInputStream ois = new ObjectInputStream(fin);
      obj.a1 = (ArrayList) ois.readObject();

      String s1 = obj.t6.getText();
      String s2 = obj.t7.getText();

      int size = obj.a1.size();
      int f5 = 0;

      for (int i = 0; i < size; i++) {
        Bookinfo r2 = (Bookinfo) obj.a1.get(i);
        if (r2.bkisno.equals(s1) && r2.title.equals(s2)) {
          JOptionPane.showMessageDialog(
              null, "ALREADYEXIT", "Welcome", JOptionPane.QUESTION_MESSAGE);
          f5 = 1;
        }
      }

      if (f5 == 0) {
        JOptionPane.showMessageDialog(null, "ALREADYEXIT", "Welcome", JOptionPane.QUESTION_MESSAGE);
        ;
      }

      fin.close();
      ois.close();
    } catch (Exception e1) {
    }
  }
Example #6
0
  public void actionPerformed(ActionEvent e) {
    try {
      FileInputStream fin = new FileInputStream(obj.f);
      ObjectInputStream ois = new ObjectInputStream(fin);
      obj.a1 = (ArrayList) ois.readObject();
    } catch (Exception e1) {
      System.out.print(e1);
    }
    int size = obj.a1.size();
    int f4 = 0;

    for (int i = 0; i < size; i++) {
      Bookinfo r2 = (Bookinfo) obj.a1.get(i);
      if (r2.bkisno.equals(obj.t3.getText()) && r2.title.equals(obj.t4.getText())) {
        JOptionPane.showMessageDialog(null, "ALREADYEXIT", "Welcome", JOptionPane.QUESTION_MESSAGE);
        f4 = 1;
      }
    }
    if (f4 == 0) {
      obj.a1.add(new Bookinfo(obj.t6.getText(), obj.t7.getText(), obj.t8.getText()));
      obj.t6.setText("");
      obj.t7.setText("");
      obj.t8.setText("");
    }
  }
Example #7
0
  public void actionPerformed(ActionEvent e) {
    try {
      FileInputStream fin = new FileInputStream(obj1.f);
      ObjectInputStream ois = new ObjectInputStream(fin);
      obj1.a1 = (ArrayList) ois.readObject();

      String s3 = obj1.t3.getText();
      String s4 = obj1.t4.getText();
      String s5 = obj1.t5.getText();
      int size = obj1.a1.size();
      int f6 = 0;

      for (int i = 0; i < size; i++) {
        Stdinfo r2 = (Stdinfo) obj1.a1.get(i);
        if (r2.name.equals(s3) && r2.id.equals(s4) && r2.addr.equals(s5)) {
          JOptionPane.showMessageDialog(null, "FOUND", "Welcome", JOptionPane.QUESTION_MESSAGE);
          f6 = 1;
        }
      }

      if (f6 == 0) {
        JOptionPane.showMessageDialog(null, "NOT FOUND", "Welcome", JOptionPane.QUESTION_MESSAGE);
      }

      fin.close();
      ois.close();
    } catch (Exception e1) {
    }
  }
Example #8
0
  public void actionPerformed(ActionEvent e) {
    try {
      FileInputStream fin = new FileInputStream(obj.f);
      ObjectInputStream ois = new ObjectInputStream(fin);
      obj.a1 = (ArrayList) ois.readObject();

      String s1 = obj.t1.getText();
      String s2 = obj.t2.getText();

      int size = obj.a1.size();
      int f1 = 0;

      for (int i = 0; i < size; i++) {
        info r = (info) obj.a1.get(i);
        if (r.uid.equals(s1) && r.pass.equals(s2)) {
          JOptionPane.showMessageDialog(null, "VALID", "Welcome", JOptionPane.QUESTION_MESSAGE);
          f1 = 1;
        }
      }

      if (f1 == 0) {
        JOptionPane.showMessageDialog(null, "ALREADYEXIT", "Welcome", JOptionPane.QUESTION_MESSAGE);
      }

      fin.close();
      ois.close();
    } catch (Exception e1) {
    }
  }
Example #9
0
  private void button3_updateActionPerformed(ActionEvent e) {
    String message = null;
    User temp = (User) list1.getSelectedValue();
    try {
      temp.name = textField1_name.getText();
      temp.emeil = textField2_emeil.getText();
      temp.telefon = Integer.valueOf(textField3_telefon.getText());
      message = "Успешно преобразован";
      textField1_name.setText("");
      textField2_emeil.setText("");
      textField3_telefon.setText("");

    } catch (NumberFormatException ex) {
      message = "Разберитесь с телефоном";
    } finally {
      JOptionPane.showMessageDialog(this, message);
    }
  }
  public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equals("Add User")) {
      jta.append("\n" + userId.getText());

      User user = new User(userId.getText());
    } else if (ae.getActionCommand().equals("Add Group")) {
      jta.append("\n" + groupId.getText());

      Group group = new Group(groupId.getText());
    } else if (ae.getActionCommand().equals("Open User View")) {
      try {
        if (!jta.getSelectedText().equals("null")) {
          userView.setVisible(true);
        }
      } catch (Exception e) {
        JOptionPane.showMessageDialog(
            frame, "Nothing selected", "Error", JOptionPane.ERROR_MESSAGE);
      }
    } else if (ae.getActionCommand().equals("Show User Total")) {
      JOptionPane.showMessageDialog(frame, User.getUserTotal());
    } else if (ae.getActionCommand().equals("Show Group Total")) {
      JOptionPane.showMessageDialog(frame, Group.getGroupTotal());
    } else if (ae.getActionCommand().equals("Show Messages Total")) {
      JOptionPane.showMessageDialog(frame, User.getMessageTotal());
    } else if (ae.getActionCommand().equals("Show Positive Percentage")) {
      String[] newsFeed = User.getNewsFeed();

      int positive = 0;
      int i = 0;
      while (!(newsFeed[i] == null)) {
        if (newsFeed[i].contains("good")
            || newsFeed[i].contains("great")
            || newsFeed[i].contains("excellent")) positive++;
        i++;
      }

      JOptionPane.showMessageDialog(frame, positive * 100.0 / i + "%");
    } else if (ae.getActionCommand().equals("Follow User")) {
      following.append("\n" + userId2.getText());
    } else if (ae.getActionCommand().equals("Post Tweet")) {
      User.postTweet(tweet.getText());
      newsFeed.append("\n" + jta.getSelectedText() + ": " + tweet.getText());
    }
  }
Example #11
0
  public void actionPerformed(ActionEvent e) {
    try {
      FileInputStream fin = new FileInputStream(obj.f);
      ObjectInputStream ois = new ObjectInputStream(fin);
      obj.a1 = (ArrayList) ois.readObject();
    } catch (Exception e1) {
      System.out.print(e1);
    }

    obj.a1.add(new info(obj.t1.getText(), obj.t2.getText()));
    obj.t1.setText("");
    obj.t2.setText("");
  }
  public void buyItemFromUser(User buyer, User seller, Item currentItem)
        // PRE:  buyer, seller, currentItem must be initialized
        // POST: Purchases item from the store and has stores it into inventory.
      {

    int buyer_balance; // The new balance of the buyer
    int seller_balance; // The new balance of the seller
    String str; // First query
    String str2; // Second query
    String str3; // Third query

    buyer_balance = buyer.getBalance() - currentItem.getPrice();
    seller_balance = seller.getBalance() + currentItem.getPrice();

    if (buyer_balance > 0) // If the buyer wont go negative
    {
      str =
          String.format(
              "Update users set balance = (%d) where user_name = '%s'",
              buyer_balance, buyer.getUserName());

      str2 =
          String.format(
              "Update users set balance = (%d) where user_name = '%s'",
              seller_balance, seller.getUserName());

      str3 =
          String.format(
              "Update items set owner_id = (%d) where item_name = '%s'",
              buyer.getUserId(), currentItem.getItemName());

      updateTables(str, str2, str3);

    } else {
      // Prompt the user with an error
      JOptionPane.showMessageDialog(
          null, "You will go bankrupt if you try buying that, try selling some items.");
    }
  }
Example #13
0
  // Constructor receives the filename
  Rolodex(String filename) throws FileNotFoundException {
    File file = new File(filename);
    Scanner scanner = new Scanner(file);

    // Split the line with ~
    while (scanner.hasNext()) {
      tokens = scanner.nextLine().split("~");
      name = tokens[0];
      email = tokens[1];
      pictures = tokens[tokens.length - 1];

      User user = new User();
      user.setUserName(name);
      user.setUserEmail(email);
      user.setPicture(pictures);
      userList.add(user);
    }

    frame = new JFrame("Rolodex");
    frame.setSize(700, 200);

    // Menu
    JMenuBar jmb = new JMenuBar();
    JMenu jmFile = new JMenu("File");
    JMenuItem jmiOpen = new JMenuItem("Open");
    jmiOpen.setEnabled(false);
    JMenuItem jmiExit = new JMenuItem("Exit");
    jmiExit.setMnemonic(KeyEvent.VK_X);
    jmFile.add(jmiOpen);
    jmFile.addSeparator();
    jmFile.add(jmiExit);
    jmb.add(jmFile);

    jmiOpen.addActionListener(this);
    jmiExit.addActionListener(this);

    JMenu jmTabs = new JMenu("Tabs");
    jmTabs.setMnemonic(KeyEvent.VK_T);

    JMenu jmiplacement = new JMenu("Placement");
    JMenuItem jmitop = new JMenuItem("Top");
    JMenuItem jmiright = new JMenuItem("Right");
    JMenuItem jmibottom = new JMenuItem("Bottom");
    JMenuItem jmileft = new JMenuItem("Left");
    jmiplacement.add(jmitop);
    jmiplacement.add(jmiright);
    jmiplacement.add(jmibottom);
    jmiplacement.add(jmileft);

    jmitop.addActionListener(this);
    jmiright.addActionListener(this);
    jmibottom.addActionListener(this);
    jmileft.addActionListener(this);

    JMenu jmilayoutpolicy = new JMenu("Layout policy");
    JMenuItem jmiscroll = new JMenuItem("Scroll");
    JMenuItem jmiwrap = new JMenuItem("Wrap");
    jmilayoutpolicy.add(jmiscroll);
    jmilayoutpolicy.add(jmiwrap);

    jmiscroll.addActionListener(this);
    jmiwrap.addActionListener(this);

    JMenuItem jmidefaults = new JMenuItem("Defaults");
    jmidefaults.setMnemonic(KeyEvent.VK_D);
    jmidefaults.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK));
    jmidefaults.addActionListener(this);
    jmTabs.add(jmiplacement);
    jmTabs.add(jmilayoutpolicy);
    jmTabs.addSeparator();
    jmTabs.add(jmidefaults);
    jmb.add(jmTabs);

    JMenu jmHelp = new JMenu("Help");
    JMenuItem jmiabout = new JMenuItem("About");
    jmiabout.addActionListener(this);
    jmHelp.add(jmiabout);
    jmb.add(jmHelp);

    frame.setJMenuBar(jmb);

    jtp = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());

    for (User user : userList) {
      image = new ImageIcon(user.getPicture());
      panel = new JPanel();
      labname = new JLabel("Name: ");
      txtname = new JTextField(20);
      txtname.setText(user.getUserName());
      labemail = new JLabel("Email: ");
      txtemail = new JTextField(20);
      txtemail.setText(user.getUserEmail());
      l = new JLabel(image);
      l.setHorizontalAlignment(SwingConstants.LEFT);
      panel.add(l);
      panel.add(labname);
      panel.add(txtname);
      panel.add(labemail);
      panel.add(txtemail);
      jtp.addTab(user.getUserName(), panel);
      topPanel.add(jtp);
    }

    frame.add(jtp);
    center(frame);
    frame.setVisible(true);
  }