The label should be created prior to the event. If the label and the eventhandler are contained in different classes you can get this done in many ways. I prefer this one:
The class containing the eventhandler gets the pointer to the class containing the label as a contructor parameter (or a setter method) and the class with the label has a public method for setting the label value.
The class with the label
Code:
public class AClass {
private JLabel aLabel=new JLabel();
.
(place the label somewhere...)
.
public void setComboLabelValue(String s) {
aLabel.setText(s);
}
}
The eventhandler class' constructor would then be like:
Code:
public class ControllerClass {
private AClass ac=null;
public ControllerClass (AClass ac) {
this.ac=ac;
}
.
.
public synchronized void actionPerformed (ActionEvent event) {
String command = event.getActionCommand();
if(command.equals("recipientName")){
JComboBox cb = (JComboBox)event.getSource();
String combName = (String)cb.getSelectedItem();
System.out.println(combName); // prints selected item to console
ac.setComboLabelValue(combName); // voila !
.
.
.
Bookmarks