-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreateAuthors.java
More file actions
86 lines (62 loc) · 2.44 KB
/
CreateAuthors.java
File metadata and controls
86 lines (62 loc) · 2.44 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
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JDialog;
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
public class CreateAuthors extends JFrame {
public CreateAuthors() {
super("Select a genre");
Font font = new Font("Verdana", Font.PLAIN, 18);
String dirname = "Genres/";
String dirName = JOptionPane.showInputDialog("Enter the name of the author");
File f1 = new File(dirname);
String genresStrings[] = f1.list();
for(int i = 0; i < genresStrings.length; i++){
File dir = new File(dirname + "/" + genresStrings[i], dirName);
dir.mkdir();
dir.mkdirs();
Container content = getContentPane();
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
final JLabel label = new JLabel(" ");
label.setAlignmentX(LEFT_ALIGNMENT);
label.setFont(font);
content.add(label);
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox box = (JComboBox)e.getSource();
String item = (String)box.getSelectedItem();
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame();
if(dir.exists()){
JOptionPane.showMessageDialog(frame, "Directory for the books of the author has been successfully created!", "That's right !", JOptionPane.PLAIN_MESSAGE);
}else{
JOptionPane.showMessageDialog(frame, "An attempt to create a directory for the books of the author had failed!", "Something wrong!", JOptionPane.ERROR_MESSAGE);
}
}
});
}
};
JComboBox comboBox = new JComboBox(genresStrings);
comboBox.setFont(font);
comboBox.setAlignmentX(LEFT_ALIGNMENT);
comboBox.addActionListener(actionListener);
content.add(comboBox);
setPreferredSize(new Dimension(250, 100));
pack();
setLocationRelativeTo(null);
setVisible(true);
}
}
}