Hello world, I am kinda new to java and I have a problem, I am trying to access a local jframe in a different class eg
Public class Mine extends JFrame {
public Mine() {
setSize(200,200);
setTitle("Mine");
setVisible("true");
JButton b = new JButton("Open");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFrame fine = new JFrame("How are You");
fine.sizeSize(200,200);
fine.setVisible(true);
}
)};
}
}
Now I am trying to access the local JFrame which is :
JFrame fine = new JFrame("How are you");
Please I this is not good code, all I am asking is that is there a way I can access a local JFrame in another class constructor like
It's a little difficult to ascertain what you're attempting here, or why you would want to do it, but if you want to access that JFrame fine from a different class, you should declare it as an instance variable and create an accessor method for it:
Public class Mine extends JFrame {
private JFrame fine;
public Mine() {
...
...
fine = new JFrame("How are You");
...
...
}
public JFrame getFine() {
return fine;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.