Moving and organizing Java codes on another files

0 votes

I would like to create a new file and put this block of action buttons codes to be organized on the other files i dont know how i would be able to move it.

Iam making this code and its a little bit disorganized and im having a hard time on what is their purpose.

Is there any other easier method to create a actionlistener codes?

public void buttonAction (){
        
        
        bgButton[0].addActionListener(e -> {
            
            bgPanel[0].setVisible(false);
            bgPanel[0].remove(bgButton[0]);
            bgPanel[1].setVisible(true);
            
        });
        
        
        
        
            
        for (int a = 3,c=0 ; a <12; a++, c++){
            
            final int b=c;
            final int d=a;
        bgButton[a].addActionListener(e -> {
            
            
            if (input>=0&&input <=9&&Num[b]!=0){
            input = Num[b]*10;
            
                if(input!=0)
                    
                    createObject(1,12,283,245,85,61,numFile[b]);//12
                    bgButton[d].setEnabled(false);
                    Number[b]=-1;
            } else if (input >9&&input<100&&input%10==0&&Num[b]!=0&&buttonClicked){
                input += Num[b];
                buttonClicked = !buttonClicked;
                createObject(1,13,432,245,85,61,numFile[b]);//13
                bgButton[d].setEnabled(false);
                    Number[b]=-1;
                    
            }else if (Num[b]==0&&buttonClicked){
                
                input += Num[b];
                createObject(1,13,432,245,85,61,numFile[b]);//13
                bgButton[d].setEnabled(false);
                buttonClicked = !buttonClicked;
                Number[b]=-1;
                
            }
            
            System.err.println("total  " + input);
            bgPanel[1].revalidate();
            bgPanel[1].repaint();
                    });
        
        }
        
        
        
        bgButton[14].addActionListener(e -> {
            
            for (int c =0 ,a=3; c <9; a++,c++){
                final int b = a;
                final int d=c;
                
                int firstNum = input/10;
                int secondNum=input%10;
                
                
                if (Number[c]==-1&&bgButton[13]!=null){
                    
                    attack = input;
                    
                    generateSoloNum(d);
                    bgButton[b].setEnabled(true);
                    updateButtonIcon(b,64,48,numFile[d]);
                    bgPanel[1].remove(bgButton[12]);
                    
                    bgPanel[1].remove(bgButton[13]);
                    bgPanel[1].revalidate();
                    bgPanel[1].repaint();
                    
                    Number [c]=0;
                    
                    input =0;
                    
                }
                
                
                
            }
            buttonClicked = true;
            bgButton[13]=null;
        });
        
        
        createObject(1,15,149,244,50,38,"res/imageAssets/x.png");//15
        
        bgButton[15].addActionListener(e -> {
            input = 0;
            bgPanel[1].remove(bgButton[12]);
            bgPanel[1].remove(bgButton[13]);
            bgPanel[1].revalidate();
            bgPanel[1].repaint();
            buttonClicked = true;
            for (int a = 3,c=0; a<12;a++,c++){
                bgButton[a].setEnabled(true);
                Number [c]=0;
            }
        });
        
    }

I tried import Main.UI; and import Main.Action;

Action is the new file that i want to move it into.

tried using chat gpt but it makes no sense

Jan 31, 2023 in Java by Tejashwini
• 3,820 points

edited 5 days ago 6 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP