Repository navigation
Expand file tree
/
Copy pathFileCreator.java
More file actions
63 lines (52 loc) · 1.73 KB
/
Copy pathFileCreator.java
File metadata and controls
63 lines (52 loc) · 1.73 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
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class FileCreator extends Frame implements ActionListener {
TextField rollField, nameField, marksField;
Button enterButton, doneButton;
FileWriter fw;
FileCreator() {
setLayout(new FlowLayout());
add(new Label("Roll Number:"));
rollField = new TextField(20);
add(rollField);
add(new Label("Student Name:"));
nameField = new TextField(20);
add(nameField);
add(new Label("Marks:"));
marksField = new TextField(20);
add(marksField);
enterButton = new Button("Enter");
doneButton = new Button("Done");
add(enterButton);
add(doneButton);
enterButton.addActionListener(this);
doneButton.addActionListener(this);
try {
fw = new FileWriter("student.txt", true);
} catch (IOException e) {
System.out.println(e);
}
setSize(300, 300);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
try {
if (e.getSource() == enterButton) {
String data = rollField.getText() + " " + nameField.getText() + " " + marksField.getText() + "\n";
fw.write(data);
rollField.setText("");
nameField.setText("");
marksField.setText("");
} else if (e.getSource() == doneButton) {
fw.close();
System.exit(0);
}
} catch (IOException ex) {
System.out.println(ex);
}
}
public static void main(String[] args) {
new FileCreator();
}
}