-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewSetpieceTactics.java
More file actions
130 lines (109 loc) · 3.67 KB
/
viewSetpieceTactics.java
File metadata and controls
130 lines (109 loc) · 3.67 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package DB2025Team09;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Font;
import java.sql.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.table.*;
public class viewSetpieceTactics extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTable table;
private int idTeam, idPlayer;
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
try {
viewSetpieceTactics frame = new viewSetpieceTactics(1);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
});
}
private void loadTacticsData() {
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.setRowCount(0);
String query = "SELECT idTactic, tacticName, tacticFormation, explainTactics, ableToTactic "
+ "FROM DB2025_Tactics WHERE tacticType = 'Setpiece' AND idTeam = ?";
try (Connection conn = DBUtil.getConnection();
PreparedStatement pstmt = conn.prepareStatement(query)) {
pstmt.setInt(1, idTeam);
try (ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
int idTactic = rs.getInt("idTactic");
String tacticName = rs.getString("tacticName");
String tacticFormation = rs.getString("tacticFormation");
String explainTactics = rs.getString("explainTactics");
String able = (rs.getInt("ableToTactic") == 1) ? "가능" : "불가능";
Object[] row = {idTactic, tacticName, tacticFormation, explainTactics, able};
model.addRow(row);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public viewSetpieceTactics(int idTeam) {
this.idTeam = idTeam;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 650, 350); // 창 크기 줄임
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnBack = new JButton("Back");
btnBack.addActionListener(e -> {
new viewTactics(idTeam).setVisible(true);
dispose();
});
btnBack.setBounds(6, 6, 117, 29);
contentPane.add(btnBack);
JLabel lblTitle = new JLabel("세트피스 전술");
lblTitle.setFont(new Font("Lucida Grande", Font.BOLD, 18));
lblTitle.setHorizontalAlignment(SwingConstants.CENTER);
lblTitle.setBounds(6, 32, 620, 29); // 라벨 너비 줄임
contentPane.add(lblTitle);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(6, 66, 620, 230); // 스크롤 영역 크기 줄임
contentPane.add(scrollPane);
table = new JTable() {
public boolean isCellEditable(int row, int column) {
return false;
}
};
table.setModel(new DefaultTableModel(
new Object[][] {},
new String[] {
"전술 ID", "필드 전술 이름", "포메이션", "전술 설명", "사용 가능 여부"
}
));
table.getColumnModel().getColumn(3).setCellRenderer(new TextAreaRenderer());
table.setRowHeight(60);
table.setRowMargin(5);
scrollPane.setViewportView(table);
loadTacticsData();
}
// 줄바꿈용 셀 렌더러
class TextAreaRenderer extends JTextArea implements TableCellRenderer {
public TextAreaRenderer() {
setLineWrap(true);
setWrapStyleWord(true);
setOpaque(true);
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus,
int row, int column) {
setText(value == null ? "" : value.toString());
if (isSelected) {
setBackground(table.getSelectionBackground());
setForeground(table.getSelectionForeground());
} else {
setBackground(table.getBackground());
setForeground(table.getForeground());
}
setFont(table.getFont());
return this;
}
}
}