-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.java
More file actions
137 lines (107 loc) · 4.04 KB
/
Console.java
File metadata and controls
137 lines (107 loc) · 4.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
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
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.*;
import javax.swing.*;
public class Console extends KeyAdapter implements ActionListener, KeyListener {
// Default Font Size for text
int fsize = 15;
// Adding Textarea.
private JTextArea area;
private JScrollPane scpane;
String text = "";
int cl;
int linecount;
// Creating Frame.
JFrame f = new JFrame("Aryan's Console");
JTextField title;
JPanel bottomPanel;
JLabel detailsOfFile;
JScrollPane sb;
JMenuItem exit, copy, paste, cut;
public Console() {
// Calling initUI() method
initUI();
// Calling addActionEvents() method to add events
addActionEvents();
}
public void actionPerformed(ActionEvent ae) {
// if exit option is choosen
if (ae.getActionCommand().equals("Exit")) {
// Destroying/Closing the frame/window
f.dispose();
}
// if copy option is choosen
else if (ae.getActionCommand().equals("Copy")) {
// Getting Selected Selected Text
text = area.getSelectedText();
} // if paste option is choosen
else if (ae.getActionCommand().equals("Paste")) {
area.insert(text, area.getCaretPosition());
} // if cut option is choosen
else if (ae.getActionCommand().equals("Cut")) {
text = area.getSelectedText();
area.replaceRange("", area.getSelectionStart(), area.getSelectionEnd());
}
}
@Override
public void keyTyped(KeyEvent ke) {
// Calculating length and count of words
cl = area.getText().length();
linecount = area.getLineCount();
detailsOfFile.setText("Length: " + cl + " Line: " + linecount);
}
private void initUI() {
detailsOfFile = new JLabel();
bottomPanel = new JPanel();
// TextArea
area = new JTextArea("");
area.append("C-OS [Version 10.0.22000.678]\n"
+ "(c) Alpha Corporation. All rights reserved.\n"
+ "\n"
+ "C:\\Users\\aryan>");
area.setSelectionStart(area.getText().length());
// Default font will be sam_serif and default font style will be plain and
// default style will be 20.
area.setFont(new Font("Serif", Font.PLAIN, 24));
// Sets the line-wrapping policy of the text area
area.setLineWrap(true);
// Sets the word-wrapping policy of the text area
area.setWrapStyleWord(true);
// Sets Background color
area.setBackground(Color.black);
area.setForeground(Color.white);
// Creating Scrollables around textarea
scpane = new JScrollPane(area);
// Creating border for scrollpane
scpane.setBorder(BorderFactory.createEmptyBorder());
bottomPanel.add(detailsOfFile);
// Set Size
f.setSize(1000, 700);
// Set layout
f.setLayout(new BorderLayout());
// Add frame
f.add(scpane, BorderLayout.CENTER);
f.add(bottomPanel, BorderLayout.SOUTH);
// f.getCursor();
// Frame visible to aryan :|
f.setVisible(true);
exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
// Assigning shortcut "Cntrl + C" for "Copy" Menu Item
copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
// Assigning shortcut "Cntrl + V" for "Paste" Menu Item
paste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
// Assigning shortcut "Cntrl + X" for "Cut" Menu Item
cut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
}
private void addActionEvents() {
exit.addActionListener(this);
copy.addActionListener(this);
paste.addActionListener(this);
cut.addActionListener(this);
}
public static void main(String ar[]) {
// TODO code application logic here
Console jai = new Console();
}
}