Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need the following two codes combined into one java file: import java.awt.*; i

ID: 3550416 • Letter: I

Question

I need the following two codes combined into one java file:



import java.awt.*;


import java.awt.event.*;


public class ColorFrame extends Frame implements ActionListener


{


Button colorButton = new Button("Change Color");


Panel cp = new Panel();


Panel np = new Panel();


Panel sp = new Panel();


Panel ep = new Panel();


Panel wp = new Panel();


int count = 0;


public ColorFrame()


{


super("Colors");


setLayout(new BorderLayout());


cp.add(colorButton);


add(np, "North");


add(sp, "South");


add(ep, "East");


add(wp, "West");


add(cp, "Center");


colorButton.addActionListener(this);


}


public void actionPerformed(ActionEvent e)


{


if(count%5==0)


np.setBackground(Color.blue);


else if(count%5==1)


ep.setBackground(Color.orange);


else if(count%5==2)


wp.setBackground(Color.green);


else if(count%5==3)


sp.setBackground(Color.yellow);


else


{


ep.setBackground(Color.white);


sp.setBackground(Color.white);


np.setBackground(Color.white);


wp.setBackground(Color.white);


}


++count;


}


}






And this:


public class UseColorFrame


{


public static void main(String[] args)


{


ColorFrame cFrame = new ColorFrame();


cFrame.setSize(350,250);


cFrame.setVisible(true);


}


}

Explanation / Answer

import java.awt.*;


import java.awt.event.*;


public class ColorFrame extends Frame implements ActionListener


{


Button colorButton = new Button("Change Color");


Panel cp = new Panel();


Panel np = new Panel();


Panel sp = new Panel();


Panel ep = new Panel();


Panel wp = new Panel();


int count = 0;


public ColorFrame()


{


super("Colors");


setLayout(new BorderLayout());


cp.add(colorButton);


add(np, "North");


add(sp, "South");


add(ep, "East");


add(wp, "West");


add(cp, "Center");


colorButton.addActionListener(this);


}


public void actionPerformed(ActionEvent e)


{


if(count%5==0)


np.setBackground(Color.blue);


else if(count%5==1)


ep.setBackground(Color.orange);


else if(count%5==2)


wp.setBackground(Color.green);


else if(count%5==3)


sp.setBackground(Color.yellow);


else


{


ep.setBackground(Color.white);


sp.setBackground(Color.white);


np.setBackground(Color.white);


wp.setBackground(Color.white);


}


++count;


}

public static void main(String[] args)


{


ColorFrame cFrame = new ColorFrame();


cFrame.setSize(350,250);


cFrame.setVisible(true);


}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote