-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualInterface.java
More file actions
86 lines (69 loc) · 2.28 KB
/
VisualInterface.java
File metadata and controls
86 lines (69 loc) · 2.28 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
package homework7.notepad;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* Created by Razer on 31.07.15.
*/
public class VisualInterface extends JFrame {
private static final String TITLE = "Notepad";
JTextArea textArea = new JTextArea();
private JFrame jFrame;
private Notepad notepad;
private JMenuItem openButton;
private JMenuItem saveButton;
public VisualInterface() {
super(TITLE);
init();
}
private void init() {
setSize(600, 400);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
setResizable(true);
setupMenu();
setupTextArea();
}
private void setupTextArea() {
JScrollPane jScrollBar = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
textArea.setLineWrap(true);
textArea.setEditable(true);
textArea.setBackground(Color.gray);
getContentPane().add(jScrollBar);
}
private void setupMenu() {
jFrame = new JFrame();
notepad = new Notepad(jFrame);
JMenuBar bar = new JMenuBar();
JMenu menu = new JMenu("File");
openButton = new JMenuItem("Open");
openButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
textArea.setText(notepad.openButton());
} catch (FileNotFoundException e1) {
JOptionPane.showMessageDialog(jFrame, "Error,file not found!", " ", JOptionPane.ERROR_MESSAGE);
}
}
});
saveButton = new JMenuItem("Save");
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
notepad.saveButton(textArea.getText());
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
bar.add(menu);
menu.add(openButton);
menu.add(saveButton);
setJMenuBar(bar);
}
}