forked from shinyewon/Piano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject_SYC
49 lines (40 loc) · 1.4 KB
/
Project_SYC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package teamproject;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GridExample extends JFrame {
private static final int ROWS = 8;
private static final int COLS = 30;
public GridExample() {
setTitle("Grid Example");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel gridPanel = new JPanel(new GridLayout(ROWS, COLS));
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
JButton cellButton = new JButton();
cellButton.setPreferredSize(new Dimension(30, 30)); // 셀 크기 조절
cellButton.addActionListener(new CellClickListener(row, col));
gridPanel.add(cellButton);
}
}
add(gridPanel);
setVisible(true);
}
private class CellClickListener implements ActionListener {
private int row;
private int col;
public CellClickListener(int row, int col) {
this.row = row;
this.col = col;
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Clicked on cell: (" + row + ", " + col + ")");
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new GridExample());
}
}