So I've been working on this project of mine and I want to refactor it.
What I have is a couple of cases that change my JButttons' icons. These cases are in a method that is in my public GUI class that extends JFrame. What I want to do is simplify the class by moving the cases onto another class. My problem is that the other class doesn't change anything. I managed to make it change an integer but no luck with the buttons.

Here is the changepic method. case 1 doesn't work, case 2 does.

public void ChangePic(int f){
        switch (f){
        case 1: 
        draftcases.CaseOne();
        System.out.println(testnumber);
        break;
        case 2:
            custom.setIcon(cards.E4En);
            custom.setRolloverIcon(cards.E4Eg);
            custom2.setIcon(cards.SCn);
            custom2.setRolloverIcon(cards.SCg);
            custom3.setIcon(cards.DCn);
            custom3.setRolloverIcon(cards.DCg);
            break;

Here is the DraftCases class. The testnumber does change but the buttons stay the same.

public class DraftCases {


public void CaseOne() {

    GUI gui = new GUI();
    Cards cards = new Cards();
    gui.custom.setIcon(cards.AZn);
    gui.custom.setRolloverIcon(cards.AZg);
    gui.custom2.setIcon(cards.TFn);
    gui.custom2.setRolloverIcon(cards.TFg);
    gui.custom3.setIcon(cards.ISn);
    gui.custom3.setRolloverIcon(cards.ISg);
    gui.testnumber = 3;
}
}

I am a beginner and I barely know anything but this shouldn't be a problem. What am I missing?

Recommended Answers

All 3 Replies

in CaseOne you don't change anything in an existing GUI, you just create a new one.
but in my opinion, you're going way to far on this. try adding a setter (setFrameIcon(Icon (or Image) ... )) method to your gui, and call that from the other class.

in your case 2, the one that does work, you don't create a new GUI, you just modify the current one, that's why that one does work.

No I'm not creating a gui, i'm just making a gui object from my GUI class. ( My gui class is called "GUI")
That's why you see me calling gui.custom.

for why reason(s) to call class_members (maybe is/are important == homework) from outside and basics JButtons methods

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.