-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreateJFrame.java
More file actions
230 lines (190 loc) · 5.43 KB
/
CreateJFrame.java
File metadata and controls
230 lines (190 loc) · 5.43 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
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
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.JPanel;
import javax.swing.LookAndFeel;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
public class CreateJFrame
{
public static void createGUI()
{
try {
UIManager.setLookAndFeel((LookAndFeel) Class.forName(UIManager.getCrossPlatformLookAndFeelClassName()).newInstance());
} catch (InstantiationException | IllegalAccessException| ClassNotFoundException | UnsupportedLookAndFeelException e) {
}
JPanel content = new JPanel(new FlowLayout());
//Create JFrame
JFrame frame = new JFrame("LIBRARY");
frame.setContentPane(content);
frame.pack();
// Center the on the screen
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
JTextArea textArea = new JTextArea(50,50);
content.add(textArea);
textArea.setLineWrap(true);
/*
//Create JScrollPane
JScrollPane sbrText = new JScrollPane(textArea);
sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
*/
//Create JFrame ActionListener
frame.addWindowListener(new WindowListener()
{
public void windowActivated(WindowEvent event)
{
}
public void windowClosed(WindowEvent event)
{
}
public void windowClosing(WindowEvent event)
{
Object[] options = {"Yes", "No"};
int n = JOptionPane.showOptionDialog(event.getWindow(), "Close the window?",
"Confirmation", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if (n == 0){
event.getWindow().setVisible(false);
System.exit(0);
}
}
public void windowDeactivated(WindowEvent event)
{
}
public void windowDeiconified(WindowEvent event)
{
}
public void windowIconified(WindowEvent event)
{
}
public void windowOpened(WindowEvent event)
{
}
});
//Create Font
Font font = new Font("Verdana", Font.PLAIN, 11);
JMenuBar menuBar = new JMenuBar();
//Create File Menu
JMenu fileMenu = new JMenu("File");
fileMenu.setFont(font);
//Create Add Menu
JMenu addMenu = new JMenu("Add");
addMenu.setFont(font);
fileMenu.add(addMenu);
//Create ReadMenuItem
JMenuItem readMenuItem = new JMenuItem("Read");
readMenuItem.setFont(font);
fileMenu.add(readMenuItem);
//Create Add genres menuItem
JMenuItem addgMenuItem = new JMenuItem("Add genres");
addgMenuItem.setFont(font);
addMenu.add(addgMenuItem);
//Create Add author MenuItem
JMenuItem addaMenuItem = new JMenuItem("Add author");
addaMenuItem.setFont(font);
addMenu.add(addaMenuItem);
//Create Add series menuItem
JMenuItem addsMenuItem = new JMenuItem("Add series");
addsMenuItem.setFont(font);
addMenu.add(addsMenuItem);
//Create Separator
addMenu.addSeparator();
//Create Add book MenuItem
JMenuItem addbMenuItem = new JMenuItem("Add book");
addbMenuItem.setFont(font);
addMenu.add(addbMenuItem);
//Create Exit Menu
JMenu exitMenu = new JMenu("Exit");
exitMenu.setFont(font);
//Create Exit MenuItem
JMenuItem exitMenuItem = new JMenuItem("Exit");
exitMenuItem.setFont(font);
exitMenu.add(exitMenuItem);
//exitMenuItem ActionListener
exitMenuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
//addbMenuItem ActionListener
addbMenuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
FileChooser fileChooser = new FileChooser();
fileChooser.fileCh();
}
});
//addgMenuItem ActionListener
addgMenuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
CreateGenres createGenres = new CreateGenres();
createGenres.createGenres();
}
});
//addaMenuItem ActionListener
addaMenuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
new CreateAuthors();
}
});
//addsMenuItem ActionListener
addsMenuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
DirectoryChooserS directoryChooserS = new DirectoryChooserS();
directoryChooserS.directoryChS();
}
});
//readMenuItem ActionListener
readMenuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
// Create object BookReader
BookReader bookReader = new BookReader(frame);
// Method will be called from the class BookReader once a file is read
bookReader.setCallback(new BookReader.BookReaderCallback() {
// Method will be called from the class BookReader once a file is read
public void onReadComplete(String text) {
// Replace the text in the Label
textArea.setText(text);
}
});
// Start "reading room " :)
bookReader.readBook();
}
});
//Create refrenceMenu
JMenu referenceMenu = new JMenu("Reference");
referenceMenu.setFont(font);
//Create aboutMenuItem
JMenuItem aboutMenuItem = new JMenuItem("About");
aboutMenuItem.setFont(font);
referenceMenu.add(aboutMenuItem);
menuBar.add(fileMenu);
menuBar.add(referenceMenu);
menuBar.add(exitMenu);
frame.setJMenuBar(menuBar);
frame.setPreferredSize(new Dimension(800, 600));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
JFrame.setDefaultLookAndFeelDecorated(true);
}
}