Examlex
import java.awt.*;
import javax.swing.*;
import java.awt.Color;
public class Checkerboard extends JFrame
{
private final int ROWS = 8;
private final int COLS = 8;
private final int GAP = 2;
private final int NUM = ROWS * COLS;
private int x;
private JPanel pane = new JPanel
(new GridLayout(ROWS, COLS, GAP, GAP));
private JPanel[] panel = new JPanel[NUM];
private Color color1 = Color.WHITE;
private Color color2 = Color.BLUE;
private Color tempColor;
public Checkerboard()
{
super("Checkerboard");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(pane);
for(x = 0; x < NUM; ++x)
{
panel[x] = new JPanel();
pane.add(panel[x]);
if(x % COLS == 0)
{
tempColor = color1;
color1 = color2;
color2 = tempColor;
}
if(x % 2 == 0)
panel[x].setBackground(color1);
else
panel[x].setBackground(color2);
}
}
public static void main(String[] args)
{
Checkerboard frame = new Checkerboard();
final int SIZE = 300;
frame.setSize(SIZE, SIZE);
frame.setVisible(true);
}
}
The above code creates a loop to fill even-positioned squares with one color and odd-positioned squares with another color, resulting in a checkerboard pattern. Describe how JPanels and a GridLayout are used to achieve this effect.
Duty of Care
A legal obligation which is imposed on an individual requiring adherence to a standard of reasonable care while performing any acts that could foreseeably harm others.
Performance-based Regulation
Regulatory approach where entities are measured and rewarded based on their performance outcomes rather than adherence to prescriptive rules.
Consumer Advocacy Groups
Organizations that work to protect the rights and interests of consumers in relation to products, services, and policies.
Environmental Issues
Problems related to the pollution, degradation, and depletion of the natural environment caused by human activities.
Q13: A(n) _ clause is used in the
Q15: A recent sociological experiment sought to determine
Q17: The tag that begins every HTML document
Q25: How is an applet like a Java
Q43: The default size of a component<br>A)GridBagLayout<br>B)JScrollPane<br>C)JPanel<br>D)glass pane<br>E)GridLayout<br>F)action
Q48: Executes again every time the applet becomes
Q85: According to Karl Marx, what is the
Q92: Jai is conducting a sociological research study
Q119: According to Karl Marx, how is class
Q149: In the United States today, the richest