1 package jrre.gui;
2
3 import java.awt.*;
4 import javax.swing.*;
5 import java.util.*;
6
7
8 public class ControlPanel extends JPanel{
9
10 private int width,height,rows,columns;
11 private String buttonNames[];
12 private JButton buttons[];
13 private Console listener;
14
15 public ControlPanel(int width,int height,int rows,int columns,String [] buttonNames,Console listener){
16 this.width = width;this.height = height;
17 this.rows = rows;this.columns = columns;
18 this.buttonNames = buttonNames;
19 this.listener = listener;
20 buttons = new JButton[buttonNames.length];
21 initPanel();
22 }
23
24 private void initPanel(){
25 setSize(width,height);
26 setMinimumSize(new Dimension(width,height));
27 setMaximumSize(new Dimension(width,height));
28 setPreferredSize(new Dimension(width,height));
29 setBorder(new javax.swing.border.EtchedBorder(javax.swing.border.EtchedBorder.RAISED, java.awt.Color.black, java.awt.Color.gray));
30 setLayout(new GraphPaperLayout(new Dimension(rows,columns)));
31 int i = 0;
32 while(i < buttons.length){
33 for(int r = 0;r < rows && i < buttons.length;r++){
34 for(int c = 0;c < columns && i < buttons.length;c++){
35 add(buttons[i] = new JButton(buttonNames[i]),new Rectangle(r,c,1,1));
36 buttons[i].setBorder(new javax.swing.border.EtchedBorder(javax.swing.border.EtchedBorder.RAISED, java.awt.Color.black, java.awt.Color.gray));
37 buttons[i].addActionListener(listener);
38 i++;
39 }
40 }
41 }
42
43
44 setVisible(true);
45 }
46
47 public void setBackgroundColor(Color c){
48 setBackground(c);
49 repaint();
50 }
51
52 public static void main(String args[]){
53
54 }
55
56 }
This page was automatically generated by Maven