How can I call a method when I press a button from a separate class?
For example, when the click event fires on the Save button I want to call the setRDF method from the other class named GenerateRDF
This is my code:
public class PersonalInfo extends JPanel { private void initialize() { JButton btnSave = new JButton("Save"); btnSave.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // call the `setRDF` method here } }); } } public class GenerateRDF extends Object { public void setRDF() { String personURI = "http://localhost/amitkumar"; String givenName = "Amit"; String familyName = "Kumar"; String fullName = givenName+familyName; Model model = ModelFactory.createDefaultModel(); Resource node = model.createResource(personURI) .addProperty(VCARD.FN, fullName) .addProperty(VCARD.N, model.createResource() .addProperty(VCARD.Given, givenName) .addProperty(VCARD.Family, familyName)); model.write(System.out); } }
extends Objectis not necessary, it's implicit. All classes extendObjectby default in java. And ifObjectis a class you created, you should rename it. Creating classes with the same name as other default java classes is the best way to confuse other developers.