forked from isenmit/javalab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeFile.java
More file actions
121 lines (100 loc) · 3.27 KB
/
EmployeeFile.java
File metadata and controls
121 lines (100 loc) · 3.27 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
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.*;
public class EmployeeFile
{
private static Color black;
public static void main(String[] args)
{
JFrame frameobj = new JFrame(); //creating frame
frameobj.setSize(500, 500); //declaring frame size
GridLayout g1=new GridLayout(5,2); // layout of the frame
frameobj.setLayout(g1); //layout is set to the frame created
JPanel p1=new JPanel(); //creating panels
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
JPanel p5=new JPanel();
JPanel p6=new JPanel();
JPanel p7=new JPanel();
JPanel p8=new JPanel();
JPanel p9=new JPanel();
JPanel p10=new JPanel();
JLabel l1=new JLabel("NAME"); //creating labels
JLabel l2=new JLabel("ID");
JLabel l3=new JLabel("DOJ");
JLabel l4=new JLabel("DOB");
JTextField f1=new JTextField(); //create obj for txtfield
JTextField f2=new JTextField();
JTextField f3=new JTextField();
JTextField f4=new JTextField();
f1.setPreferredSize(new Dimension(200,30)); //size of txtfield
f2.setPreferredSize(new Dimension(200,30));
f3.setPreferredSize(new Dimension(200,30));
f4.setPreferredSize(new Dimension(200,30));
JButton b1=new JButton("SUBMIT");
JButton b2=new JButton("RESET");
b1.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
File fileobj=new File("/home/Admin/workspace/P10 - Employee File/File.txt");
try
{
FileWriter fw=new FileWriter(fileobj.getAbsoluteFile(),true);
System.out.println("\n NAME : " +f1.getText() +"\n" +"ID : " +f2.getText() +"\n" +"DOJ : " +f3.getText() +"\n" +"DOB : "+f4.getText() +"\n");
fw.write("\n NAME : " +f1.getText() +"\n" +"ID : " +f2.getText() +"\n" +"DOJ : " +f3.getText() +"\n" +"DOB : "+f4.getText() +"\n");
fw.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
});
b2.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
f1.setText(" ");
f2.setText(null);
f3.setText(null);
f4.setText(null);
}
});
p1.add(l1); //add labels to panels where labels=name,id,doj,dob
p3.add(l2);
p5.add(l3);
p7.add(l4);
p2.add(f1); //add textfield to panels where txtfield is user defined
p4.add(f2);
p6.add(f3);
p8.add(f4);
p9.add(b1); //add buttons to panel
p10.add(b2);
//l1.setBorder(BorderFactory.createLineBorder(Color.black));
l1.setBorder(BorderFactory.createLineBorder(black,10));
l2.setBorder(BorderFactory.createLineBorder(black,10));
l3.setBorder(BorderFactory.createLineBorder(black,10));
l4.setBorder(BorderFactory.createLineBorder(black,10));
frameobj.add(p1); //add panels to frames
frameobj.add(p2);
frameobj.add(p3);
frameobj.add(p4);
frameobj.add(p5);
frameobj.add(p6);
frameobj.add(p7);
frameobj.add(p8);
frameobj.add(p9);
frameobj.add(p10);
frameobj.setVisible(true);
}
}