import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GridLayer
{
int nr_linii=0,nr_coloane=0;
public static void main(int x,int y)
{
GridLayer gui=new GridLayer(x,y);
}
JFrame frame;
JLabel label;
GridLayer(int x,int y)
{
if(x>=0&&y>=0)
nr_linii=x;
nr_coloane=y;
frame=new JFrame("Butoane");
JPanel panel=new JPanel();
panel.setLayout(new GridLayout(nr_linii,nr_coloane));
for(int i=0;i<(nr_linii*nr_coloane);i++)
{
label=new JLabel(""+(i+1));
label.setOpaque(true);
int red=(int )(Math.random()*255);
int green=(int )(Math.random()*255);
int blue=(int )(Math.random()*255);
Color random=new Color(red,green,blue);
//Color complementary=new Color (255-red,255-green,255-blue);
label.setBackground(random);
panel.add(label);
}
frame.add(panel,BorderLayout.CENTER);
frame.setVisible(true);
frame.setSize(nr_linii*75,nr_coloane*75);
}
}
Niciun comentariu:
Trimiteți un comentariu