Searching a Vector of objects

I'm embarassed to ask this question but I haven't figured out the answer myself yet so I need help.
I need to be able to search a Vector (it could be an Array just as easily) by only certain parts of the objects in the vector. So for example I have vector v that contains 10 objects o. Objects o are a very small custom class that each have a name and a number. How do I search the vector for the object o that contains name x?
I tried overriding the equals method of object o and using the IndexOf method of vector v but that did not work.

I'm embarassed to ask this question but I haven't
figured out the answer myself yet so I need help.
I need to be able to search a Vector (it could be an
Array just as easily) by only certain parts of the
objects in the vector. So for example I have vector
v that contains 10 objects o. Objects o are a very
small custom class that each have a name and a
number. How do I search the vector for the object o
that contains name x?Iterate over the Vector and ask each element whether its name is x.
I tried overriding the equals method of object o and
using the IndexOf method of vector v but that did not
work.What does "did not work" mean?

Similar Messages

  • Vector smart objects

    I am having to copy and paste a graphic from MS Word 08 and place it into Photoshop CS3. It imports as Vector Smart Object and is very blurry. I have done this with MS Word 04 to CS2 with no problems. I searched the forum but did not see any solutions. Any ideas. Thanks

    Welles,<br /><br />Although I have Office 2008 on my system, I don't use it for "publishing". But it does make sense that they now follow the convention of XPress and InDesign with the use of placeholders.<br /><br />(Of course we can see prepress departments, printers and service bureaus around the world finally running out to embrace Word....)  <g><br /><br />Neil

  • Program error when attempting to edit a vector smart object. Help?

    I'm running Photoshop CS6 (13.0.1) 64bit on a MacBook Pro running OS X Lion. About 60% of the time when I try to double click a vector smart object instead of opening it up in Illustrator I get an error that says, "Could not edit original smart object because of program error." This most recent time it was a smart object from vector data I copied and pasted from Illustrator into Photoshop.
    Any idea why this is happening and how I can fix it?
    Thanks.

    Hi there, 
    I got this problem when I installed Adob master collection Over CS 5.
    I had children book story storis which created in Adobe illustrator CS 5 and I created art boards in Adobe photoshop cs 5.
    After installting CS 6 i tried to edit the smart objects and it was not opeinging the smart object file in Illustrator.
    I did some tests.
    1) Right click on smart object layer and click export contents. Save on desktopp or anywhere you want. (I saved on desktop)
    2) I had this file on my desktop (Vector Smart Object10.ai) but it didn't show any icon, which program should open this type of file.
    3) Double click on the file and it pop up a extension window 'Click on change and select adobe illustrator' and press OK.
    4) Go back to your photoshop file and right click on smart object layer and click dit content. now this time it opens up assets in illustrator.
    ENJOY!
    www.4d-studios.co.uk

  • Is it possible to export Vector Smart Objects as vector SVG files from Photoshop CC 2014?

    I have Vector Smart Objects copied from Illustrator and pasted into Photoshop. I would like to export them as vector SVG files (using Generator or Extract Assets). I can add the .svg extension to the layer and actually export an SVG just fine. The problem is any SVG I have exported have all been raster images. It defeats the purpose of having that as an option as far as I'm concerned.
    I remember watching and listening to keynotes and other speakers at Adobe MAX 2014 who said it was so powerful and amazing to create SVG files from Photoshop. If we're still exporting raster SVG files from Photoshop...that's not very impressive or exciting--especially since this era of modern web development benefits greatly from using vector SVG files.
    I understand that Shape Layers can be exported as vector SVG files but that seems very limiting. I also realize that users can create some impressive vectors in Photoshop, but that is not optimal. Illustrator is a better tool for creating vectors and I normally use Photoshop and Illustrator side-by-side. I know that vector SVG files can be exported from Illustrator but that isn't as user friendly and convenient as utilizing Photoshop > Generator > Reflow.
    My idea was to create my assets in Illustrator, paste them into Photoshop as Vector Smart Objects, set up my layout, and then use the Generator/Reflow method or Extract Assets to get a new web design started.
    Maybe I misunderstood what the speakers at Adobe MAX had said. Perhaps it's just user error and I'm just missing something simple (it happens).
    Photoshop CC 2014 notes the following under Help > System Info:
    Adobe Photoshop Version: 2014.2.2 20141204.r.310 2014/12/04:23:59:59 CL 994532  x64
    Operating System: Windows 8.1 64-bit
    Any help or suggestions would be greatly appreciated! Thank you in advance for your time.

    Not quite the same, but have a look at the new Libraries feature that came with 2014.2.2  I just tried it, and dragging a vector object into a library I created in Photoshop, was there in Illustrator.  This happens without having to close and reopen Illustrator.  Just use the drop down at the top of the Libraries panel (in Illustrator) to find your custom, or job specific library.

  • How to copy objects from Pages (5.5.1) and paste it into Photoshop as a vector smart object with high resolution?

    I recently have bought a new Macbook Pro (Version 10.10.1) with the OS X Yosemite. The computer comes with the new Pages (version 5.5.1).
    Here is the problem: I like to create artwork using the shapes on Pages. Previously, on my old mac, I used Pages 4.3 to create objects, which I would copy then paste to Photoshop and it would become a vector smart object. However, in the new Pages (version 5.5.1), when I copy objects, they would appear on Photoshop as instead, a layer and it would not be in full resolution.
    Also, I know there is nothing wrong with the Pages file itself because I have converted the document to PDF form and it is high resolution when inserted into Photoshop that way.
    Does anyone know how I can copy individual objects from Pages (5.5.1) and paste it into Photoshop as a vector smart object with high resolution as I have done before?
    Thanks!

    ghotiz wrote:
    copy the image and have it in a high-quality PNG format that does not include the background from the Pages document.
    Oh, well if you don't actually need vector objects then it looks like this is possible. As I said earlier, Pages is putting a PNG on the clipboard. I tested it and it does paste into Photoshop as a transparent layer, because I can see the transparent background of the pasted PNG graphic if I either turn off all layers behind it in Photoshop, or if I start a new Photoshop document to paste into but make sure I choose Transparent for the Background Contents in the New Document dialog.

  • PS opens vector smart object all pixilated

    I have this problem when using graphics from Illustrator as vector smart objects in Photoshop. I have followed tones of heated discussions on this but I haven't got any further. So here is what I do following the steps on the PS help: I copy graphics in AI and paste them in PS as smart object. A layer will be added that even has the name vector smart object but the graphic itself is all pixilated. Now the size of my PS-file is 150X150 Pixels with a resolution of 300. I need this size because I want to implement the file into my website and the layout requires this size for all my graphics. I would say it doesn't matter much what size the file is anyway since according to the PS help whatever vector smart object I place in Photoshop it won't change image quality when transformed. Therefor I'd say that not even the small file should be a problem here. But obviously there is something not working... because even when, to compare, I paste the graphic as pixel it shows the same result. Strange enough that I have used this vector smart objects before and it worked just fine... So I tried to paste the graphic in different ways, saving it as pdf in AI and then placing it in PS, insert it directly as smart object, making sure the file handling and clipboard references are adjusted, and finally after no success trashing the preferences in both applications. Still not closer to a satisfying result. I attach the graphics (first the AI graphic, then the vector smart object from PS) to show the difference and maybe there is someone out there that can tell what I am doing wrong. By the way I just converted the files to jpegs to post them here so the sizes might not match on the screen...

    One other thing to check...
    Are you viewing the display at 100%?
    Photoshop's OpenGL-based image resizing algorithms are smoother and fuzzier than they used to be (or than they are with OpenGL disabled).  What I'm getting at is that you may be perceiving fuzziness in the display that's not really there in the image.
    How does the fuzziness look if you zoom in a lot?
    -Noel

  • Keynote 6.0 vector smart object conversion to Photoshop CS6

    Hi,
    I upgraded to OS 10.9 and Keynote 6.0. In the previous version of Keynote, I was able to easily paste Keynote content (words, shapes, charts) into Photoshop CS6 & Illustrator CS6 as vector objects, of which the elements could be independently manipulated by releasing the clipping mask.
    However, with Keynote 6.0, it appears the content mentioned above pastes into CS6 software as .tiff files with no option to convert to a vector smart object?  Is there a way to force a vector object placement or does this new Keynote version no allow (and if so why eliminate such a convenient function as vector smart objects)?
    Thanks for the help...

    Hello  thanks for your answers,
    i posted this when i was upset because it was a very frustrating situation. I create Vector art in Illustrator and most of the times i just copy and paste them into Photoshop. I dont use Illustrator Cs6 because some Issues with the color Picker and because i Use Scriptographer alot. So i use Photoshop CS6 and Illustrator CS 5.
    Somehow recently i noticed this strange behaviour. When i close Illustrator completely and doubleclick the Layer in Photoshop it works fine.

  • Flv player is opening vector smart objects instead of illustrator.

    How do I re-associate vector smart objects in Photoshop to open in Illustrator as they did before the update?

    Editing smart objectrs uses the system wide associations, not the ones from Bridge, so you need to adjust that for the *.ai file type.
    Mylenium

  • Getting the search result as an object---URGENT

    Hi,
    I want to capture the search results in an object and perform certain functions on it.
    To achieve it we have seen certain procedures, the bottle neck is how to get the portlet instance id of the generated page.
    Any pointers to achieve the same ??
    Thanks in advance,
    Kapil

    Please provide a bit more detail. What version of portal are you using? What are the " ... certain procedures ... " that you mention.What sort of object do you want to capture the results into? An Oracle Object Type? Why do you need to the portlet instance id?

  • [Forum FAQ] The Value drop down list is grayed out when you perform search for Group Policy Objects in GPMC

    Symptom
    On Windows Server 2012 or Windows Server 2012 R2, when you use the Search for Group Policy Objects feature in GPMC, the “Value” field is not populated when you choose “User Configuration” as the Search Item. (See Figure 1.)
    <Figure 1>
    Cause
    The happens because the  Data of the (Default) value of the following Registry Key is not correct.
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions\{4D2F9B6F-1E52-4711-A382-6A8B1A003DE6}]
    By default the Data is (value not set). (see Figure 2)
    <Figure 2>
    Resolution
    The registry keys under [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions] are the Group Policy Preference Client Side Extensions. The CSE name of the GUID {4D2F9B6F-1E52-4711-A382-6A8B1A003DE6} is
    RemoteApp and Desktop Connections. Please follow the steps below to resolve the issue.
    1. Locate the registry key: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions\{4D2F9B6F-1E52-4711-A382-6A8B1A003DE6}]
    2. Take the ownership of this key: Right click on the registry key and choose Permissions option and click the Advanced button on the dialogue window. Then on the Advanced Security Settings dialogue window, click Change button to take the ownership
    of the key for the current logon account and make the current logon account Full Control permission with the registry key. (See Figure 3.)
    <Figure 3> 
    3. Change the data of (Default) value from "(value not set)" to
    "RemoteApp and Desktop Connection Component". (See Figure 4)
    <Figure 4>
    4. Once the steps above are completed, the Value drop down list will be populated again when you perform Search in GPMC. (See Figure 5)
    <figure 5>
    This article has been created as a TechNet Wiki
    here.
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    thanks for the tip - but you should create this as a wiki article as it will be easier to reference in the future
    Regards,
    Denis Cooper
    MCITP EA - MCT
    Help keep the forums tidy, if this has helped please mark it as an answer
    My Blog
    LinkedIn:

  • Vector of objects problem

    Hello All,
    I am trying out a program which uses vector of objects.It is throwing an exception when I compile it.The aim of the program is.
    for eg if we have a set of producers
    count =5
    P1 P2 P3 P4 P5
    7 8 9 10 11
    C1 C2 C3 C4 C5
    1 2 3 4 5
    store all those pairs of consumers and producers where (Ci <=Pi).
    Hash table keys will be of the form S0,S1,S2..SN
    in this Case SO should correspond to a vector which is (7 1),(8 1),(9,1),(10,1),(11,1)
    similarly
    S1 should be (8,1),(8,2) etc.
    I have tried writing the code it doesnt work why.
    Thanks.
    Regards.
    NP
    import java.io.*;
    import java.util.*;
    import java.lang.StrictMath;
    import java.util.ArrayList;
    class CollectionCache
    private final Map cache;
    public CollectionCache()
    cache=new Hashtable();
    public Collection put(Object key,Collection value)
    return(Collection)cache.put(key,value);
    public Collection get(Object key)
    return(Collection)cache.get(key);
    public class Participant
    boolean isProducer;
    double value;
    String name;
    static double resources_used;
    static int p=0;
    static int q=0;
    //static int[] final_index_pro=new int[100];
    //static int[] final_index_con=new int[100];
    public void set_is_pro_or_con(boolean ispro)
    isProducer=ispro;
    public boolean get_is_pro_or_con()
    return isProducer;
    public void set_is_pro_or_con_value(double value)
    this.value=value;
    public double get_is_pro_or_con_value()
    return value;
    public void set_is_pro_or_con_name(String name)
    this.name=name;
    public String get_is_pro_or_con_name()
    return name;
    public static void main(String args[]) throws IOException
    ArrayList Producer=new ArrayList();
    ArrayList Consumer=new ArrayList();
    Collection c=new Vector();
    int i;
    BufferedReader console= new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the number of resources you want to input");
    String input=console.readLine();
    int count=Integer.parseInt(input);
    System.out.println(count);
    for(i=0;i<count;i++)
    Producer.add(i,new Participant());
    for(i=0;i<count;i++)
    Consumer.add(i,new Participant());
    System.out.println("Reading values into producer array");
    for(i=0;i<count;i++)
    ((Participant)Producer.get(i)).set_is_pro_or_con(true);
    String t="P"+ i;
    ((Participant)Producer.get(i)).set_is_pro_or_con_name(t);
    ((Participant)Producer.get(i)).set_is_pro_or_con_value((int)(StrictMath.random()*10 + 1));
    System.out.println("Reading values into consumer array");
    for(i=0;i<count;i++)
    ((Participant)Consumer.get(i)).set_is_pro_or_con(true);
    String t="P"+ i;
    ((Participant)Consumer.get(i)).set_is_pro_or_con_name(t);
    ((Participant)Consumer.get(i)).set_is_pro_or_con_value((int)(StrictMath.random()*10 + 1));
    //Making Graph topology
    System.out.println("producer array");
    for(i=0;i<count;i++)
    //System.out.println(dup_producer.get_is_pro_or_con());
    //System.out.println(dup_producer[i].get_is_pro_or_con_name());
    System.out.println(((Participant)Producer.get(i)).get_is_pro_or_con_value());
    System.out.println("consumer array");
    for(i=0;i<count;i++)
    //System.out.println(dup_consumer[i].get_is_pro_or_con());
    //System.out.println(dup_consumer[i].get_is_pro_or_con_name());
    System.out.println(((Participant)Consumer.get(i)).get_is_pro_or_con_value());
    System.out.println("Values Printed");
    //String s;
    CollectionCache cc=new CollectionCache();
    int j=0;
    while(j<count)
    for(i=0;i<count;i++)
    if( (((Participant)Consumer.get(j)).get_is_pro_or_con_value()) <= (((Participant)Producer.get(i)).get_is_pro_or_con_value()))
    c.add(Double.toString((((Participant)Consumer.get(j)).get_is_pro_or_con_value())));
    c.add(Double.toString((((Participant)Producer.get(i)).get_is_pro_or_con_value())));
    final Object s="S" +j;
    cc.put(s,c);
    j++;
    j=0;
    while(j<count)
    Collection value=cc.get("S" + j);
    if(value!=null)
    for(Iterator it=value.iterator(); ;it.next())
    System.out.println(it.next().toString());
    j++;

    Or if you want to keep it in as small a scope as possible:
    Iterator it = valu      e.iterator();
      while (it.hasNe                                                       xt()) {
        System.out.println(it
    .next
    }

  • [svn:fx-trunk] 7916: Last of the List PARB changes - selectedItems is now a Vector of Objects and selectedIndices is a Vector of Numbers .

    Revision: 7916
    Author:   [email protected]
    Date:     2009-06-17 09:04:51 -0700 (Wed, 17 Jun 2009)
    Log Message:
    Last of the List PARB changes - selectedItems is now a Vector of Objects and selectedIndices is a Vector of Numbers.
    Also, put alphabetized spark-manifest correctly after my last checkin.
    QA: Yes
    Doc: Yes
    Checkintests: Pass
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/flex4/src/spark/components/List.as
        flex/sdk/trunk/frameworks/spark-manifest.xml

    Gordon, it looks like its been a while since you made this post.  Not sure how valid it is now...   I am particularly interested in the LigatureLevel.NONE value.  It seems that it is no longer supported.
    How do I turn of ligatures in the font rendering?
    My flex project involves trying to match the font rendering of Apache's Batik rendering of SVG and ligatures have been turned off in that codebase.  Is there any way (even roundabout) to turn ligatures off in flash?
    Thanks,
    Om

  • How do I print out a vector of objects?

    Hi,
    I am having trouble printing out the contents of my vector. Can somebody please help me out. Im trying to create a vector of objects. I keep getting output like this:
    There are 5 total classes
    5
    ClassObject@13f5d07
    Here is my code:
    //Test.java
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    public class Test {
            ClassObject co = new ClassObject();
            Vector vec = new Vector();
            public Test () throws Exception {
                    Read("input.dat");
            public void Read(String fileName) {
                    String num; //number of cells
                    String cells; //cell data
                    int x = 0;
                    try {
                            FileReader file = new FileReader(fileName);
                            BufferedReader in = new BufferedReader (file);
                            num = in.readLine();
                            int number = Integer.valueOf(num).intValue(); //convert string to int
                            System.out.println("There are " + number + " total classes");
                            while ((cells = in.readLine()) != null) {
                                    StringTokenizer st = new StringTokenizer(cells, "- ");
                                    while (st.hasMoreTokens()) {
                                           co.classNumber = Integer.valueOf(st.nextToken()).intValue();
                                           co.classRelation = Integer.valueOf(st.nextToken()).intValue();
                                          // System.out.println(co[x].classRelation);
                                           vec.addElement(co);
                                           x++;
                                    System.out.println("\n" + x);
                                    System.out.println(vec.lastElement());
                    catch (IOException e) {
                            System.out.println("cannot read file");
                            System.exit(0);
            public static void main (String[] args) throws Exception {
                    new Test ();
    //ClassObject.java
    import java.util.*;
    import java.lang.*;
    public class ClassObject {
            int classNumber;
            int classRelation;
    //input.dat
    5
    1-2 1-3 2-4 3-4 4-5Thanks!!!!!

    public class ClassObject
        int classNumber;
        int classRelation;
        public String toString()
            return classNumber + "-" + classRelation;
    }

  • Sorting a vector of objects using attribute of object class as comparator

    i would like to sort a vector of objects using an attribute of object class as comparator. let me explain, i'm not sure to be clear.
    class MyObject{
    String name;
    int value1;
    int value2;
    int value3;
    i've got a Vector made of MyObject objects, and i would sort it, for instance, into ascending numerical order of the value1 attribute. Could someone help me please?
    KINSKI.

    Vector does not implement a sorted collection, so you can't use a Comparator. Why don't you use a TreeSet? Then you couldclass MyObject
      String name;
      int value1;
      int value2;
      int value3;
      // Override equals() in this class to match what our comparator does
      boolean equals (Object cand)
        // Verify comparability; this will also allow subclasses.
        if (cand !instanceof MyObject)
          throw new ClassCastException();
        return value1 = cand.value1;
      // Provide the comparator for this class. Make it static; instance not required
      static Comparator getComparator ()
        // Return this class's comparator
        return new MyClassComparator();
      // Define a comparator for this class
      private static class MyClassComparator implements Comparator
        compare (Object cand1, Object cand2)
          // Verify comparability; this will also allow subclasses.
          if ((cand1 !instanceof MyObject) || (cand2 !instanceof MyObject))
            throw new ClassCastException();
          // Compare. Less-than return -1
          if ((MyObject) cand1.value1 < (MyObject) cand2.value1))
            return -1;
          // Greater-than return 1
          else if ((MyObject) cand1.value1 > (MyObject) cand2.value1))
            return 1;
          // Equal-to return 0.
          else
            return 0;
    }then just pass MyObject.getComparator() (you don't need to create an instance) when you create the TreeSet.

  • Searching a vector

    Ok, second post. I gave up on the whole array idea and moved to vectors. I got it reading the text file and adding to the vector succesfully. Now I need to search that vector. The text file looks like this:
    9876543 9876543 Y
    0612207 0612207 N
    0123456 0123456 N
    1234567 1234567 Y
    Here's my code so far:
    import java.*;
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class EmailForms extends JFrame implements ActionListener {
         private JTextField jtfUserName;
         private JPasswordField jpfPassword;
         private JButton jbtLogin;
         private JButton jbtCancel;
         Vector LoginData = new Vector();
         public static void main (String[] args) {     
              EmailForms LoginFrame = new EmailForms();
              LoginFrame.setSize(200, 100);
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              int screenWidth = screenSize.width;
              int screenHeight = screenSize.height;
              Dimension frameSize = LoginFrame.getSize();
              int x = (screenWidth - frameSize.width)/2;
              int y = (screenHeight - frameSize.height)/2;
              LoginFrame.setLocation(x, y);
              LoginFrame.pack();
              LoginFrame.setVisible(true);     
         public EmailForms () {     
              try {     
                   String UP1Line;
                   FileInputStream fis = new FileInputStream("UP1.txt");
                  BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                  while ((UP1Line = br.readLine()) != null) {
                        StringTokenizer st = new StringTokenizer(UP1Line, " ");
                        while (st.hasMoreTokens()) {
                          LoginData.addElement(st.nextToken());
                    br.close();
                    fis.close();
              catch (IOException ex){
                   JOptionPane.showMessageDialog(this, "Fatal Systems Error", "Email Forms: File Error 1",
                   JOptionPane.INFORMATION_MESSAGE);
                   System.exit(0);     
              catch (NullPointerException ex){
                   JOptionPane.showMessageDialog(this, "Fatal Systems Error", "Email Forms: File Error 2",
                   JOptionPane.INFORMATION_MESSAGE);
                   System.exit(0);     
              setTitle("E-Forms: Login");
              JPanel jpLoginLabels = new JPanel();
              jpLoginLabels.setLayout(new GridLayout(2, 1));
              jpLoginLabels.add(new JLabel("Username:"));
              jpLoginLabels.add(new JLabel("Password:"));
              JPanel jpLoginText = new JPanel();
              jpLoginText.setLayout(new GridLayout(2, 1));
              jpLoginText.add(jtfUserName = new JTextField(10));
              jpLoginText.add(jpfPassword = new JPasswordField(10));
              JPanel p1 = new JPanel();
              p1.setLayout(new BorderLayout());     
              p1.add(jpLoginLabels, BorderLayout.WEST);
              p1.add(jpLoginText, BorderLayout.CENTER);
              JPanel p2 = new JPanel();
              p2.setLayout(new FlowLayout(FlowLayout.CENTER));     
              p2.add(jbtLogin = new JButton("Login"));
              p2.add(jbtCancel = new JButton("Cancel"));     
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(p1, BorderLayout.CENTER);
              getContentPane().add(p2, BorderLayout.SOUTH);
              jbtLogin.addActionListener(this);
              jbtCancel.addActionListener(this);
         public void actionPerformed(ActionEvent e) {
              String arg = e.getActionCommand();
              int index = find(jtfUserName.getText().trim(), new String(jpfPassword.getPassword()));
              if (arg == "Cancel") {
                   System.exit(0);
                   arg = "";
              if (arg == "Login") {
                   if (index == -1) {
                        JOptionPane.showMessageDialog(this, "Username/Password Not Found", "Email Forms: Login Error",
                        JOptionPane.INFORMATION_MESSAGE);
                   else {
                        if (index == 1 ){
                             JOptionPane.showMessageDialog(this, "Username and Password Found: Admin", "Email Forms: Good",
                             JOptionPane.INFORMATION_MESSAGE);
                        else {
                             JOptionPane.showMessageDialog(this, "Username and Password Found: User", "Email Forms: Good",
                             JOptionPane.INFORMATION_MESSAGE);          
              arg = "";
         public int find(String UName, String PWord) {
              for (int i = 0; i < LoginData.size(); i++) {                                        
                   // if ((first.element.of.first.line.UName  == LoginData.elementAt(i)) && (second.element.of.first.line.PWord == LoginData(i))) {
                   //          if (third.element.of.first.line.yes or no admin == "Y") {
                   //               goto adminside;
                   //               return 1; }
                   //          else {
                   //               goto userside;
                   //               return 2;
              return -1;
    }Essentially this is a login method. The standard username and password. The kicker is the third entry in each line of the vector "Y" or "No". This entry denotes whether or not the user is an admin. If he/she is an admin, they go to an admin program else he/she is a regular user and goes to the user program. I've done some reading on searching vectors in this forum as well as others, but none have I have read have tackled this third entry. Can someone have a look and give me their opinion.
    Thanks in advance,
    Colin

    Here you go:
    1. Use a HashMap to look up credentials.
    2. Use regular expressions to check for certain values
    The code does what you need (just checked it), but you probably wouldn't save the credentials as a "String[]" array. So there's room for improvement ;)
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class EmailForms extends JFrame implements ActionListener {
         private static final long serialVersionUID = -6409081110711705001L;
         private JTextField jtfUserName;
         private JPasswordField jpfPassword;
         private JButton jbtLogin;
         private JButton jbtCancel;
         private HashMap<String, String[]> users;
         public static void main (String[] args) {     
              EmailForms LoginFrame = new EmailForms();
              LoginFrame.setSize(200, 100);
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              int screenWidth = screenSize.width;
              int screenHeight = screenSize.height;
              Dimension frameSize = LoginFrame.getSize();
              int x = (screenWidth - frameSize.width)/2;
              int y = (screenHeight - frameSize.height)/2;
              LoginFrame.setLocation(x, y);
              LoginFrame.pack();
              LoginFrame.setVisible(true);     
         public EmailForms () {     
              users = new HashMap<String, String[]>();
              try {     
                   String UP1Line;
                   FileInputStream fis = new FileInputStream("UP1.txt");
                  BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                  while ((UP1Line = br.readLine()) != null) {
                       String [] items = UP1Line.split(" ", 4);     //max. 6 tokens, separated by semicolon
                       users.put(items[0], new String[] { items[1], items[2] });
                       if (items[2].matches("[Yy]"))
                            System.err.println("y");
                       else
                            System.err.println("n");
                    br.close();
                    fis.close();
              catch (IOException ex){
                   JOptionPane.showMessageDialog(this, "Fatal Systems Error", "Email Forms: File Error 1",
                   JOptionPane.INFORMATION_MESSAGE);
                   System.exit(0);     
              catch (NullPointerException ex){
                   JOptionPane.showMessageDialog(this, "Fatal Systems Error", "Email Forms: File Error 2",
                   JOptionPane.INFORMATION_MESSAGE);
                   System.exit(0);     
              setTitle("E-Forms: Login");
              JPanel jpLoginLabels = new JPanel();
              jpLoginLabels.setLayout(new GridLayout(2, 1));
              jpLoginLabels.add(new JLabel("Username:"));
              jpLoginLabels.add(new JLabel("Password:"));
              JPanel jpLoginText = new JPanel();
              jpLoginText.setLayout(new GridLayout(2, 1));
              jpLoginText.add(jtfUserName = new JTextField(10));
              jpLoginText.add(jpfPassword = new JPasswordField(10));
              JPanel p1 = new JPanel();
              p1.setLayout(new BorderLayout());     
              p1.add(jpLoginLabels, BorderLayout.WEST);
              p1.add(jpLoginText, BorderLayout.CENTER);
              JPanel p2 = new JPanel();
              p2.setLayout(new FlowLayout(FlowLayout.CENTER));     
              p2.add(jbtLogin = new JButton("Login"));
              p2.add(jbtCancel = new JButton("Cancel"));     
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(p1, BorderLayout.CENTER);
              getContentPane().add(p2, BorderLayout.SOUTH);
              jbtLogin.addActionListener(this);
              jbtCancel.addActionListener(this);
         public void actionPerformed(ActionEvent e) {
              String arg = e.getActionCommand();
              int index = find(jtfUserName.getText().trim(), new String(jpfPassword.getPassword()));
              if (arg == "Cancel") {
                   System.exit(0);
                   arg = "";
              if (arg == "Login") {
                   if (index == -1) {
                        JOptionPane.showMessageDialog(this, "Username/Password Not Found", "Email Forms: Login Error",
                        JOptionPane.INFORMATION_MESSAGE);
                   else {
                        if (index == 1 ){
                             JOptionPane.showMessageDialog(this, "Username and Password Found: Admin", "Email Forms: Good",
                             JOptionPane.INFORMATION_MESSAGE);
                        else {
                             JOptionPane.showMessageDialog(this, "Username and Password Found: User", "Email Forms: Good",
                             JOptionPane.INFORMATION_MESSAGE);          
              arg = "";
         public int find(String UName, String PWord) {
              String [] creds = users.get(UName);
              if (creds!=null && creds[0].matches(PWord)) {
                   System.out.println("ok");
                   if (creds[1].matches("[Yy]"))
                        return 1;
                   else
                        return 0;
              System.err.println("not ok");
              return -1;
    }

Maybe you are looking for

  • HT4589 How can I share a video shot at 60 fps.  Quick time error 0 and 50 occur for  DVD

    Change camera settings to 60 fps and now program will not share to DVD.  Getting quicktime error 0 for DVD and error 50 on master file.  Seems Quicktime cannot handle 60 fps. Is there a way I can solve this problem?  Camera setting will go back to 30

  • Using a function to define javascript objects

    Hello, like to ask if the  external parenthises are really necessary?   Like here: incident.Controller = (...)     //see code block at the end of this question  I dont think so.   (at least the code works the same for me). Also, I would also like to

  • Read from the datafile while data acquisition

    I have a program to process and record the data while experimenting. The data file is attached here with (please have a look). It is recorded injection by injection with injection number. Is it possible to read the data file while acquisition and dis

  • Windows laptops interfere with Timecapsule wireless network

    Anyone who could help me with this problem I'd be very indebted to! I set up my timecapsule to work as a wireless base station using all the standard settings. Works fine with my MBP and iPhone. But whenever my flatmates (who are using Vista and XP S

  • Problem encountered in Cluster Communication for WLS 6.1 SP2

              Hi,           Currently, we have an admin server with 2 clusters of managed servers. We realise           that the managed server in the cluster will communicate with the other servers           in the other cluster using port 7001. Is ther