public class NewJPanel extends javax.swing.JPanel {
/** Creates new form NewJPanel */
public NewJPanel() {
initComponents();
CreateUI();
}
public void CreateUI() {
JFrame window = new JFrame("Test");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setBounds(50, 50, 400, 400);
JPanel panel = new JPanel(new BorderLayout());
panel.add(CreateDisplay(), BorderLayout.CENTER);
window.add(panel, BorderLayout.CENTER);
window.setVisible(true);
}
private JPanel CreateDisplay() {
JPanel mainPanel = new JPanel(new BorderLayout());
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
final JPanel slots = new JPanel();
slots.setBorder(BorderFactory.createLineBorder(Color.black));
slots.setBackground(new Color(255, 222, 188));
slots.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent me) {
}
public void mousePressed(MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
}
public void mouseEntered(MouseEvent me) {
slots.setBackground(new Color(255, 255, 188));
}
public void mouseExited(MouseEvent me) {
slots.setBackground(new Color(255, 222, 188));
}
});
jPanel1.add(slots);
}
}
mainPanel.add(jPanel1, BorderLayout.CENTER);
return mainPanel;
}
/** This method is called from within the constructor to
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 459, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 430, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(269, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(63, Short.MAX_VALUE))
);
}// </editor-fold>
public static void main(String[] args) {
new NewJPanel();
// TODO code application logic here
}
// private JPanel slotsPanel = new JPanel(new GridLayout(8, 8));
// Variables declaration - do not modify
/*
private javax.swing.JPanel jPanel1;
*/private JPanel jPanel1 = new JPanel(new GridLayout(8, 8));
// End of variables declaration
}