Evo, veceras sam bas raspolozen, pa mi nije bio problem da ti otkucam kod na brzinu :)
Code:
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
public class Test extends JFrame{
//U ovu labelu ćemo ispisivati tekst sa onog tekst polja, sa kog smo izgubili fokus
JLabel label;
JTextField jtfTekstPolje1;
JTextField jtfTekstPolje2;
JTextField jtfTekstPolje3;
public static void main (String args[]){
new Test();
}
public Test(){
super();
getContentPane().setLayout(null);
this.setBounds(100, 100, 300, 160);
jtfTekstPolje1 = new JTextField();
jtfTekstPolje1.setBounds(10, 10, 267, 19);
jtfTekstPolje1.addFocusListener(new FocusAdapter() {
public void focusLost(final FocusEvent e) {
ispisiVrijednost(e);
}
});
getContentPane().add(jtfTekstPolje1);
jtfTekstPolje2 = new JTextField();
jtfTekstPolje2.setBounds(10, 35, 267, 19);
jtfTekstPolje2.addFocusListener(new FocusAdapter() {
public void focusLost(final FocusEvent e) {
ispisiVrijednost(e);
}
});
getContentPane().add(jtfTekstPolje2);
jtfTekstPolje3 = new JTextField();
jtfTekstPolje3.setBounds(10, 60, 267, 19);
jtfTekstPolje3.addFocusListener(new FocusAdapter() {
public void focusLost(final FocusEvent e) {
ispisiVrijednost(e);
}
});
getContentPane().add(jtfTekstPolje3);
label = new JLabel();
label.setBounds(10, 95, 267, 14);
getContentPane().add(label);
this.setVisible(true);
}
private void ispisiVrijednost(FocusEvent e){
if (e.getComponent().equals(jtfTekstPolje1)){
label.setText(jtfTekstPolje1.getText());
}else if (e.getComponent().equals(jtfTekstPolje2)){
label.setText(jtfTekstPolje2.getText());
}else if (e.getComponent().equals(jtfTekstPolje3)){
label.setText(jtfTekstPolje3.getText());
}
}
}