how to pass data from one class to another

Viewed 70

I am struggling with two classes, my first class must receive data and store it in variables, the second class must send it to the first class.

My problem is that I am doing in the second class new first, which makes a new instance of the first class, and that's why I can't modify what I need.

For example:

public class EditText extends javax.swing.JFrame {
    
    private String fontName = "Arial";
    private int fontStyle = 0;
    private int fontSize = 10;
    
    String filename = "Untitled";

    public EditText() {
        initComponents();
        getProperties();
        updateFont();
        JList lstFont = new javax.swing.JList(
                GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
    }
public class FontWindow extends javax.swing.JFrame {  
   
    private String fontName = "Arial";
    private int fontStyle = 0;
    private int fontSize = 10;
   
    final EditText form = (null);
    
    public FontWindow() {
        initComponents();
        displayFontList();
    }

EditText is the first class, and the second is FontWindow.

I have an event on closing second class where it must transfer data to the first, I tried by doing it by

EditText form = new EditText();

However it does not work, because when I set visible the form it shows a new one, But I need the last one.

0 Answers
Related