Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

When I create a Swing GUI class, I can change from one JFrame to the other via a jButton using the following code:

private void btnChangeClassActionPerformed(java.awt.event.ActionEvent evt) {                                               

        ClassA ca = new ClassA();
        ca.setVisible(true);
        this.dispose();
    }

But when I create a blank java class (hard coding), this code does not work as the .setVisible(true); does not work. In fact when I press ctrl + space to bring up suggestions, nothing is listed after ca.. This only occurs when I try to change jFrames with hard coded applications.

The stacktrace produces this error:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException:
Uncompilable source code - Erroneous sym type: classPackage.ClassB.setVisible

How can I correct this error?

share|improve this question
    
I am not sure what you mean by "hard coded". could you provide more source code? – Christian Ammann Jul 7 at 17:52
    
What I mean by hard coded is that I am not using 'drag and drop'. Everything is coded from scratch. – Osiris93 Jul 7 at 17:56
    
See The use of multiple JFrames, good / bad practice and for better help sooner, please post a Minimal, Complete, and Verifiable example not just a code snippet, so we can copy-paste it and see the same error as you – Frakcool Jul 7 at 18:10
up vote 1 down vote accepted

I am not sure what's your problem, but what you a trying to do should work. Here is my example for ClassA.java

public class ClassA extends JFrame{
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("helo moto");
        ClassA a = new ClassA();
    }

    ClassA(){
        super();
        setSize(200, 200);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        JButton button = new JButton("ClassB");
        button.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                new ClassB();
                ClassA.this.dispose();
            }
        });
        Container container = getContentPane();
        container.add(button);
        setVisible(true);
    }
}

And here is ClassB.java:

public class ClassB extends JFrame{
    ClassB(){
        super();
        setSize(200, 200);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        JButton button = new JButton("ClassA");

        button.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                new ClassA();
                ClassB.this.dispose();
            }
        });
        Container container = getContentPane();
        container.add(button);
        setVisible(true);
    }   
}
share|improve this answer
    
There was my problem...my ClassB was not extending JFrame. Thanx :D – Osiris93 Jul 7 at 18:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.