-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelect_image.java
More file actions
94 lines (72 loc) · 3.04 KB
/
Copy pathSelect_image.java
File metadata and controls
94 lines (72 loc) · 3.04 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
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
public class Select_image extends JFrame {
JFrame frm = new JFrame("Select File");
String filePath; // ���� ���
String fileName; // ���� �̸�
Toolkit toolkit = getToolkit(); // �̹����� �������� ���ؼ�
String id;
Select_image(String userid){
id = userid;
// ��ü ������
frm.setSize(500,700);
frm.setLocationRelativeTo(null);
frm.setResizable(false);
Container contentPane = getContentPane();
contentPane.setBackground(Color.WHITE);
// ��� ------------------------------------------------------------------
JPanel upper = new JPanel();
upper.setPreferredSize(new Dimension(500,100));
// �߾� ------------------------------------------------------------------
JPanel center = new JPanel();
center.setPreferredSize(new Dimension(500,500));
JButton selectButton = new JButton("Select File"); // ���� ���� ��ư
selectButton.setPreferredSize(new Dimension(200, 100));
selectButton.setBackground(Color.WHITE);
selectButton.addActionListener(new OpenActionListener());
center.add(selectButton);
// �ϴ� ------------------------------------------------------------------
JPanel bottom = new JPanel();
bottom.setPreferredSize(new Dimension(500,100));
// ��ü �����ӿ� �߰�
contentPane.add(upper, BorderLayout.NORTH);
contentPane.add(center, BorderLayout.CENTER);
contentPane.add(bottom, BorderLayout.SOUTH);
frm.add(contentPane);
frm.setVisible(true);
}
class OpenActionListener implements ActionListener {
JFileChooser chooser;
OpenActionListener(){
chooser = new JFileChooser();
}
public void actionPerformed(ActionEvent e){
FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & PNG Images", "jpg", "png");
chooser.setFileFilter(filter);
int ret = chooser.showOpenDialog(null);
if(ret != JFileChooser.APPROVE_OPTION){
JOptionPane.showMessageDialog(null, "No file selected", "Warning", JOptionPane.WARNING_MESSAGE);
return;
}
filePath = chooser.getSelectedFile().getPath(); // ������ ���� ���
fileName = chooser.getSelectedFile().getName();
System.out.println(fileName);
new Profile_edit(id);
frm.setVisible(false);
}
}
public String getFilePath(){
return filePath;
}
public String getFileName(){
return fileName;
}
public static void main(String[] args) {
new Select_image("network4");
}
}