Appendix
Appendix
Appendix
Easyapp.java that was used in my program was created by the IB, the class itself was taken
from the site http://ibcomp.fis.edu/Java/EasyApp.html .
Mulkey, D. (2006). EasyApp - Simplified AWT Controls. Germany.
My program code:
1 package ttft;
2
3 /**
4 * Time-Table for Teacher (TTFT)
5 * IDE - NetBeans 7.3.1
6 * @author
7 * date December 2013
8 */
9 import java.awt.*;
10 import java.io.RandomAccessFile;
11 import java.io.IOException;
12
13 public class TTFT extends EasyApp {
14
15 public static void main(String[] args) {
16 new TTFT();
17 }
18 Label Title = addLabel("Login Section", 50, 50, 400, 50, this);
19 Label Login_ = addLabel("Login", 50, 110, 60, 50, this);
74
75 void RegisterCheck() {
76 try {
77 RandomAccessFile main = new RandomAccessFile("main.txt", "rw");
78 if (main.length() == 0) {
79 new Register();
80 } else {
81 outputString("You are already registered!\n" + "Please, try to Login!");
82 }
83 } catch (IOException e) {
84 e.getMessage();
85 }
86 }
87 }
1 package ttft;
2 import java.awt.*;
3 import java.io.RandomAccessFile;
4 import java.io.IOException;
5
6 public class AddLesson extends EasyApp {
7
8 Label Title = addLabel("Add a Lesson Section", 40, 40, 400, 50, this);
9 Label TeacherL = addLabel("Teacher", 50, 100, 80, 30, this);
10 Label SubjectL = addLabel("Subject", 50, 140, 80, 30, this);
11 Label DayL = addLabel("Day", 50, 180, 80, 30, this);
12 Label PeriodL = addLabel("Period", 50, 220, 80, 30, this);
13 Label GradeL = addLabel("Grade", 50, 260, 80, 30, this);
14 TextField Teacher = addTextField("", 170, 100, 150, 30, this);
15 TextField Subject = addTextField("", 170, 140, 150, 30, this);
16 TextField Day = addTextField("", 170, 180, 150, 30, this);
17 TextField Period = addTextField("", 170, 220, 150, 30, this);
18 TextField Grade = addTextField("", 170, 260, 150, 30, this);
19 Button TimeTable = addButton("Time-Table", 40, 310, 100, 50, this);
20 Button Accept = addButton("Accept", 160, 310, 100, 50, this);
21 Button Exit = addButton("Exit", 280, 310, 100, 50, this);
22
23 public AddLesson() {
24 setTitle("CompLab Time-table");
25 setBounds(425, 78, 440, 390);
26 Title.setFont(new Font("Arial", 0, 20));
27 Title.setForeground(Color.blue);
28 }
29
30 public void actions(Object source, String command) {
31 if (source == TimeTable) {
32 new TimeTable();
33 }
34 if (source == Accept) {
35 Accept();
36 }
37 if (source == Exit) {
38 System.exit(0);
39 }
40 }
41 // methods description
42 void Accept() {
43 String teacher = Teacher.getText();
44 String subject = Subject.getText();
45 String day = Day.getText();
46 String period = Period.getText();
47 String grade = Grade.getText();
48 if (teacher.equals("") || subject.equals("") || day.equals("") || period.equals("") ||
grade.equals("")) {
49 outputString("Error!\n" + "fill in all fields!");
50
51 } else {
52 String record = teacher + "/" + subject + "/" + day + "/" + period + "/" + grade;
53 try {
1 package ttft;
2 import java.awt.*;
3 public class CompLabTT extends EasyApp {
4
5 Button TimeTable = addButton("Time-Table", 50, 50, 130, 50, this);
6 Button AddLesson = addButton("Add a Lesson", 200, 50, 130, 50, this);
7 Button Search = addButton("Search", 125, 115, 130, 50, this);
8 Button Exit = addButton("Exit", 240, 190, 100, 50, this);
9
10 public CompLabTT() {
11 setTitle("CompLab Time-table");
12 setBounds(400, 80, 380, 260);
13 }
14
15 public void actions(Object source, String command) {
16 if (source == TimeTable) {
17 new TimeTable();
18 }
19 if (source == AddLesson) {
20 new AddLesson();
21 }
22 if (source == Search) {
23 new Search();
24 }
25 if (source == Exit) {
26 System.exit(0);
27 }
28 }
29 }
1 package ttft;
2 import java.awt.*;
3 import java.io.RandomAccessFile;
4 import java.io.IOException;
5
6 public class EditTT extends EasyApp {
7
8 Label Title = addLabel("Time-Table Editor", 40, 40, 400, 50, this);
9 Label TeacherL = addLabel("Teacher", 50, 100, 80, 30, this);
10 Label SubjectL = addLabel("Subject", 50, 140, 80, 30, this);
11 Label DayL = addLabel("Day", 50, 180, 80, 30, this);
12 Label PeriodL = addLabel("Period", 50, 220, 80, 30, this);
13 Label GradeL = addLabel("Grade", 50, 260, 80, 30, this);
14 TextField Teacher = addTextField("", 170, 100, 150, 30, this);
15 TextField Subject = addTextField("", 170, 140, 150, 30, this);
16 TextField Day = addTextField("", 170, 180, 150, 30, this);
17 TextField Period = addTextField("", 170, 220, 150, 30, this);
18 TextField Grade = addTextField("", 170, 260, 150, 30, this);
19 Button Accept = addButton("Accept", 85, 310, 100, 50, this);
20 Button Exit = addButton("Exit", 220, 310, 100, 50, this);
21
22 public EditTT() {
23
24 setTitle("Edit Time-Table");
25 setBounds(425, 78, 350, 390);
26 Title.setFont(new Font("Arial", 0, 20));
27 Title.setForeground(Color.blue);
28 buttonInfo();
29 }
30
31 public void actions(Object source, String command) {
32
33 if (source == Accept) {
34 Accept();
35 }
36 if (source == Exit) {
37 System.exit(0);
38 }
39 }
40 String button = TimeTable.check[TimeTable.i][TimeTable.j];
41 int z;
42
43 void buttonInfo() {
44
45 z = 0;
46 String day;
47 if (TimeTable.j == 0) {
48 day = "Monday";
49 } else if (TimeTable.j == 1) {
50 day = "Tuesday";
51 } else if (TimeTable.j == 2) {
52 day = "Wednesday";
53 } else if (TimeTable.j == 3) {
54 day = "Thursday";
55 } else {
56 day = "Friday";
57 }
58
59 String period = "" + (TimeTable.i + 1);
60 if (button != null) {
61 // button is not empty
62 while (z < TimeTable.count) {
63 if (TimeTable.LessonInfo[z][2].equals(day) && TimeTable.LessonInfo[z][3].equals(period)) {
64 Teacher.setText(TimeTable.LessonInfo[z][0]);
65 Subject.setText(TimeTable.LessonInfo[z][1]);
66 Day.setText(TimeTable.LessonInfo[z][2]);
67 Period.setText(TimeTable.LessonInfo[z][3]);
68 Grade.setText(TimeTable.LessonInfo[z][4]);
69 HistoryOfActions();
70 Edit();
71 break;
72 }
73 z++;
74 }
75 } else {
76 Day.setText(day);
77 Period.setText(period);
78 }
79 }
80
81 void HistoryOfActions() {
82
83 try {
84 RandomAccessFile OldInfo = new RandomAccessFile("History.txt", "rw");
85 OldInfo.seek(OldInfo.length());
86 OldInfo.writeBytes(TimeTable.LessonInfo[z][0] + "/" + TimeTable.LessonInfo[z][1] + "/"
+ TimeTable.LessonInfo[z][2] + "/" + TimeTable.LessonInfo[z][3] + "/"
+TimeTable.LessonInfo[z][4] + "\n");
87
88 } catch (IOException e) {
89 e.getMessage();
90 }
91 }
92 //if Button is empty - Accept() method works as input new lesson
93 //if Button is already accepted - client should change information and then save
94 // thus, change = delete + accept
95 void Accept () {
96 String teacher = Teacher.getText();
97 String subject = Subject.getText();
98 String day = Day.getText();
99 String period = Period.getText();
100 String grade = Grade.getText();
101 if (teacher.equals("") || subject.equals("") || day.equals("") || period.equals("") ||
grade.equals("")) {
102 outputString("Error!\n" + "fill in all fields!");
103
104 } else {
105 String record = teacher + "/" + subject + "/" + day + "/" + period + "/" + grade;
106 try {
1 package ttft;
2 import java.awt.*;
3 import java.io.RandomAccessFile;
4 import java.io.IOException;
5
6 public class EditTTHistory extends EasyApp {
7 Label Title = addLabel("Time-Table Editor", 40, 40, 400, 50, this);
8 Label TeacherL = addLabel("Teacher", 50, 100, 80, 30, this);
9 Label SubjectL = addLabel("Subject", 50, 140, 80, 30, this);
10 Label DayL = addLabel("Day", 50, 180, 80, 30, this);
11 Label PeriodL = addLabel("Period", 50, 220, 80, 30, this);
12 Label GradeL = addLabel("Grade", 50, 260, 80, 30, this);
13 TextField Teacher = addTextField(History.name, 170, 100, 150, 30, this);
14 TextField Subject = addTextField(History.subject, 170, 140, 150, 30, this);
15 TextField Day = addTextField(History.day, 170, 180, 150, 30, this);
16 TextField Period = addTextField(History.lesson, 170, 220, 150, 30, this);
17 TextField Grade = addTextField(History.grade, 170, 260, 150, 30, this);
18 Button Accept = addButton("Accept", 85, 310, 100, 50, this);
19 Button Exit = addButton("Exit", 220, 310, 100, 50, this);
20
21 public EditTTHistory() {
22 setTitle("Edit Time-Table");
23 setBounds(425, 78, 350, 390);
24 Title.setFont(new Font("Arial", 0, 20));
25 Title.setForeground(Color.blue);
26 }
27
28 public void actions(Object source, String command) {
29
30 if (source == Accept) {
31 Accept();
32 }
33 if (source == Exit) {
34 System.exit(0);
35 }
36 }
37
38 void Accept () {
39 String teacher = Teacher.getText();
40 String subject = Subject.getText();
41 String day = Day.getText();
42 String period = Period.getText();
43 String grade = Grade.getText();
44 if (teacher.equals("") || subject.equals("") || day.equals("") || period.equals("") ||
grade.equals("")) {
45 outputString("Error!\n" + "fill in all fields!");
46
47 } else {
48 String record = teacher + "/" + subject + "/" + day + "/" + period + "/" + grade;
49 try {
50 RandomAccessFile timetable = new RandomAccessFile("timetable.txt", "rw"); //file
to save all information as an records
51 int length = (int) timetable.length();
52 if (length == 0) {
53 timetable.writeBytes(TTFT.name + "'s room TimeTable\n");
54 timetable.writeBytes("\n");
55 } else {
56 timetable.seek(length);
57 }
58 timetable.writeBytes(record + "\n");
59 } catch (IOException e) {
60 e.getMessage();
61 }
62 }
63 //clean all fileds after accepting all data
64 Teacher.setText("");
65 Subject.setText("");
66 Day.setText("");
67 Period.setText("");
68 Grade.setText("");
69 }
70 }
1 package ttft;
2 import java.awt.*;
3 import java.io.RandomAccessFile;
4 import java.io.IOException;
5
6 public class History extends EasyApp {
7
8 Label Title = addLabel("Changes made in the timetable", 50, 50, 400, 40, this);
9 Button Exit = addButton("Exit", 240, 270, 80, 40, this);
10 Button Edit = addButton("Edit", 100, 270, 110, 40, this);
11 List HistoryA = addList("", 50, 100, 290, 150, this);
12
13 public History() {
14 setTitle("History of Actions");
15 setBounds(400, 80, 390, 330);
16 Title.setFont(new Font("Arial", 0, 15));
17 Title.setForeground(Color.blue);
18 ShowHistory();
19 }
20
21 public void actions(Object source, String command) {
22 if (source == Exit) {
23 System.exit(0);
24 }
25 if (source == Edit) {
26 Edit();
27 }
28 }
29
30 void ShowHistory() {
31 String text; // to read records from History.txt file
32 HistoryA.removeAll();
33 try {
34 RandomAccessFile OldInfo = new RandomAccessFile("History.txt", "rw");
35 while (OldInfo.getFilePointer() != OldInfo.length()) {
36 text = OldInfo.readLine();
37 HistoryA.add(text + "\n");
38 }
39 } catch (IOException e) {
40 e.getMessage();
41 }
42 }
43 static String name;
44 static String subject;
45 static String day;
46 static String lesson;
47 static String grade;
48
49 void Edit() {
50 String text = HistoryA.getSelectedItem();
51 int index1 = text.indexOf("/");
52 int index2 = text.indexOf("/", index1 + 1);
53 int index3 = text.indexOf("/", index2 + 1);
54 int index4 = text.indexOf("/", index3 + 1);
55
1 package ttft;
2 import java.awt.*;
3 import java.io.RandomAccessFile;
4 import java.io.IOException;
5
6 public class Register extends EasyApp {
7
8 Label Title = addLabel("Register Section", 50, 50, 400, 50, this);
9 Label Login_ = addLabel("Login", 50, 110, 60, 50, this);
10 TextField T1 = addTextField("", 170, 120, 150, 30, this);
11 Label Password_ = addLabel("Password", 50, 160, 60, 50, this);
12 TextField T2 = addTextField("", 170, 170, 150, 30, this);
13 Button Create = addButton("Create", 50, 225, 130, 40, this);
14 Button Exit = addButton("Exit", 200, 225, 130, 40, this);
15
16 public Register() {
17
18 setTitle("Time-Table for Teachers");
19 setBounds(425, 78, 370, 320);
20 Title.setFont(new Font("Arial", 0, 20));
21 Title.setForeground(Color.blue);
22 }
23
24 public void actions(Object source, String command) {
25 if (source == Create) {
26 Create();
27 }
28 if (source == Exit) {
29 System.exit(0);
30 }
31 }
32
33 void Create() {
34 String login = T1.getText();
35 String password = T2.getText();
36 String passwordNew = "";
37 try {
38 RandomAccessFile main = new RandomAccessFile("main.txt", "rw");
39 for (int i = 0; i < password.length(); i++) {
40 int k = (int) password.charAt(i) + 1;
41 passwordNew = passwordNew + (char) k;
42 }
43 main.writeBytes(login + "|" + passwordNew + "\n");
44
45 } catch (IOException e) {
46 e.getMessage();
47 }
48 dispose();
49 }
50 }
1 package ttft;
2
3 import java.awt.*;
4
5 public class Search extends EasyApp {
6
7 Button ByDay = addButton("By Day", 150, 110, 90, 40, this);
8 Button ByClass = addButton("By Class", 50, 160, 90, 40, this);
9 Button ByTeacher = addButton("By Teacher", 50, 110, 90, 40, this);
10 Button BySubject = addButton("By Subject", 150, 160, 90, 40, this);
11 Button History = addButton("History of actions", 50, 220, 190, 40, this);
12 Button Exit = addButton("Exit", 280, 220, 70, 40, this);
13 TextField SearchText = addTextField("", 50, 60, 190, 30, this);
14
15 public Search() {
16 setTitle("Search");
17 setBounds(400, 80, 390, 280);
18 }
19 static String text;
20 static int index;
21 public void actions(Object source, String command) {
22
23 text = SearchText.getText();
24
25 if (source == ByDay) {
26 index = 2;
27 new findInfo();
28 }
29 if (source == ByClass) {
30 index = 4;
31 new findInfo();
32 }
33 if (source == ByTeacher) {
34 index = 0;
35 new findInfo();
36 }
37 if (source == BySubject) {
38 index = 1;
39 new findInfo();
40 }
41 if (source == History) {
42 new History();
43 }
44 if (source == Exit) {
45 System.exit(0);
46 }
47 }
48 }
1 package ttft;
2
3 import java.awt.*;
4 import java.io.RandomAccessFile;
5 import java.io.IOException;
6
7 public class TimeTable extends EasyApp {
8
9 Label Title = addLabel("Computer Lab Time-Table", 40, 40, 400, 50, this);
10 Button Exit = addButton("Exit", 660, 610, 100, 40, this);
11 Label Lesson = addLabel("Lesson | Time", 40, 100, 120, 40, this);
12 Label Lesson1 = addLabel(" 1 | 09:00-09:45", 40, 150, 120, 40, this);
13 Label Lesson2 = addLabel(" 2 | 09:50-10:35", 40, 200, 120, 40, this);
14 Label Lesson3 = addLabel(" 3 | 10:45-11:30", 40, 250, 120, 40, this);
15 Label Lesson4 = addLabel(" 4 | 11:35-12:20", 40, 300, 120, 40, this);
16 Label Lesson5 = addLabel(" 5 | 12:50-13:35", 40, 350, 120, 40, this);
17 Label Lesson6 = addLabel(" 6 | 13:40-14:25", 40, 400, 120, 40, this);
18 Label Lesson7 = addLabel(" 7 | 14:30-15:15", 40, 450, 120, 40, this);
19 Label Lesson8 = addLabel(" 8 | 15:20-16:05", 40, 500, 120, 40, this);
20 Label Lesson9 = addLabel(" 9 | 16:10-16:55", 40, 550, 120, 40, this);
21 Label Monday = addLabel("Monday", 185, 100, 120, 40, this);
22 Label Tuesday = addLabel("Tuesday", 305, 100, 110, 40, this);
23 Label Wednesday = addLabel("Wednesday", 420, 100, 120, 40, this);
24 Label Thursday = addLabel("Thursday", 545, 100, 120, 40, this);
25 Label Friday = addLabel("Friday", 665, 100, 120, 40, this);
26 static Button[][] Lessons = new Button[9][5];
27
28 public TimeTable() {
29
30 setTitle("CompLab Time-table");
31 setBounds(20, 20, 800, 670);
32 Title.setFont(new Font("Arial", 0, 20));
33 Title.setForeground(Color.blue);
34 Monday.setFont(new Font("Arial", 0, 15));
35 Monday.setForeground(Color.blue);
36 Tuesday.setFont(new Font("Arial", 0, 15));
37 Tuesday.setForeground(Color.blue);
38 Wednesday.setFont(new Font("Arial", 0, 15));
39 Wednesday.setForeground(Color.blue);
40 Thursday.setFont(new Font("Arial", 0, 15));
41 Thursday.setForeground(Color.blue);
42 Friday.setFont(new Font("Arial", 0, 15));
43 Friday.setForeground(Color.blue);
44 Lesson.setFont(new Font("Arial", 0, 15));
45 Lesson.setForeground(Color.blue);
46 createButtons();
47 }
48 static int i; //Horizontal coordinate
49 static int j; //Vertical coordinate
50 static String[][] LessonInfo = new String[45][5]; // lessons max number is 9 * 5 = 45
51 static String[][] check = new String[9][5];
52
53 public void actions(Object source, String command) {
54 if (source == Exit) {
55 System.exit(0);
56 }
57 for (i = 0; i < 9; i++) {
58 for (j = 0; j < 5; j++) {
59 if (source == Lessons[i][j]) {
60 new EditTT();
61 dispose();
62 }
63 }
64 }
65 }
66 String lessonName = ""; //what to write on the button
67 static int count; // how many registered lessons we have in the "timetable.txt" file
68
69 static void createArray() {
70 String line;
71 //read information from file:
72 //Teacher's name, subject, day, period, grade.
73 try {
74 count = 0;
75 int index1;
76 int index2;
77 RandomAccessFile timetable = new RandomAccessFile("timetable.txt", "rw");
78 timetable.readLine(); // List title
79 timetable.readLine(); //empty line
80 // read lines from file and puts in the 2D array
81 while (timetable.length() != timetable.getFilePointer()) {
82 index1 = 0;
83 line = timetable.readLine();
84 index2 = line.indexOf("/");
85 LessonInfo[count][0] = line.substring(index1, index2);
86 index1 = index2;
87 index2 = line.indexOf("/", index1 + 1);
88 LessonInfo[count][1] = line.substring(index1 + 1, index2);
89 index1 = index2;
90 index2 = line.indexOf("/", index1 + 1);
91 LessonInfo[count][2] = line.substring(index1 + 1, index2);
92 index1 = index2;
93 index2 = line.indexOf("/", index1 + 1);
94 LessonInfo[count][3] = line.substring(index1 + 1, index2);
95 index1 = index2;
96 LessonInfo[count][4] = line.substring(index1 + 1);
97 count++;
98 }
99 } catch (IOException e) {
100 e.getMessage();
101 }
102 }
103
104 void createButtons() {
105 createArray();
106 // draw taken/used buttons
107 String buttonTitle;
108 int day;
109 int a, b;
110 String subject;
1 package ttft;
2
3 import java.awt.*;
4 import java.io.RandomAccessFile;
5 import java.io.IOException;
6
7 public class findInfo extends EasyApp {
8
9 Label Title = addLabel("", 50, 50, 290, 40, this);
10 List info = addList("", 50, 100, 290, 200, this);
11 Button Exit = addButton("Exit", 240, 310, 100, 50, this);
12
13 public findInfo() {
14 setTitle("Find information");
15 setBounds(400, 80, 380, 380);
16 Title.setFont(new Font("Arial", 0, 15));
17 Title.setForeground(Color.blue);
18
19 if (Search.index == 0) {
20 Title.setText("Teacher - " + Search.text);
21 } else if (Search.index == 1) {
22 Title.setText("Subject - " + Search.text);
23 } else if (Search.index == 2) {
24 Title.setText("Day - " + Search.text);
25 } else {
26 Title.setText("Grade - " + Search.text);
27 }
28
29 information();
30 }
31
32 public void actions(Object source, String command) {
33 if (source == Exit) {
34 System.exit(0);
35 }
36 }
37
38 void information() {
39 TimeTable.createArray();
40 info.removeAll();
41 int i = 0;
42 int index = Search.index;
43 String line;
44 while (TimeTable.LessonInfo[i][0] != null) {
45 if (TimeTable.LessonInfo[i][index].equals(Search.text)) {
46 line = TimeTable.LessonInfo[i][0] + "/" + TimeTable.LessonInfo[i][1] + "/" +
TimeTable.LessonInfo[i][2] + "/" + TimeTable.LessonInfo[i][3] + "/" + TimeTable.LessonInfo[i][4];
47 info.add(line + "\n");
48 }
49 i++;
50 }
51 }
52 }