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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
*
* NewJFrame.java
*
* Created on 27. November 2007, 10:30
*/
package javaapplication2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.Image*;
/**
*
* @author schueler
*/
public class NewJFrame extends javax.swing.JFrame {
FileDialog fd = new FileDialog(this, "Datei öffnen", FileDialog.LOAD);
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] font = ge.getAvailableFontFamilyNames();
for (int i=0; i<font.length; i++) {
jComboBox1.addItem(font[i]);
}
jMenuItem1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
if (ae.getActionCommand().equals("Speichern"))
{
//fd.show();
fd.setVisible(true);
try
{
String dat = fd.getFile();
String pfad = fd.getDirectory();
String dateiname = pfad + "\\" + dat + ".txt";
FileOutputStream out = new FileOutputStream(dateiname);
byte[] bytes;
String z = jTextPane1.getText();
bytes = z.getBytes();
for(int i=0; i<z.length();i++)
{
out.write(bytes[i]);
}
out.close();
}
catch (Exception e) { jTextPane1.setText("Bug T_T"); }
}
}
}
);
jMenuItem2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
if (ae.getActionCommand().equals("Laden"))
{
//fd.show();
fd.setVisible(true);
try
{
String dat = fd.getFile();
String pfad = fd.getDirectory();
String dateiname = pfad + "\\" + dat;
if (dateiname.toLowerCase().endsWith(".txt"))
{
FileReader fr = new FileReader(dateiname);
BufferedReader br = new BufferedReader(fr);
String z = br.readLine();
while (z != null)
{
//jTextPane1.append(z + "\n");
jTextPane1.setText(jTextPane1.getText()+z);
z = br.readLine();
}
}
}
catch (Exception e) { jTextPane1.setText("Bug T_T"); }
}
}
}
);
jMenuItem3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
}
);
jMenuItem4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
jTextPane1.copy();
}
}
);
jMenuItem5.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
jTextPane1.paste();
}
}
);
jMenuItem6.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
jTextPane1.cut();
}
}
);
jComboBox1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
jTextPane1.setFont(new Font(String.valueOf(jComboBox1.getSelectedItem()), jTextPane1.getFont().getStyle(), jTextPane1.getFont().getSize()));
}
}
);
jComboBox2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
jTextPane1.setFont(new Font(jTextPane1.getFont().getFamily(), jComboBox2.getSelectedIndex(), jTextPane1.getFont().getSize()));
}
}
);
jTextField1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
jTextPane1.setFont(new Font(jTextPane1.getFont().getFamily(), jTextPane1.getFont().getStyle(), Integer.valueOf(jTextField1.getText())));
jSlider1.setValue(Integer.valueOf(jTextField1.getText()));
}
}
);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox();
jComboBox2 = new javax.swing.JComboBox();
jTextField1 = new javax.swing.JTextField();
jSlider1 = new javax.swing.JSlider();
jScrollPane2 = new javax.swing.JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem4 = new javax.swing.JMenuItem();
jMenuItem5 = new javax.swing.JMenuItem();
jMenuItem6 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Normal", "Fett", "Kursiv", "Fett+Kursiv" }));
jTextField1.setText("12");
jSlider1.setMinimum(2);
jSlider1.setOrientation(javax.swing.JSlider.VERTICAL);
jSlider1.setValue(12);
jSlider1.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
jSlider1StateChanged(evt);
}
});
jSlider1.addHierarchyListener(new java.awt.event.HierarchyListener() {
public void hierarchyChanged(java.awt.event.HierarchyEvent evt) {
jSlider1HierarchyChanged(evt);
}
});
jScrollPane2.setViewportView(jTextPane1);
jMenu1.setText("Datei");
jMenuItem1.setText("Speichern");
jMenu1.add(jMenuItem1);
jMenuItem2.setText("Laden");
jMenu1.add(jMenuItem2);
jMenuItem3.setText("Beenden");
jMenu1.add(jMenuItem3);
jMenuBar1.add(jMenu1);
jMenu2.setText("Bearbeiten");
jMenuItem4.setText("Kopieren");
jMenu2.add(jMenuItem4);
jMenuItem5.setLabel("Einf\u00fcgen");
jMenu2.add(jMenuItem5);
jMenuItem6.setLabel("Ausschneiden");
jMenu2.add(jMenuItem6);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(24, 24, 24)
.add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 146, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 97, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 51, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jSlider1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(4, 4, 4)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, jSlider1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE))
.addContainerGap())
);
pack();
}// </editor-fold>
private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {
jTextField1.setText(String.valueOf(jSlider1.getValue()));
jTextPane1.setFont(new Font(jTextPane1.getFont().getFamily(), jTextPane1.getFont().getStyle(), Integer.valueOf(jTextField1.getText())));
}
private void jSlider1HierarchyChanged(java.awt.event.HierarchyEvent evt) {
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JComboBox jComboBox1;
private javax.swing.JComboBox jComboBox2;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JMenuItem jMenuItem5;
private javax.swing.JMenuItem jMenuItem6;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JSlider jSlider1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextPane jTextPane1;
// End of variables declaration
}
|