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

Create a JFrame that uses BorderLayout. Place a JButton in the center region. Ea

ID: 3532218 • Letter: C

Question

Create a JFrame that uses BorderLayout. Place a JButton in the center region. Each time the user clicks the JButton, change the background color in one of the other regions. Save the file as JColorFrame.java.


Okay, So I wrote the program in netbeans and I didn't get any errors during the build. But when I compile and run the program from the terminal nothing happens. Is there somethind I'm doing wrong?


/*import java.awt.*;


import java.awt.event.*;



public class JColorFrame extends Frame implements ActionListener


{


Button colorButton = new Button("Change");


Panel cp = new Panel();


Panel np = new Panel();


Panel sp = new Panel();


Panel ep = new Panel();


Panel wp = new Panel();


int count = 0;


public JColorFrame()


{


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.green);


else if(count%5==1)


ep.setBackground(Color.magenta);


else if(count%5==2)


wp.setBackground(Color.orange);


else if(count%5==3)


sp.setBackground(Color.red);


else


{


ep.setBackground(Color.white);


sp.setBackground(Color.white);


np.setBackground(Color.white);


wp.setBackground(Color.white);


}



++count;


}


}

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/


/**

*

* @author SeriousOrangutan

*/

public class JColorFrame {


/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

}

}

Explanation / Answer

if you get errors about the library package in terminal,try to install graphics libary .jar file in your laptop. If your code gets hanged up., it's bcause of stack overflow. stack overflow is an error which is caused due to unending code. U have to modify your code.