Domanda

I've created a JDialog, and passed my JFrame in with it.

for (int i = 0; i < digiProdRadioBtns.length; i++) {
        if (digiProdCheck[i].isSelected()) {

            ProdDialog a = new ProdDialog(digiPopup[i], frame, digiProductList.getProduct(counter), digiProductList);
        } 

I've then tried to access the methods of the JFrame from within the JDialog, but cannot.

public class ProdDialog extends JDialog {

cdDialog = new JDialog(jFrame, true);



 this.jframe = jFrame;
 jframe.newEmployee();

I've read that what I'm trying to do is possible, any reason as to why it's not working for me?

È stato utile?

Soluzione

JFrame and JDialog are top-level containers typically used as view components. In general, they don't communicate except to position a dialog relative to its parent frame. Instead, arrange for your views to communicate using a PropertyChangeEvent, as shown in this example. Having a separate model that contains a notional List<Product> will let you employ the pattern discussed here.

Altri suggerimenti

I'm missing a lot of context here, what is it that is not working for you?

I assume you are seeing an error on the jframe.newEmployee(); command saying that the method is undefined, if so then that is reasonable because the JFrame class does not have that method, if your class is class ProdJFrame and it extends JFrame and has that method, then you need to do ((ProdJFrame)jframe).newEmployee();

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top