글쓴이 :조신제 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]);
}
}