Error javax.swing.JFrame can not be cast to screenPrincipal

1

I'm trying to pass data from one screen to another and I get the following error, I do not know how to fix it.

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: 
javax.swing.JFrame cannot be cast to pantallaPrincipal

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JFrame cannot be cast to pantallaPrincipal
at dialogAlta.<init>(dialogAlta.java:23)
at dialogAlta$2.run(dialogAlta.java:251)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
atjava.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
 BUILD SUCCESSFUL (total time: 1 second)

Here is the code where the error throws me.

private pantallaPrincipal p;

public dialogAlta(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    p = (pantallaPrincipal)parent;
    initComponents();
}
    
asked by J.newbie 09.12.2018 в 21:20
source

1 answer

1

If you want to pass data you would have to pass the parent as a parameter to Main Screen for that you must modify the screen constructorPrincipal

public class PantallaPrincipal {
    private JFrame frame;

    public PantallaPrincipal(JFrame  frame){
        this.frame = frame;
    }
}

Now in dialogAlta () you place:

p = new PantallaPrincipal(parent);

Pd: Classes in JAVA begin with the first letter in uppercase

    
answered by 10.12.2018 / 21:07
source