-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.java
More file actions
71 lines (64 loc) · 2 KB
/
background.java
File metadata and controls
71 lines (64 loc) · 2 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.ArrayList;
public class background extends JFrame{
public static final int serialVersionUID=1;
public static void main(String[] args) {
background bkg = new background();
}
public background() {
JButton btn;
String file = System.getProperty("user.home") + "/.lockbackground";
String config = System.getProperty("user.home")+"/.lockconf";
File g = new File(file);
if(g.exists()) {} else {g.mkdir();}
File[] f = g.listFiles();
File conf = new File(config);
if(conf.exists()) {} else {
try {
conf.createNewFile();
}catch (IOException eb) {
JOptionPane.showMessageDialog(null, eb.toString());
}};
JFrame bkgfr = new JFrame();
JPanel bkgpa = new JPanel(new BorderLayout());
JPanel bkgls = new JPanel();
BoxLayout lay = new BoxLayout(bkgls, BoxLayout.PAGE_AXIS);
bkgls.setLayout(lay);
for (File f1 : f) {
btn = new JButton(f1.getName());
btn.setBackground(Color.WHITE);
btn.setFocusable(false);
btn.setBorder(null);
btn.setBorder(BorderFactory.createEmptyBorder(3, 3, 10, 10));
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String f2 = f1.getAbsolutePath();
conf.delete();
try {
FileWriter fw = new FileWriter(conf);
fw.write(f2);
fw.close();
} catch (IOException e1) {
JOptionPane.showMessageDialog(null, e.toString());
}
}
});
bkgls.add(btn);
}
bkgls.setBackground(Color.white);
bkgpa.add(bkgls);
bkgpa.add(new JLabel("Chọn hình nền"), BorderLayout.NORTH);
bkgpa.setBackground(Color.white);
bkgfr.setTitle("Đổi hình nền");
bkgfr.setContentPane(bkgpa);
bkgfr.setDefaultCloseOperation(EXIT_ON_CLOSE);
bkgfr.setSize(800,600);
bkgfr.setVisible(true);
}
}