I'm using JFrame and I'm wondering why int 'a' doesn't update. If I run this program this comes out:: 10 30 10
I want to get
10 30 30
But I cant change my method initialize or initialize2 to a static method because that's not possible while using JFrame. In the example it looks like you can, but in my actual program you can't. Anyone got any ideas? So my question is, how can I update my int a? Thank you.
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class test {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
test window = new test();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public test() {
int a = 10;
initialize(a);
initialize2(a);
}
/**
* Initialize the contents of the frame.
* @param a
*/
public int initialize(int a) {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
System.out.println(a);
a = a + 20;
System.out.println(a);
return a;
}
public void initialize2(int a){
System.out.println(a);
}
}