±Û¾´ÀÌ :Á¶½ÅÁ¦ 1998³â 8¿ù 05ÀÏ 13:41:49
In Reply to: [Áú¹®] GridLayoutÀÌ Àß ¾ÈµÇ´Â ±º¿ä...HELP~~ posted by ÀüÀç¿Ï on 1998³â 8¿ù 03ÀÏ 19:07:57:
import java.awt.*;
import java.awt.event.*;
public class Lay extends Frame
{
private static int labelNum = 50; //»ý¼ºµÉ ·¹À̺íÀÇ °¹¼öÀÔ´Ï´Ù.
Panel myPanel = new Panel();
public Lay()
{
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
System.exit(-1);
}
});
addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent evt) {
Frame frame = (Frame)evt.getSource();
Dimension d = frame.getSize();
int w = d.width;
int h = d.height;
System.out.println("Frame's width : " + w + "\nFrame's height : " + h);
}
});
myPanel.setLayout(new GridLayout(0, labelNum, 0, 0));
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ·¹À̾ƿô °ü¸®ÀÚ¸¦ ¼³Á¤Çß½À´Ï´Ù.
myPanel.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
Panel p = (Panel)evt.getSource();
Dimension d = p.getSize();
int w = d.width;
int h = d.height;
System.out.println("Panel's width : " + w + "\nPanel's height : " + h);
}
});
this.setSize(600,60);
}
public static void main(String args[])
{
Lay myLay = new Lay();
myLay.addLabel(myLay.makeLabel());
myLay.add(myLay.myPanel);
myLay.show();
}
public static Label[] makeLabel()
{
Label[] temp_label = new Label[labelNum];
int c = -1;
for(int i = 0 ; i < temp_label.length ; i++)
{
temp_label[i] = new Label();
c *= -1;
if(c == -1 ) {
temp_label[i].setBackground(Color.white);
}else {
temp_label[i].setBackground(Color.black);
}
if( (temp_label.length-1) == i) temp_label[i].setBackground(Color.blue);
}
return temp_label;
}
public void addLabel(Label[] l)
{
int c = l.length;
for(int i = 0 ; i < c ; i ++) myPanel.add(l[i]);
}
}