KirkPatrick 28 Junior Poster

Before going into the explanation I will list what I am wanting to do in order:

  • Have main() read results.csv and create beans according to the lines of data in the file
  • Have my beans set up correctly (getters, setters, and propertychanges)

To give you guys a quick brief on what I am doing: I am running a program called Angry IP Scanner through my java application. What it does is records the information I want and saves it to a csv file called results.csv.


I'm going to try and explain this as clear as possible so that you guys won't get confused. I'll be using illustrations to help out. (i noticed that image tags are disabled, if they are not allowed I'll remove them from my post)

Main() reading results.csv

What I am wanting to do is have my main() open up my results.csv (this will contain data that should be displayed on the bean.) and I want it to read the amount of lines (after the header of course, i'm just wanting the data angy IP picked up or will pick up) . Once it has read the amount of lines located in the results.csv I want it to create the same amount of beans as there are lines. Below I will illustrate what I am talking about.

Here is the program at full (an example of what im wanting it to be without the data):

[img]http://img80.imageshack.us/img80/8343/program.png[/img]


By the way, the viewobject is my bean. So the light gray ;)


Alright, lets pretend this is what is already located in my results.csv:

'IpAddress', 'ComputerName', 'MacAddress'

192.168.0.0,marley,00-14-5e-6b-9b-c4
192.168.0.1,barley,00-24-5e-6b-9b-c4
192.168.0.2,carley,00-34-5e-6b-9b-c4
192.168.0.3,harley,00-44-5e-6b-9b-c4
192.168.0.4,darley,00-54-5e-6b-9b-c4

I don't want the first line to be counted because that would be my header. However each line after that I want counted, so once its set up correctly it would create 5 beans like so:


[img]http://img89.imageshack.us/img89/729/programcopy.png[/img]


My attempt on this came out to something of this sort: (pseudocode)

ViewObject vo = new ViewObject();

read.parse(results.csv)
s = parseResult[]
parseResult = String hostname, String Ip

 ArrayList<ViewObject> list = new ArrayList();
 for(int i = 0; i < s.length(); i++) {
 list.add(vo);

But I can't quite figure out how to get my parseResult to equal my two strings without making it a class.

Also if you need more code to understand what I am doing, I can post it.

Next part,

Beans: Getters, Setters, PropertyChanges

Right now I am wanting my beans (viewobjects) to pull up the information from results.csv and I'm wanting it to update when angryIP runs. So about every three minutes. I'm not sure if I have it set up correctly, but here is what I have at the moment (for the setters/getters/propertychanges):

private PropertyChangeSupport pcs = new PropertyChangeSupport(this);

    public JLabel getComputerName() {
        return computerName;
    }

    public void setComputerName (JLabel computerName) {
        JLabel oldComputerName = getComputerName();
        this.computerName = computerName;
        firePropertyChange("computerName", oldComputerName, computerName);
    }

    public JLabel getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress (JLabel IpAddress) {
        JLabel oldIpAddress = getIpAddress();
        this.ipAddress = IpAddress;
        firePropertyChange("ipAddress", oldIpAddress, IpAddress);
    }


//I noticed this had been added to a snippet i had checked out and wasn't sure if they are needed

   @Override
   private void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
       if (oldValue == null && newValue != null || !oldValue.equals(newValue)) {
           this.pcs.firePropertyChange(propertyName, oldValue, newValue);
       }
   }


   @Override
   public void addPropertyChangeListener(PropertyChangeListener listener) {
       pcs.addPropertyChangeListener(listener);
   }

   @Override
   public void addPropertyChangeListener(String computerName, PropertyChangeListener listener) {
       pcs.addPropertyChangeListener(computerName, listener);
   }

   @Override
   public void removePropertyChangeListener(PropertyChangeListener listener) {
       pcs.removePropertyChangeListener(listener);
   }

   @Override
   public void removePropertyChangeListener(String ipAddress, PropertyChangeListener listener) {
       pcs.removePropertyChangeListener(ipAddress, listener);
   }

I'm not quite sure how to have it get and set from a csv file.


I am looking for examples on how to do something of this sort, if you provide code please explain what it does with commentary. I want to know whats going on and why, not just copy and paste it. I appreciate any and all help/advice given as I am fairly new to java.

And lastly, thank you for taking to time to read the thread

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.