Oto przykładowy kod:
przykładowa klasa UserInterface
public class UserInterface extends JPanel{
public JLabel name_label = new JLabel("Imię: ");
public JLabel lastname_label = new JLabel("Nazwisko: ");
public JTextField name_tf;
public JTextField lastname_tf;
public JButton zmien_dane;
public String imie;
public String nazwisko;
public UserInterface(ActionListener al) {
imie = "Marian";
nazwisko = "Kowalski";
zmien_dane = new JButton("Edtytuj swoje dane");
zmien_dane.setName("change_data_button");
zmien_dane.addActionListener(al);
name_tf = new JTextField();
name_tf.setEditable(false);
name_tf.setText(imie);
lastname_tf = new JTextField();
lastname_tf.setEditable(false);
lastname_tf.setText(nazwisko);
this.add(name_label);
this.add(lastname_label);
this.add(name_tf);
this.add(lastname_tf);
}
}
klasa Logic
public class Logic implements ActionListener {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JButton button = (JButton) e.getSource();
if(button.getName().equals("change_data_button")) {
// ???????????????????????????????????????????
}
}