More actions
imported>Unknown No edit summary |
(Repair batch-0001 pages from live compare) |
||
| Line 6: | Line 6: | ||
그냥 count, 루프에서 숫자만 넣어봤따.ㅋㅋ | 그냥 count, 루프에서 숫자만 넣어봤따.ㅋㅋ | ||
내가처음만든자바프로그램2.bmp | |||
== 코드 == | == 코드 == | ||
import java.awt.*; | import java.awt.*; | ||
| Line 13: | Line 13: | ||
public class GridLayoutDemo extends JFrame implements ActionListener{ | public class GridLayoutDemo extends JFrame implements ActionListener{ | ||
private JButton buttons | private JButton buttons[]; | ||
private Container container; | private Container container; | ||
private GridLayout grid1; | private GridLayout grid1; | ||
| Line 49: | Line 49: | ||
//버튼을 생성하여 추가한다. | //버튼을 생성하여 추가한다. | ||
buttons = new JButton | buttons = new JButton[25]; | ||
for(int count = 0; count < 25; count++) { | for(int count = 0; count < 25; count++) { | ||
buttons | buttons[count] = new JButton(Integer.toString(count)); | ||
buttons | buttons[count].addActionListener(this); | ||
container.add(buttons | container.add(buttons[count]); | ||
} | } | ||
setSize(500,500); | setSize(500,500); | ||
| Line 64: | Line 64: | ||
container.validate(); | container.validate(); | ||
} | } | ||
public static void main(String | public static void main(String[] args) { | ||
GridLayoutDemo application = new GridLayoutDemo(); | GridLayoutDemo application = new GridLayoutDemo(); | ||
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
Latest revision as of 23:56, 26 March 2026
BasicJAVA2005/실습2/허아영
이야기
아직 미완성. 랜덤만 넣으면 된다. 안에꺼는 int-> string 형으로 변환해서 그냥 count, 루프에서 숫자만 넣어봤따.ㅋㅋ
내가처음만든자바프로그램2.bmp
코드
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