1. 개요
- 강사님이 자바 스윙으로 뮤직 플레이어를 만들어보라고 하셨다.
- 사용해야할 주요기능은 DB 연동, Image, Audio 등이다.
2. 자료구조
3. 소스코드
3.1 Main
1
2
3
4
5
6
7
8
9
10
11
12
13 |
package Main;
import Frame.MainFrame;
public class Main {
public static void main(String[] args) {
new MainFrame();
}
}
|
cs |
3.2 MainFrame
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233 |
package Frame;
import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import Center.FirstPanel;
import Center.InsertPanel;
import Center.ShowPanel;
import Dialog.DeleteConfirmDialog;
import Dialog.ListPlzDialog;
import Dialog.ListPlzDialog2;
import Dialog.OneChkPlzDialog;
import Dialog.OneChkPlzDialog2;
import Head.CategoriPanel;
import Head.TitlePanel;
public class MainFrame extends JFrame implements ActionListener, MouseListener{
private JPanel northPanel;
private JPanel centerPanel;
private TitlePanel tp;
private CategoriPanel cp;
private FirstPanel fp;
private InsertPanel ip;
private ShowPanel sp;
public MainFrame() {
setTitle("메인화면");
setSize(1900, 1000);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Head
northPanel = new JPanel();
northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS));
//Head - 메인화면으로
tp = new TitlePanel();
tp.addMouseListener(this);
northPanel.add(tp);
//Head - 음악 목록 보기
cp = new CategoriPanel();
cp.getShowAlbumListBtn().addActionListener(this);
//Head - 음악 추가
cp.getInsertAlbumBtn().addActionListener(this);
//Head - 음악 수정
cp.getUpdateAlbumBtn().addActionListener(this);
//Head - 음악 삭제
cp.getDeleteAlbumBtn().addActionListener(this);
//Head - 음악 듣기
cp.getStartMusicBtn().addActionListener(this);
northPanel.add(cp);
add(northPanel, BorderLayout.NORTH);
//Center
centerPanel = new JPanel();
//Center - 첫패널
fp = new FirstPanel();
fp.setVisible(true);
centerPanel.add(fp);
//Center - 음악 목록 보기 패널
sp = new ShowPanel();
sp.setVisible(false);
centerPanel.add(sp);
//Center - 음악 추가 패널
ip = new InsertPanel();
ip.setVisible(false);
centerPanel.add(ip);
//Center - scrollpane
JScrollPane scroll = new JScrollPane(centerPanel);
//scroll.setSize(1900, 700);
//scroll.setLocation(0, 50);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scroll.setViewportView(centerPanel);
add(scroll, BorderLayout.CENTER);
//add(centerPanel, BorderLayout.CENTER);
setVisible(true);
}
//Head btn events
@Override
public void actionPerformed(ActionEvent e) {
//음악 목록 보기 버튼을 눌렸을 때
if(e.getSource()==cp.getShowAlbumListBtn()){
sp.showMethod();
//sp.repaint();
fp.setVisible(false);
ip.setVisible(false);
sp.setVisible(true);
}
//음악 삽입 버튼을 눌렸을 때
if(e.getSource()==cp.getInsertAlbumBtn()){
fp.setVisible(false);
sp.setVisible(false);
ip.setVisible(true);
}
//음악 수정 버튼을 눌렸을 때
if(e.getSource()==cp.getUpdateAlbumBtn()){
//음악 수정은 음악 목록 보기에서 체크 되어 있을 때만 가능
//음악 목록 보기가 활성화 되어 있는지 확인
if(sp.isVisible()){
if(sp.getChk()==1){ // 음악이 1개만 선택 되어 있다면?
UpdateFrame uf = new UpdateFrame();
fp.setVisible(false);
ip.setVisible(false);
sp.setVisible(false);
}else{ // 음악이 선택되지 않았거나 여러개 선택되었다면?
new Dialog(new OneChkPlzDialog());
fp.setVisible(false);
ip.setVisible(false);
sp.setVisible(true);
}
}else{ //음악 목록 보기가 활성화 되어 있지 않다면?
new Dialog(new ListPlzDialog());
fp.setVisible(false);
ip.setVisible(false);
sp.setVisible(true);
}
}
//삭제 버튼을 눌렸을 때
if(e.getSource() == cp.getDeleteAlbumBtn()){
//음악 삭제도 음악 목록 보기에서 체크 되어 있을 때만 가능
//음악 목록 보기가 활성화 되어 있는지 확인
if(sp.isVisible()){
if(sp.getChk()==0){ // 음악이 선택 되어 있지않다면?
new Dialog(new OneChkPlzDialog2());
fp.setVisible(false);
ip.setVisible(false);
sp.setVisible(true);
}else{
DeleteConfirmDialog dcd = new DeleteConfirmDialog();
fp.setVisible(false);
ip.setVisible(false);
sp.setVisible(true);
}
}else{ //음악 목록 보기가 활성화 되어 있지 않다면?
new Dialog(new ListPlzDialog());
fp.setVisible(false);
ip.setVisible(false);
sp.setVisible(true);
}
}
//음악 듣기 버튼을 눌렸을 때
if(e.getSource() == cp.getStartMusicBtn()){
//음악 듣기도 음악 목록 보기에서 체크되어 있을 때만 가능
//음악 목록 보기가 활성화 되어 있는지 확인
if(sp.isVisible()){
if(sp.getChk()==1){ // 음악이 1개만 선택 되어 있다면?
MusicFrame mf = new MusicFrame();
fp.setVisible(false);
ip.setVisible(false);
sp.setVisible(true);
}else{ // 음악이 선택되지 않았거나 여러개 선택되었다면?
new Dialog(new OneChkPlzDialog());
fp.setVisible(false);
ip.setVisible(false);
sp.setVisible(true);
}
}else{ //음악 목록 보기가 활성화 되어 있지 않다면?
new Dialog(new ListPlzDialog2());
fp.setVisible(false);
ip.setVisible(false);
sp.setVisible(true);
}
}
}
@Override
public void mouseClicked(MouseEvent e) {
if(e.getSource()==tp){
sp.setVisible(false);
ip.setVisible(false);
fp.setVisible(true);
}
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
}
|
cs |
3.3 CategoriPanel
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 |
package Head;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JPanel;
public class CategoriPanel extends JPanel {
private JButton showAlbumListBtn;
private JButton insertAlbumBtn;
private JButton updateAlbumBtn;
private JButton deleteAlbumBtn;
private JButton startMusicBtn;
public CategoriPanel() {
setBackground(new Color(171,242,0));
setSize(1900, 50);
showAlbumListBtn = new JButton("음악 목록 보기");
add(showAlbumListBtn);
insertAlbumBtn = new JButton("음악 추가");
add(insertAlbumBtn);
updateAlbumBtn = new JButton("음악 수정");
add(updateAlbumBtn);
deleteAlbumBtn = new JButton("음악 삭제");
add(deleteAlbumBtn);
startMusicBtn = new JButton("음악 듣기");
add(startMusicBtn);
}
public JButton getShowAlbumListBtn() {
return showAlbumListBtn;
}
public JButton getInsertAlbumBtn() {
return insertAlbumBtn;
}
public JButton getUpdateAlbumBtn() {
return updateAlbumBtn;
}
public JButton getDeleteAlbumBtn() {
return deleteAlbumBtn;
}
public JButton getStartMusicBtn(){
return startMusicBtn;
}
}
|
cs |
3.4 TitlePanel
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 |
package Head;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
public class TitlePanel extends JPanel {
private BufferedImage image;
public TitlePanel(){
try {
File file = new File("C:\\Temp\\titlePic.png");
image = ImageIO.read(file);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void paint(Graphics g) {
g.drawImage(image, 0, 0, null);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(1900, 200);
}
public BufferedImage getImage() {
return image;
}
}
|
cs |
3.5 Album
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 |
package DB;
import java.io.InputStream;
public class Album {
private int id;
private String name;
private String date;
private String singer;
private String title;
private String genre;
private String picName;
private InputStream picture;
private int picLength;
private String musicName;
private InputStream music;
private int musicLength;
public String getMusicName() {
return musicName;
}
public void setMusicName(String musicName) {
this.musicName = musicName;
}
public InputStream getMusic() {
return music;
}
public void setMusic(InputStream music) {
this.music = music;
}
public int getMusicLength() {
return musicLength;
}
public void setMusicLength(int musicLength) {
this.musicLength = musicLength;
}
public String getPicName() {
return picName;
}
public void setPicName(String picName) {
this.picName = picName;
}
public int getPicLength() {
return picLength;
}
public void setPicLength(int picLength) {
this.picLength = picLength;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getSinger() {
return singer;
}
public void setSinger(String singer) {
this.singer = singer;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getGenre() {
return genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
public InputStream getPicture() {
return picture;
}
public void setPicture(InputStream picture) {
this.picture = picture;
}
}
|
cs |
3.6 DBConnector
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246 |
package DB;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
public class DBConnector {
private Connection con = null;
private String driverName = "com.mysql.jdbc.Driver";
private String dbURL = "jdbc:mysql://192.168.0.20:3306/melon";
private String dbUser = "IT";
private String dbPassword = "1234";
private Statement stmt;
private PreparedStatement pstmt;
private ResultSet rs;
private ArrayList<Album> data = new ArrayList<>();
public DBConnector() {
try {
Class.forName(driverName);
con = DriverManager.getConnection(dbURL, dbUser, dbPassword);
} catch (Exception e) {
e.printStackTrace();
}
}
//음악 추가
public void insertDB(String name, String date, String singer, String title, String genre, InputStream picture, String picName, int picLength, InputStream music, String musicName, int musicLength){
try {
String sql = "insert into album (name, date, singer, title, genre, picname, musicname)"
+ "values (?, ?, ?, ?, ?, ?, ?)";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, date);
pstmt.setString(3, singer);
pstmt.setString(4, title);
pstmt.setString(5, genre);
pstmt.setString(6, picName);
pstmt.setString(7, musicName);
pstmt.executeUpdate();
sql = "insert into pic (picname, picture, piclength) values (?, ?, ?)";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, picName);
pstmt.setBinaryStream(2, picture, picLength);
pstmt.setInt(3, picLength);
pstmt.executeUpdate();
sql = "insert into music (musicname, music, musiclength) values (?, ?, ?)";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, musicName);
pstmt.setBinaryStream(2, music, musicLength);
pstmt.setInt(3, musicLength);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if(pstmt!=null){
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
//음악 목록 보기
public ArrayList<Album> showDB(){
try {
String sql = "select a.*, p.picture, p.piclength, m.music, m.musiclength from album a join pic p join music m on a.picname = p.picname and a.musicname = m.musicname";
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next()){
Album ab = new Album();
ab.setId(rs.getInt(1));
ab.setName(rs.getString(2));
ab.setDate(rs.getString(3));
ab.setSinger(rs.getString(4));
ab.setTitle(rs.getString(5));
ab.setGenre(rs.getString(6));
ab.setPicName(rs.getString(7));
ab.setMusicName(rs.getString(8));
ab.setPicture(rs.getBinaryStream(9));
ab.setPicLength(rs.getInt(10));
ab.setMusic(rs.getBinaryStream(11));
ab.setMusicLength(rs.getInt(12));
data.add(ab);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(rs!=null){
rs.close();
}
if(stmt!=null){
stmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return data;
}
//음악 검색
public Album selectDB(int id){
Album ab = new Album();
try {
String sql = "select a.*, p.picture, p.piclength, m.music, m.musiclength from album a join pic p join music m on a.picname = p.picname and a.musicname = m.musicname and id="+id;
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next()){
ab.setId(rs.getInt(1));
ab.setName(rs.getString(2));
ab.setDate(rs.getString(3));
ab.setSinger(rs.getString(4));
ab.setTitle(rs.getString(5));
ab.setGenre(rs.getString(6));
ab.setPicName(rs.getString(7));
ab.setMusicName(rs.getString(8));
ab.setPicture(rs.getBinaryStream(9));
ab.setPicLength(rs.getInt(10));
ab.setMusic(rs.getBinaryStream(11));
ab.setMusicLength(rs.getInt(12));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(rs!=null){
rs.close();
}
if(stmt!=null){
stmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return ab;
}
//음악 수정
public void updateDB(int id, String name, String date, String singer, String title, String genre, String picName, InputStream picture, int length, String musicName, InputStream music, int musicLength){
try {
String sql = "update album set name=?, date=?, singer=?, title=?, genre=?, picname=?, musicname=? where id=?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, date);
pstmt.setString(3, singer);
pstmt.setString(4, title);
pstmt.setString(5, genre);
pstmt.setString(6, picName);
pstmt.setString(7, musicName);
pstmt.setInt(8, id);
pstmt.executeUpdate();
sql = "update pic set picture=?, piclength=? where picname=?";
pstmt = con.prepareStatement(sql);
pstmt.setBinaryStream(1, picture, length);
pstmt.setInt(2, length);
pstmt.setString(3, picName);
pstmt.executeUpdate();
sql = "update music set music=?, musiclength=? where musicname=?";
pstmt = con.prepareStatement(sql);
pstmt.setBinaryStream(1, music, musicLength);
pstmt.setInt(2, musicLength);
pstmt.setString(3, musicName);
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(pstmt!=null){
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
//음악 삭제
public void deleteDB(int id){
try {
String picName = null;
String sql = "select picname from album where id="+id;
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
if(rs.next()){
picName = rs.getString(1);
}
String musicName = null;
sql = "select musicname from album where id="+id;
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
if(rs.next()){
musicName = rs.getString(1);
}
sql = "delete from album where id=?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, id);
pstmt.executeUpdate();
sql = "delete from pic where picname=?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, picName);
pstmt.executeUpdate();
sql = "delete from music where musicname=?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, musicName);
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(pstmt!=null){
pstmt.close();
}
if(rs!=null){
rs.close();
}
if(stmt!=null){
stmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
|
cs |
3.7 FirstPanel
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 |
package Center;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
public class FirstPanel extends JPanel {
BufferedImage image;
public FirstPanel() {
try {
image = ImageIO.read(new File("C:\\Temp\\main.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void paint(Graphics g) {
g.drawImage(image, 0, 0, null);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(1900,750);
}
}
|
cs |
3.8 ShowPanel
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192 |
package Center;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import javax.imageio.ImageIO;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import DB.Album;
import DB.DBConnector;
public class ShowPanel extends JPanel{
//전역 변수 설정
private JPanel topPanel; // 카테고리 라벨들을 붙일 패널
private JLabel[] topLbl; // 카테고리 라벨들
private ArrayList<Album> data;
private DBConnector dbc;
private JPanel centerPanel; // rowPanel 들을 붙일 패널
private int chkCount = 0; // 체크박스를 선택한 개수를 담을 변수
private JCheckBox chk; // 체크박스
private int[] ids;
private static int chkID;
private static LinkedList<Integer> chkIDs = new LinkedList<>();
public ShowPanel() {
setLayout(null);
setVisible(true);
//topPanel 영역 ------------------------------------------
topPanel = new JPanel();
topPanel.setBounds(0, 0, 1900, 50);
topPanel.setLayout(null);
add(topPanel);
topLbl = new JLabel[7];
String[] topLblText = {"선택", "앨범사진", "제목", "가수명", "발매일",
"장르", "앨범명"};
Font font = new Font("D2Coding", Font.BOLD, 20);
for (int i = 0; i < topLbl.length; i++) {
topLbl[i] = new JLabel();
topLbl[i].setText(topLblText[i]);
topLbl[i].setHorizontalAlignment((int)CENTER_ALIGNMENT);
topLbl[i].setFont(font);
topLbl[i].setBounds(i*270, 0, 270, 50);
topPanel.add(topLbl[i]);
}
//centerPanel 영역 ---------------------------------------------
data = new ArrayList<>();
dbc = new DBConnector();
centerPanel = new JPanel();
centerPanel.setBounds(0, 50, 1900, 700);
//centerPanel.setLayout(new GridLayout(data.size(), 1, 0, 0));
centerPanel.setLayout(null);
add(centerPanel);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(1900, 750);
}
//이미지를 그리는 inner class
class DrawImgPanel extends JPanel{
BufferedImage is;
public DrawImgPanel(BufferedImage is) {
this.is = is;
}
@Override
public void paint(Graphics g) {
g.drawImage(is, 70, 0, 120, 100, null);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(270, 100);
}
}
//show method - db에서 음악 목록을 불러와서 뿌려준다.
public void showMethod(){
centerPanel.removeAll();
data.clear();
data = dbc.showDB();
JPanel[] rowPanel = new JPanel[data.size()];
chk = new JCheckBox();
ids = new int[data.size()];
for (int i = 0; i < data.size(); i++) {
rowPanel[i] = new JPanel();
rowPanel[i].setLayout(null);
Integer id = data.get(i).getId();
chk = new JCheckBox();
chk.setBounds(120, 25, 50, 50);
chk.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == e.SELECTED){
chkCount++;
chkIDs.add(id);
System.out.println(chkIDs);
}else if(e.getStateChange() == e.DESELECTED){
chkCount--;
chkIDs.remove(id);
System.out.println(chkIDs);
}
}
});
InputStream picture = data.get(i).getPicture();
DrawImgPanel imgPanel = null;
try {
imgPanel = new DrawImgPanel(ImageIO.read(picture));
imgPanel.setBounds(270, 0, 270, 100);
} catch (IOException e) {}
String name = data.get(i).getName();
String singer = data.get(i).getSinger();
String date = data.get(i).getDate();
String genre = data.get(i).getGenre();
String title = data.get(i).getTitle();
JLabel[] contentsLbl = new JLabel[5];
for (int j = 0; j < contentsLbl.length; j++) {
contentsLbl[j] = new JLabel();
}
contentsLbl[0].setText(name);
contentsLbl[0].setBounds(540, 0, 270, 100);
contentsLbl[0].setHorizontalAlignment((int)CENTER_ALIGNMENT);
contentsLbl[1].setText(singer);
contentsLbl[1].setBounds(810, 0, 270, 100);
contentsLbl[1].setHorizontalAlignment((int)CENTER_ALIGNMENT);
contentsLbl[2].setText(date);
contentsLbl[2].setBounds(1080, 0, 270, 100);
contentsLbl[2].setHorizontalAlignment((int)CENTER_ALIGNMENT);
contentsLbl[3].setText(genre);
contentsLbl[3].setBounds(1350, 0, 270, 100);
contentsLbl[3].setHorizontalAlignment((int)CENTER_ALIGNMENT);
contentsLbl[4].setText(title);
contentsLbl[4].setBounds(1620, 0, 270, 100);
contentsLbl[4].setHorizontalAlignment((int)CENTER_ALIGNMENT);
rowPanel[i].add(chk);
rowPanel[i].add(imgPanel);
rowPanel[i].add(contentsLbl[0]);
rowPanel[i].add(contentsLbl[1]);
rowPanel[i].add(contentsLbl[2]);
rowPanel[i].add(contentsLbl[3]);
rowPanel[i].add(contentsLbl[4]);
rowPanel[i].setBounds(0, i*110, 1900, 100);
centerPanel.add(rowPanel[i]);
}
}
public int getChk(){
return chkCount;
}
public int getChkID(){
if(chkIDs.size()==1){
chkID = chkIDs.get(0);
}
return chkID;
}
public LinkedList<Integer> getChkIDs(){
return chkIDs;
}
}
|
cs |
3.9 InsertPanel
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192 |
package Center;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import DB.DBConnector;
import Dialog.SuccessDialog;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JSeparator;
import java.awt.Color;
import java.awt.Dialog;
public class InsertPanel extends JPanel implements ActionListener{
private JTextField tf1, tf2, tf3, tf4, tf5;
private JLabel lb1, lb2, lb3, lb4, lb5, lb6, lb7, lb8, lb9;
private JButton btn1, btn2, btn3;
private JFrame jf;
private FileDialog fd1;
private InputStream fis, musicFis;
private String picName, musicName;
private int picLength, musicLength;
public InsertPanel() {
setLayout(null);
lb1 = new JLabel("곡명");
lb1.setBounds(34, 34, 62, 18);
add(lb1);
lb2 = new JLabel("발매일");
lb2.setBounds(34, 64, 62, 18);
add(lb2);
lb3 = new JLabel("가수");
lb3.setBounds(34, 94, 62, 18);
add(lb3);
lb4 = new JLabel("앨범명");
lb4.setBounds(34, 124, 62, 18);
add(lb4);
lb5 = new JLabel("장르");
lb5.setBounds(34, 154, 62, 18);
add(lb5);
tf1 = new JTextField();
tf1.setBounds(106, 31, 330, 24);
add(tf1);
tf1.setColumns(10);
tf2 = new JTextField();
tf2.setBounds(106, 61, 330, 24);
add(tf2);
tf2.setColumns(10);
tf3 = new JTextField();
tf3.setBounds(106, 91, 330, 24);
add(tf3);
tf3.setColumns(10);
tf4 = new JTextField();
tf4.setBounds(106, 121, 330, 24);
add(tf4);
tf4.setColumns(10);
tf5 = new JTextField();
tf5.setBounds(106, 151, 330, 24);
add(tf5);
tf5.setColumns(10);
lb6 = new JLabel("사진");
lb6.setBounds(34, 188, 62, 18);
add(lb6);
lb7 = new JLabel("");
lb7.setBounds(106, 188, 200, 24);
add(lb7);
lb8 = new JLabel("음악");
lb8.setBounds(34, 222, 62, 18);
add(lb8);
lb9 = new JLabel("");
lb9.setBounds(106, 222, 200, 24);
add(lb9);
btn1 = new JButton("사진넣기");
btn1.setBounds(93, 272, 105, 39);
btn1.addActionListener(this);
add(btn1);
btn2 = new JButton("저장");
btn2.setBounds(331, 272, 105, 39);
btn2.addActionListener(this);
add(btn2);
btn3 = new JButton("음악넣기");
btn3.setBounds(212, 272, 105, 39);
btn3.addActionListener(this);
add(btn3);
JSeparator separator = new JSeparator();
separator.setForeground(Color.BLACK);
separator.setBounds(34, 257, 400, 2);
add(separator);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(600, 500);
}
@Override
public void actionPerformed(ActionEvent e) {
//사진 넣기
if(e.getSource() == btn1){
try {
jf = new JFrame();
jf.setSize(300, 300);
jf.setDefaultCloseOperation(jf.DISPOSE_ON_CLOSE);
fd1 = new FileDialog(jf, "사진을 선택하시오.", FileDialog.LOAD);
fd1.setVisible(true);
String fileDir = fd1.getDirectory(); // 선택한 파일 경로가져옴
String fileName = fd1.getFile(); // 파일이름,확장자
File file = new File(fileDir + fileName);
fis = new FileInputStream(file);
picName = fileDir + fileName;
picLength = (int) file.length();
lb7.setText(fileDir + "\\" + fileName);
} catch (Exception ex) {
ex.printStackTrace();
}
}
//저장
if(e.getSource() == btn2){
String name = tf1.getText().toString();
String date = tf2.getText().toString();
String singer = tf3.getText().toString();
String title = tf4.getText().toString();
String genre = tf5.getText().toString();
DBConnector dbc = new DBConnector();
dbc.insertDB(name, date, singer, title, genre, fis, picName, picLength, musicFis, musicName, musicLength);
SuccessDialog sd = new SuccessDialog();
Dialog dl = new Dialog(sd);
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
lb7.setText("");
lb9.setText("");
}
//음악 넣기
if(e.getSource() == btn3){
try {
jf = new JFrame();
jf.setSize(300, 300);
jf.setDefaultCloseOperation(jf.DISPOSE_ON_CLOSE);
fd1 = new FileDialog(jf, "음악을 선택하시오.", FileDialog.LOAD);
fd1.setVisible(true);
String fileDir = fd1.getDirectory(); // 선택한 파일 경로가져옴
String fileName = fd1.getFile(); // 파일이름,확장자
File file = new File(fileDir + fileName);
musicFis = new FileInputStream(file);
musicName = fileDir + fileName;
musicLength = (int) file.length();
lb9.setText(fileDir + "\\" + fileName);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
|
cs |
3.10 UpdateFrame
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294 |
package Frame;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import Center.ShowPanel;
import DB.Album;
import DB.DBConnector;
import Dialog.SuccessDialog;
public class UpdateFrame extends JFrame {
private ShowPanel sp;
private int id;
private DBConnector dbc;
private Album ab;
public UpdateFrame() {
setBounds(700, 300, 500, 500);
setDefaultCloseOperation(UpdateFrame.DISPOSE_ON_CLOSE);
sp = new ShowPanel();
id = sp.getChkID();
dbc = new DBConnector();
ab = new Album();
ab = dbc.selectDB(id);
UpdatePanel up = new UpdatePanel();
add(up);
setVisible(true);
}
class UpdatePanel extends JPanel implements ActionListener {
private ImgPanel imgPanel;
private JTextField tf1, tf2, tf3, tf4, tf5;
private JLabel lb1, lb2, lb3, lb4, lb5, lb6, lb7;
private JButton btn1, btn2, btn3;
private String name ;
private String date ;
private String singer ;
private String title ;
private String genre ;
private String picName;
private InputStream picture = null;
private int picLength;
private InputStream fis = null;
private int length = 0;
private InputStream musicFis = null;
private String musicName;
private InputStream music = null;
private int musicLength = 0;
public UpdatePanel() {
setSize(500, 500);
setLayout(null);
name = ab.getName();
date = ab.getDate();
singer = ab.getSinger();
title = ab.getTitle();
genre = ab.getGenre();
picName = ab.getPicName();
picture = ab.getPicture();
picLength = ab.getPicLength();
musicName = ab.getMusicName();
music = ab.getMusic();
musicLength = ab.getMusicLength();
try {
imgPanel = new ImgPanel(ImageIO.read(picture));
} catch (IOException e) {
e.printStackTrace();
}
imgPanel.setBounds(10, 10, 300, 300);
add(imgPanel);
//곡명
lb1 = new JLabel("곡명");
lb1.setBounds(325, 10, 150, 25);
add(lb1);
tf1 = new JTextField();
tf1.setBounds(325, 35, 150, 25);
tf1.setText(name);
add(tf1);
//발매일
lb2 = new JLabel("발매일");
lb2.setBounds(325, 60, 150, 25);
add(lb2);
tf2 = new JTextField();
tf2.setBounds(325, 85, 150, 25);
tf2.setText(date);
add(tf2);
//가수
lb3 = new JLabel("가수");
lb3.setBounds(325, 110, 150, 25);
add(lb3);
tf3 = new JTextField();
tf3.setBounds(325, 135, 150, 25);
tf3.setText(singer);
add(tf3);
//앨범명
lb4 = new JLabel("앨범명");
lb4.setBounds(325, 160, 150, 25);
add(lb4);
tf4 = new JTextField();
tf4.setBounds(325, 185, 150, 25);
tf4.setText(title);
add(tf4);
//장르
lb5 = new JLabel("장르");
lb5.setBounds(325, 210, 150, 25);
add(lb5);
tf5 = new JTextField();
tf5.setBounds(325, 235, 150, 25);
tf5.setText(genre);
add(tf5);
//음악
lb6 = new JLabel("음악");
lb6.setBounds(325, 260, 150, 25);
add(lb6);
lb7 = new JLabel("");
lb7.setBounds(325, 285, 150, 25);
lb7.setText(musicName);
add(lb7);
//분리선
JSeparator separator = new JSeparator();
separator.setBounds(20, 325, 450, 5);
add(separator);
//저장 버튼
btn1 = new JButton("저장");
btn1.setBounds(320, 370, 120, 30);
btn1.addActionListener(this);
add(btn1);
//사진 넣기 버튼
btn2 = new JButton("사진넣기");
btn2.setBounds(60, 370, 120, 30);
btn2.addActionListener(this);
add(btn2);
//음악 넣기 버튼
btn3 = new JButton("음악넣기");
btn3.setBounds(190, 370, 120, 30);
btn3.addActionListener(this);
add(btn3);
}
class ImgPanel extends JPanel{
BufferedImage is;
public ImgPanel(BufferedImage is) {
this.is = is;
}
public void imgChange(BufferedImage cImg){
is = cImg;
}
@Override
public void paint(Graphics g) {
g.drawImage(is, 0, 0, 300, 300, null);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(120, 120);
}
}
//버튼 이벤트
@Override
public void actionPerformed(ActionEvent e) {
//저장
if(e.getSource() == btn1){
name = tf1.getText().toString();
date = tf2.getText().toString();
singer = tf3.getText().toString();
title = tf4.getText().toString();
genre = tf5.getText().toString();
if(fis != null){
picture = fis;
}else{
File file = new File(picName);
try {
picture = new FileInputStream(file);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
if(length == 0){
length = picLength;
}
dbc.updateDB(id, name, date, singer, title, genre, picName, picture, length, musicName, music, musicLength);
new Dialog(new SuccessDialog());
dispose();
}
//사진넣기
if(e.getSource() == btn2){
try {
JFrame jf = new JFrame();
jf.setSize(300, 300);
jf.setDefaultCloseOperation(jf.DISPOSE_ON_CLOSE);
FileDialog fd1 = new FileDialog(jf, "사진을 선택하시오.", FileDialog.LOAD);
fd1.setVisible(true);
String fileDir = fd1.getDirectory(); // 선택한 파일 경로가져옴
String fileName = fd1.getFile(); // 파일이름,확장자
File file = new File(fileDir + fileName);
fis = new FileInputStream(file);
picName = fileDir + fileName;
length = (int) file.length();
System.out.println(fileDir + fileName);
/*remove(imgPanel);
imgPanel = new ImgPanel(ImageIO.read(file));
imgPanel.setBounds(10, 10, 300, 300);
add(imgPanel);
repaint();*/
imgPanel.imgChange(ImageIO.read(file));
repaint();
} catch (Exception e2) {
e2.printStackTrace();
}
}
//음악 넣기
if(e.getSource() == btn3){
try {
JFrame jf = new JFrame();
jf.setSize(300, 300);
jf.setDefaultCloseOperation(jf.DISPOSE_ON_CLOSE);
FileDialog fd1 = new FileDialog(jf, "음악을 선택하시오.", FileDialog.LOAD);
fd1.setVisible(true);
String fileDir = fd1.getDirectory(); // 선택한 파일 경로가져옴
String fileName = fd1.getFile(); // 파일이름,확장자
File file = new File(fileDir + fileName);
musicFis = new FileInputStream(file);
musicName = fileDir + fileName;
musicLength = (int) file.length();
lb7.setText(musicName);
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
}
|
cs |
3.11 MusicFrame
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193 |
package Frame;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.filechooser.FileNameExtensionFilter;
import Center.ShowPanel;
import DB.Album;
import DB.DBConnector;
import Frame.UpdateFrame.UpdatePanel.ImgPanel;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
public class MusicFrame extends JFrame{
private ShowPanel sp;
private int id;
private DBConnector dbc;
private Album ab;
public MusicFrame() {
setTitle("뮤직 플레이어");
setSize(500, 500);
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
setLocation(screenSize.width /2 - 250 ,screenSize.height/2 - 150);
setDefaultCloseOperation(MusicFrame.DISPOSE_ON_CLOSE);
sp = new ShowPanel();
id = sp.getChkID();
dbc = new DBConnector();
ab = new Album();
ab = dbc.selectDB(id);
MusicPlayerPanel mpp = new MusicPlayerPanel();
add(mpp);
setVisible(true);
}
class MusicPlayerPanel extends JPanel implements ActionListener{
private File musicFile;
private InputStream isMusic;
private AudioStream asMusic;
private AudioPlayer apMusic;
private JButton btnStart, btnChange, btnStop;
private JLabel lblTitle, lblSinger;
private String name, singer;
private InputStream picture = null;
private InputStream music = null;
private ImgPanel2 imgPanel;
public MusicPlayerPanel() {
setSize(500,500);
getContentPane().setLayout(null);
name = ab.getName();
singer = ab.getSinger();
picture = ab.getPicture();
music = ab.getMusic();
btnStart = new JButton("음악시작");
btnStart.setBounds(10, 400, 150, 30);
btnStart.addActionListener(this);
getContentPane().add(btnStart);
btnChange = new JButton("음악변경");
btnChange.setBounds(168, 400, 150, 30);
btnChange.addActionListener(this);
getContentPane().add(btnChange);
btnStop = new JButton("음악정지");
btnStop.setBounds(325, 400, 150, 30);
btnStop.addActionListener(this);
getContentPane().add(btnStop);
try {
imgPanel = new ImgPanel2(ImageIO.read(picture));
} catch (Exception e) {
e.printStackTrace();
}
imgPanel.setBounds(85, 10, 300, 300);
getContentPane().add(imgPanel);
lblTitle = new JLabel("\uC81C\uBAA9");
lblTitle.setBounds(10, 320, 465, 25);
lblTitle.setText(name);
lblTitle.setHorizontalAlignment((int)CENTER_ALIGNMENT);
getContentPane().add(lblTitle);
lblSinger = new JLabel("\uAC00\uC218");
lblSinger.setBounds(10, 350, 465, 25);
lblSinger.setText(singer);
lblSinger.setHorizontalAlignment((int)CENTER_ALIGNMENT);
getContentPane().add(lblSinger);
apMusic = AudioPlayer.player;
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btnStart){
playMusic();
}else if(e.getSource()==btnChange){
changeMusic();
}else{
stopMusic();
}
}
//음악 실행
public void playMusic(){
try {
asMusic = new AudioStream(music);
apMusic.start(asMusic);
} catch (Exception e) {
e.printStackTrace();
}
}
//음악 변경
public void changeMusic(){
//파일 열기 다이얼로그
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Audio(wav,au,mid,rmf)", "wav","au","mid","rmf");
//만들어둔 JFileChooser에 파일 필터를 부착
chooser.setFileFilter(filter);
//파일 열기 다이얼로그 출력
int ret = chooser.showOpenDialog(null);
String filePath = chooser.getSelectedFile().getPath();
String fileName = chooser.getSelectedFile().getName();
//선택된 파일을 AudioStream 에 담기
musicFile = new File(filePath);
try {
isMusic = new FileInputStream(musicFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
//음악 정지
public void stopMusic(){
apMusic.stop(asMusic);
}
//앨범 이미지 패널
class ImgPanel2 extends JPanel{
BufferedImage is;
public ImgPanel2(BufferedImage is) {
this.is = is;
}
public void imgChange(BufferedImage cImg){
is = cImg;
}
@Override
public void paint(Graphics g) {
g.drawImage(is, 0, 0, 300, 300, null);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(120, 120);
}
}
}
}
|
cs |
3.12 DeleteConfirmDialog
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 |
package Dialog;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import Center.ShowPanel;
import DB.DBConnector;
public class DeleteConfirmDialog extends JFrame {
private ShowPanel sp;
private LinkedList<Integer> chkIDs;
private DBConnector dbc;
private JPanel btnPanel;
public DeleteConfirmDialog() {
setSize(500, 300);
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
setLocation(screenSize.width /2 - 250 ,screenSize.height/2 - 150);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
sp = new ShowPanel();
chkIDs = sp.getChkIDs();
dbc = new DBConnector();
JLabel lbl = new JLabel("선택한 음악을 삭제하시겠습니까?");
Font font = new Font("D2Coding", Font.BOLD, 20);
lbl.setHorizontalAlignment((int)CENTER_ALIGNMENT);
lbl.setFont(font);
getContentPane().add(lbl, BorderLayout.CENTER);
btnPanel = new JPanel();
JButton btnOK = new JButton("확인");
btnOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < chkIDs.size(); i++) {
dbc.deleteDB(chkIDs.get(i));
}
new SuccessDialog2();
dispose();
}
});
btnPanel.add(btnOK);
JButton btnNO = new JButton("취소");
btnNO.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
btnPanel.add(btnNO);
getContentPane().add(btnPanel, BorderLayout.SOUTH);
setVisible(true);
}
} |
cs |
3.13 ListPlzDialog
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 |
package Dialog;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ListPlzDialog extends JFrame implements ActionListener {
public ListPlzDialog() {
setSize(500, 300);
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
setLocation(screenSize.width /2 - 250 ,screenSize.height/2 - 150);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JLabel lbl = new JLabel("음악 목록 보기에서 수정할 음악을 선택해 주세요.");
Font font = new Font("D2Coding", Font.BOLD, 20);
lbl.setHorizontalAlignment((int)CENTER_ALIGNMENT);
lbl.setFont(font);
getContentPane().add(lbl, BorderLayout.CENTER);
JButton btn = new JButton("확인");
btn.addActionListener(this);
getContentPane().add(btn, BorderLayout.SOUTH);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
}
|
cs |
3.14 ListPlzDialog2
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 |
package Dialog;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ListPlzDialog2 extends JFrame implements ActionListener {
public ListPlzDialog2() {
setSize(500, 300);
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
setLocation(screenSize.width /2 - 250 ,screenSize.height/2 - 150);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JLabel lbl = new JLabel("음악 목록 보기에서 재생할 음악을 선택해 주세요.");
Font font = new Font("D2Coding", Font.BOLD, 20);
lbl.setHorizontalAlignment((int)CENTER_ALIGNMENT);
lbl.setFont(font);
getContentPane().add(lbl, BorderLayout.CENTER);
JButton btn = new JButton("확인");
btn.addActionListener(this);
getContentPane().add(btn, BorderLayout.SOUTH);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
}
|
cs |
3.15 OneChkPlzDialog
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 |
package Dialog;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class OneChkPlzDialog extends JFrame implements ActionListener {
public OneChkPlzDialog() {
setSize(500, 300);
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
setLocation(screenSize.width /2 - 250 ,screenSize.height/2 - 150);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JLabel lbl = new JLabel("수정할 음악을 하나만 선택해 주세요.");
Font font = new Font("D2Coding", Font.BOLD, 20);
lbl.setHorizontalAlignment((int)CENTER_ALIGNMENT);
lbl.setFont(font);
getContentPane().add(lbl, BorderLayout.CENTER);
JButton btn = new JButton("확인");
btn.addActionListener(this);
getContentPane().add(btn, BorderLayout.SOUTH);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
}
|
cs |
3.16 OneChkPlzDialog2
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 |
package Dialog;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class OneChkPlzDialog2 extends JFrame implements ActionListener {
public OneChkPlzDialog2() {
setSize(500, 300);
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
setLocation(screenSize.width /2 - 250 ,screenSize.height/2 - 150);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JLabel lbl = new JLabel("삭제할 음악을 선택해 주세요.");
Font font = new Font("D2Coding", Font.BOLD, 20);
lbl.setHorizontalAlignment((int)CENTER_ALIGNMENT);
lbl.setFont(font);
getContentPane().add(lbl, BorderLayout.CENTER);
JButton btn = new JButton("확인");
btn.addActionListener(this);
getContentPane().add(btn, BorderLayout.SOUTH);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
}
|
cs |
3.17 SuccessDialog
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 |
package Dialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class SuccessDialog extends JFrame implements ActionListener {
public SuccessDialog() {
setSize(500, 300);
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
setLocation(screenSize.width /2 - 250 ,screenSize.height/2 - 150);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JLabel lbl = new JLabel("데이터베이스에 저장되었습니다.");
lbl.setHorizontalAlignment((int)CENTER_ALIGNMENT);
getContentPane().add(lbl, BorderLayout.CENTER);
JButton btn = new JButton("확인");
btn.addActionListener(this);
getContentPane().add(btn, BorderLayout.SOUTH);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
}
|
cs |
3.18 SuccessDialog2
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 |
package Dialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class SuccessDialog2 extends JFrame implements ActionListener {
public SuccessDialog2() {
setSize(500, 300);
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
setLocation(screenSize.width /2 - 250 ,screenSize.height/2 - 150);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JLabel lbl = new JLabel("성공적으로 삭제되었습니다.");
lbl.setHorizontalAlignment((int)CENTER_ALIGNMENT);
getContentPane().add(lbl, BorderLayout.CENTER);
JButton btn = new JButton("확인");
btn.addActionListener(this);
getContentPane().add(btn, BorderLayout.SOUTH);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
}
|
cs |
'Java > Java 프로젝트' 카테고리의 다른 글
Server and PieChart (0) | 2016.08.25 |
---|---|
Java 임금 계산기 (0) | 2016.08.11 |