-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFollowing.java
More file actions
127 lines (101 loc) · 3.41 KB
/
Following.java
File metadata and controls
127 lines (101 loc) · 3.41 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
package workshop;
import java.awt.EventQueue;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JTextPane;
import java.awt.BorderLayout;
import javax.swing.JTable;
import java.awt.Color;
import java.awt.Scrollbar;
import java.awt.List;
import java.awt.event.*;
import java.sql.*;
import java.io.*;
public class Following {
private JFrame frm;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Following window = new Following();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Following() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frm = new JFrame("팔로잉");
frm.setSize(250, 500);
//TODO 부모 프레임을 화면 가운데에 배치
frm.setLocationRelativeTo(null);
//TODO 부모 프레임을 닫았을 때 메모리에서 제거되도록 설정
frm.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
//TODO 부모 프레임 창 크기 고정 실시
frm.setResizable(false);
//TODO 부모 레이아웃 설정
frm.getContentPane().setLayout(null);
//TODO 부모 프레임이 보이도록 설정
frm.setVisible(true);
JLabel jl = new JLabel("following");
jl.setHorizontalAlignment(jl.CENTER);
jl.setSize(250,30);
frm.getContentPane().add(jl, BorderLayout.NORTH);
Scrollbar scrollbar = new Scrollbar();
frm.getContentPane().add(scrollbar, BorderLayout.EAST);
Connection con = null;
Statement stmt = null;
PreparedStatement pstmt;
ResultSet rs = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver"); // jdbc driver load
String url = "jdbc:mysql://localhost/workshop";
String user = "root";
String passwd = "Spring030!"; // root 계정 비밀번호
con = DriverManager.getConnection(url, user, passwd);
System.out.println(con);
System.out.println("MySQL Server Link Successful");
} catch (Exception e) {
e.getMessage();
}
PreparedStatement ps = null;
final DefaultListModel<String> lm = new DefaultListModel<>();
String following = "";
try{
Class.forName("com.mysql.cj.jdbc.Driver");
stmt = con.createStatement();
String qu = "select * from follow";
rs = stmt.executeQuery(qu);
int i = 1;
while(rs.next()) {
following = rs.getString(1);
lm.addElement(i +". following: "+following);
i++;
}
if( rs != null ) rs.close();
if( stmt != null ) stmt.close();
if( con != null ) con.close();
}
catch (Exception e){
System.out.println(e);
}
final JList<String> ls = new JList<>(lm);
ls.setBounds(0,30,250,500);
frm.add(ls);
frm.setLayout(null);
frm.setVisible(true);
frm.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
}