~java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GridLayoutDemo extends JFrame implements ActionListener{
private JButton buttons[];
private Container container;
private GridLayout grid1;
//GUI 구성
public GridLayoutDemo()
{
super("Random numbers ver.1");
//레이아웃을 구성한다.
grid1 = new GridLayout(5,5);
//컨텐트 패인을 얻고 레이아웃을 설정한다.
container = getContentPane();
container.setLayout(grid1);
//메뉴
JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic('F');
//Exit 메뉴
JMenuItem exitItem = new JMenuItem("Exit");
exitItem.setMnemonic('x');
fileMenu.add(exitItem);
exitItem.addActionListener(
new ActionListener() {
//클릭하면 종료
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
}
);
//메뉴바 부착
JMenuBar bar = new JMenuBar();
setJMenuBar(bar);
bar.add(fileMenu);
//버튼을 생성하여 추가한다.
buttons = new JButton[25];
for(int count = 0; count < 25; count++) {
buttons[count] = new JButton(Integer.toString(count));
buttons[count].addActionListener(this);
container.add(buttons[count]);
}
setSize(500,500);
setVisible(true);
}
public void actionPerformed(ActionEvent event)
{
container.validate();
}
public static void main(String[] args) {
GridLayoutDemo application = new GridLayoutDemo();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
----
아영아..ㅠ.ㅜ 아직 위키어려..ㅠ.ㅜ 그림파일에 띄어쓰기하지마.. 파싱하기 힘들어..T.T