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.
Cognitive Structures
Mental frameworks and patterns used to organize and interpret information, influencing how we perceive the world.
Preoperational
A stage in Jean Piaget's theory of cognitive development where children from about 2 to 7 years old engage in symbolic play but struggle with logic and taking the perspective of others.
Concrete Operations
A stage in Jean Piaget's theory of cognitive development, typically occurring between ages 7 and 11, when children gain the ability to think logically about concrete events.
Decenter
The cognitive ability to take multiple aspects of a situation into account and understand perspectives other than one's own.
Q6: Describe and provide an example of the
Q13: When a JFrame is closed, you can
Q17: Comma-separated values (CSV) is a file format
Q24: A(n) _ is a tree of components
Q24: Although everyday cultural practices-such as greeting a
Q30: Placing a file in the _ directory
Q43: The _ method provides information about the
Q50: Even if you simply want to display
Q61: When you create a(n) _, you can
Q69: <object code = "AClass.class" width = 300