Java system outputing string twice

Hello all,
Can someone tell me why the attached code is outputting strings to the console twice??

Thanks
************ clientGUI *************
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class ClientGUI extends JFrame implements ActionListener {
	public static final int defaultWidth = 80, defaultHeight = 40;
	
	  
	   private String [] listChoices = {"Football", "Music"};
	   private JList streamList;
	   private List list;
	   
	   private Button  clearButton;
	   private Button  sendButton;
	   
	   private JTextArea consoleDisplay;
	   
	   private JScrollPane consoleScroll;
	   
	   public ClientGUI() {
	        super("ClientGUI");
		    Panel topPanel = new Panel();
		    Panel bottomPanel = new Panel();
	        
	        consoleDisplay = new JTextArea(200, 7);
	        consoleDisplay.setLineWrap(true);
	        consoleScroll = new JScrollPane(consoleDisplay);
	        
	        list = new List();
	        list.add("damian");
	        list.add("conor");
	        list.addActionListener(this);
	        topPanel.add(list);
	        
	        streamList = new JList(listChoices);
	        topPanel.add(streamList);
	        streamList.addListSelectionListener(
        			new ListSelectionListener(){
						public void valueChanged(ListSelectionEvent e) {							
							getStreamChoice();
						}   	
        });
	        
	        clearButton = new Button("Clear");
	        clearButton.setBackground(Color.white);
	        clearButton.addActionListener(this);
	        topPanel.add(clearButton);
	        
	        sendButton = new Button("Send");
	        sendButton.addActionListener(this);
	        topPanel.add(sendButton);
	        
	        bottomPanel.add(consoleDisplay);

	        this.add(topPanel, BorderLayout.NORTH);
	        this.add(bottomPanel, BorderLayout.CENTER);

	        this.setSize(400, 400);
	        this.setVisible(true);
	        
	        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	    }  
	 

 public static void main(String[] args) {
    new ClientGUI();
}

@Override
 public void actionPerformed(ActionEvent arg0) {
	// TODO Auto-generated method stub	
 }


 public void getStreamChoice(){
	
	if(streamList.getSelectedValue().equals("Football")){
		FootballStream footy = new FootballStream();
		footy.messageStream.add("hello, welcome to the football stream");
		System.out.println(footy.messageStream.firstElement());
	}
	else{
		System.out.println("Music");
	}	
 }	        	
}

************** FootballStream **************

import java.io.Serializable;
import java.util.Vector;

public class FootballStream implements Serializable{
	
	Vector<String> messageStream;
	
	public FootballStream(){
		this.messageStream = new Vector<String>();
		
	}

}

Open in new window

oggiemcAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:

check here discussion and solution of similar issue with ListSelcetionEvent:
http://forums.devshed.com/java-help-9/listselectionlistener-registers-two-events-on-one-mouse-click-285809.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GlobaLevelProgrammerCommented:
looks good to me...because its a listener...is something tripping it twice during runtime?
0
for_yanCommented:
This prints only once:

import java.awt.event.ActionEvent;


import java.awt.*;
import java.awt.event.*;
import java.io.Serializable;
import java.util.Vector;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class ClientGUI extends JFrame implements ActionListener {
	public static final int defaultWidth = 80, defaultHeight = 40;


	   private String [] listChoices = {"Football", "Music"};
	   private JList streamList;
	   private List list;

	   private Button  clearButton;
	   private Button  sendButton;

	   private JTextArea consoleDisplay;

	   private JScrollPane consoleScroll;

	   public ClientGUI() {
	        super("ClientGUI");
		    Panel topPanel = new Panel();
		    Panel bottomPanel = new Panel();

	        consoleDisplay = new JTextArea(200, 7);
	        consoleDisplay.setLineWrap(true);
	        consoleScroll = new JScrollPane(consoleDisplay);

	        list = new List();
	        list.add("damian");
	        list.add("conor");
	        list.addActionListener(this);
	        topPanel.add(list);

	        streamList = new JList(listChoices);
	        topPanel.add(streamList);
	        streamList.addListSelectionListener(
        			new ListSelectionListener(){

						public void valueChanged(ListSelectionEvent e) {
                            if (! e.getValueIsAdjusting()){
                            System.out.println("here");
							getStreamChoice();
                            }
						}
        });

	        clearButton = new Button("Clear");
	        clearButton.setBackground(Color.white);
	        clearButton.addActionListener(this);
	        topPanel.add(clearButton);

	        sendButton = new Button("Send");
	        sendButton.addActionListener(this);
	        topPanel.add(sendButton);

	        bottomPanel.add(consoleDisplay);

	        this.add(topPanel, BorderLayout.NORTH);
	        this.add(bottomPanel, BorderLayout.CENTER);

	        this.setSize(400, 400);
	        this.setVisible(true);

	        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	    }


 public static void main(String[] args) {
    new ClientGUI();
}


 public void actionPerformed(ActionEvent arg0) {
	// TODO Auto-generated method stub
 }


 public void getStreamChoice(){

	if(streamList.getSelectedValue().equals("Football")){
		FootballStream footy = new FootballStream();
		footy.messageStream.add("hello, welcome to the football stream");
		System.out.println(footy.messageStream.firstElement());
	}
	else{
		System.out.println("Music");
	}
 }
}





 class FootballStream implements Serializable {

	Vector<String> messageStream;

	public FootballStream(){
		this.messageStream = new Vector<String>();

	}

}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.