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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;


public class menu extends account {
	
	// Alle nødvendige variabler erklæres her, såvel textfields som strings til at modtage textfield information.
	double actualRate = super.interestRate;
	
	private TextField fNameF;
	private TextField lNameF;
	private TextField cprNumF;
	private TextField streetF;
	private TextField cityF;
	private TextField phoneNumF;
	
	private TextField savAccNumF;
	private TextField curAccNumF;
	private TextField amountF;
	private TextField destAccNumF;
	private TextField rateF;
	
	private String fName;
	private String lName;
	private String cprNum;
	private String street;
	private String city;
	private String phoneNum;
	private String newRate;
	
	private String savAccNum;
	private String curAccNum;
	private String amount;
	private String destAccNum;

	private Dimension buttSize = new Dimension(300, 20);
	private Dimension space    = new Dimension(0, 10);
	private int returnNum;
	
	// message benyttes i tilfælde af FileNotFoundExceptions
	String message = "Fejl i processen";
	
	// Frames initialiseres uden for classes og constructorer, så de er tilgængelige i alle metoder.
	// Menu frames.
		JFrame hMenu         	= new JFrame();
		JFrame accountMan			= new JFrame();
		JFrame systemMan			= new JFrame();
		JFrame backupMan			= new JFrame();
		JFrame newAccMan			= new JFrame();
		JFrame displayAcc			= new JFrame();
	
	// Service funktion frames.
		JFrame savTrans			= new JFrame();
		JFrame curTrans			= new JFrame();
		JFrame depo					= new JFrame();
		JFrame with					= new JFrame();
		JFrame rate					= new JFrame();
		
		JButton returnButton		= new JButton("Tilbage til hovedmenu.");
		JButton godkend 			= new JButton("Godkend");
		
	// Herfra påbegyndes konstruktionen af samtlige menuer, actionlistenere og funktioner dertil.
		public menu() {
		
	// Menu knapper initialiseres.
		JButton konto 		  		= new JButton();
		JButton backup		  		= new JButton();
		JButton system		  		= new JButton();
		JButton newAcc				= new JButton();
		
		// actionlisteners implementeres
		konto.addActionListener (new kontoManagement() );		
		backup.addActionListener(new backupManagement());
		system.addActionListener(new systemManagement());
		newAcc.addActionListener(new createNewAccount());
					
		JLabel HMI = new JLabel("Velkommen! Foretag venligst et valg for at navigere.");
	
		JPanel HMP = new JPanel();
		HMP.setLayout(new BoxLayout(HMP, BoxLayout.Y_AXIS));
		


	// Hoved menu knapper indstilles:
		menuButton(konto,  "Administrér konto"   );
		menuButton(backup, "Anvend backup system");
		menuButton(system, "Systemindstillinger" );
		menuButton(newAcc, "Opret ny konto"		  );
	
	// Hver menu skabes med de presets, som er indstillet i menu-classen.
		menuFrame(hMenu, "Hovedmenu");
						
			hMenu.setVisible(true);
			hMenu.setLayout (new BorderLayout());
			hMenu.add(HMI, BorderLayout.NORTH);
			hMenu.add(HMP, BorderLayout.WEST);
			
				HMP.add(Box.createRigidArea(space));
				HMP.add(konto);
				HMP.add(Box.createRigidArea(space));
				HMP.add(backup);
				HMP.add(Box.createRigidArea(space));
				HMP.add(system);
				HMP.add(Box.createRigidArea(space));
				HMP.add(newAcc);
			

		}
	
	
	public class createNewAccount implements ActionListener {
		public void actionPerformed (ActionEvent e) {
			hMenu.setVisible(false);
			newAccMan.setVisible(true);
			menuFrame(newAccMan, "Skab ny konto");
			newAccMan.setLayout(new GridLayout(0, 2));
			setReturn(6);
			
				fNameF 	 = new TextField(20);
				lNameF 	 = new TextField(20);
				cprNumF   = new TextField(10);
				streetF   = new TextField(10);
				cityF 	 = new TextField(10);
				phoneNumF = new TextField(10);
				
				newAccMan.add(new JLabel("Fornavn:"));
				newAccMan.add(fNameF);
				newAccMan.add(new JLabel("Efternavn:"));
				newAccMan.add(lNameF);
				newAccMan.add(new JLabel("CPR Nummer:"));
				newAccMan.add(cprNumF);
				newAccMan.add(new JLabel("Gade samt nummer:"));
				newAccMan.add(streetF);
				newAccMan.add(new JLabel("Postnummer og by:"));
				newAccMan.add(cityF);
				newAccMan.add(new JLabel("Telefon nummer:"));
				newAccMan.add(phoneNumF);
				newAccMan.add(godkend);
				returnButton.addActionListener(new returnToHMenu());
				godkend.addActionListener(new acceptNewAcc());
		}
	}
	
				public class acceptNewAcc implements ActionListener {
					public void actionPerformed (ActionEvent e) {
						fName  	= fNameF.getText();
						lName  	= lNameF.getText();
						cprNum 	= cprNumF.getText();
						street 	= streetF.getText();
						city 	   = cityF.getText();
						phoneNum = phoneNumF.getText();
						
						account confirm = new account();
						
						try {
						confirm.saveAccount(fName, lName, cprNum, street, city, phoneNum);
							}
						catch(FileNotFoundException message) {
							System.out.println(message);
							}
					}
				}
		
	public class kontoManagement implements ActionListener {
		public void actionPerformed (ActionEvent e) {
			hMenu.setVisible(false);	
			menuFrame(accountMan, "Konto administration");
			accountMan.setVisible(true);
			setReturn(1);
			
			accountMan.setLayout(new BorderLayout());
			
			JButton savingsTrans    = new JButton();
			JButton currentTrans    = new JButton();
			JButton makeDeposit	   = new JButton();
			JButton displayAcc		= new JButton();

			
			menuButton(savingsTrans,   "Foretag transaktion fra opsparings- til lønkonto."	 );
			menuButton(currentTrans,   "Foretag transaktion fra lønkonto til angiven konto."	 );
			menuButton(makeDeposit,    "Indsæt beløb på konto."										 );
			menuButton(displayAcc,		"Vis konto information"											 );
			
			savingsTrans.addActionListener(new savingsTransaction());
			currentTrans.addActionListener(new currentTransaction());
			makeDeposit.addActionListener(new deposit());
			displayAcc.addActionListener(new displayAccount());
			returnButton.addActionListener(new returnToHMenu());
			
			
			JPanel KM					= new JPanel();
			KM.setLayout(new BoxLayout(KM, BoxLayout.Y_AXIS));
			KM.add(savingsTrans);
			KM.add(Box.createRigidArea(space));
			KM.add(currentTrans);
			KM.add(Box.createRigidArea(space));
			KM.add(makeDeposit);
			KM.add(Box.createRigidArea(space));
			KM.add(displayAcc);
			
			accountMan.add(KM, BorderLayout.WEST);
			
			JPanel KMB = new JPanel();
			KMB.setLayout(new BoxLayout(KMB, BoxLayout.X_AXIS));
			accountMan.add(KMB, BorderLayout.SOUTH);
			
			KMB.add(returnButton);					
			}
		}
		
						public class displayAccount implements ActionListener {
							public void actionPerformed (ActionEvent e) {
								displayAcc.setVisible(true);
								accountMan.setVisible(false);
								cprNumF = new TextField(10);
								
								godkend.addActionListener(new acceptdisplay());
								
								displayAcc.setLayout(new GridLayout(0,2));
								
								
								
								displayAcc.add(new JLabel("Indtast CPR:"));
								displayAcc.add(cprNumF);
								displayAcc.add(godkend);
															
							}
						}
						
								public class acceptdisplay implements ActionListener {
									public void actionPerformed (ActionEvent e) {
										cprNum = cprNumF.getText();
										
										searchAccount find = new searchAccount();
										try {
										find.accountReader(cprNum);
										}
										catch(FileNotFoundException message) {
										System.out.println(message);
										}
									
									}
								}
								
						// Alle funktioner under konto management
						public class savingsTransaction implements ActionListener {
							public void actionPerformed (ActionEvent e) {
								accountMan.setVisible(false);
								savTrans.setVisible(true);
								setReturn(2);
								
								menuFrame(savTrans, "Opsparingskonto overførsel til lønkonto.");
								savTrans.setLayout(new BorderLayout());
								
								JPanel savPanel = new JPanel(new GridLayout(0,2));
								amountF 			 = new TextField(8);
								savAccNumF 		 = new TextField(8);
								JPanel SPB		 = new JPanel();
								SPB.setLayout(new BoxLayout(SPB, BoxLayout.X_AXIS));
								
								savPanel.add(new JLabel("Opsparingskonto nummer: "));
								savPanel.add(savAccNumF);
								savPanel.add(new JLabel("Beløb at overføre til lønkonto: "));
								savPanel.add(amountF);
								savTrans.add(savPanel, BorderLayout.WEST);
								
								returnButton.addActionListener(new returnToHMenu());
								godkend.addActionListener(new runSavTrans());
								
								SPB.add(godkend);
								SPB.add(returnButton);
								
								
								savTrans.add(SPB, BorderLayout.SOUTH);
							}
						}
						
						
								public class runSavTrans implements ActionListener {
									public void actionPerformed (ActionEvent e) {
											savAccNum = savAccNumF.getText();
											amount    = amountF.getText();
											
											double tAmount = Double.parseDouble(amount);
											
											makeTransfer savTrans = new makeTransfer();
											try {
											savTrans.makeSavingsTransfer(savAccNum, tAmount);
											}
											catch (FileNotFoundException message) {
												System.out.println(message);
												}
										
										}
								}
						
						public class currentTransaction implements ActionListener {
							public void actionPerformed (ActionEvent e) {
								accountMan.setVisible(false);
								curTrans.setVisible(true);
								setReturn(3);
								menuFrame(curTrans, "Foretag transaktion for lønkonto.");
								curTrans.setLayout(new BorderLayout());
								JPanel curPanel = new JPanel(new GridLayout(0,2));
								
								returnButton.addActionListener(new runCurTrans());
								
								curAccNumF  = new TextField(8);
								destAccNumF = new TextField(8);
								amountF 		= new TextField(8);
								
								curTrans.add(new JLabel("Her kan du overføre transaktioner til en specificeret konto."));
								curPanel.add(new JLabel("Indtast lønkonto nummer:"));
								curPanel.add(curAccNumF);
								curPanel.add(new JLabel("Indtast modtager konto:"));
								curPanel.add(destAccNumF);
								curPanel.add(new JLabel("Beløb at overføre fra lønkonto:"));
								curPanel.add(amountF);
								
								JPanel BCP = new JPanel(new GridLayout(0,2));
								
								curTrans.add(curPanel, BorderLayout.WEST);
								returnButton.addActionListener(new returnToHMenu());
								
								BCP.add(godkend);
								BCP.add(returnButton);
								curTrans.add(BCP, BorderLayout.SOUTH);
								
								
							}
						}
								
								public class runCurTrans implements ActionListener {
										public void actionPerformed (ActionEvent e) {
											curAccNum  = curAccNumF.getText();
											destAccNum = destAccNumF.getText();
											amount 	  = amountF.getText();
										
										}
								}
								
								
						public class deposit implements ActionListener {
							public void actionPerformed (ActionEvent e) {
								depo.setVisible(true);
								accountMan.setVisible(false);
								setReturn(4);
								menuFrame(depo, "Foretag kontoudtog eller indsæt beløb.");
								godkend.addActionListener(new makeDeposit());
								returnButton.addActionListener(new returnToHMenu());
								curAccNumF = new TextField(8);
								amountF 		= new TextField(8);
								
								JPanel DP = new JPanel();
								DP.setLayout(new GridLayout(0,2));
								DP.add(new JLabel("Indtast beløb at udtrække/indsætte"));
								DP.add(amountF);
								DP.add(new JLabel("Indtast kontonummer"));
								DP.add(curAccNumF);
								DP.add(godkend);
								DP.add(returnButton);
								
								depo.add(DP);
							}
						}
										
										public class makeDeposit implements ActionListener {
												public void actionPerformed (ActionEvent e) {
													String curAccNum  	= curAccNumF.getText();
													String amount	   	= amountF.getText();
													double tAmount 		= Double.parseDouble(amount);
													makeTransfer deposit = new makeTransfer();
													
													try {
														deposit.makeDeposit(curAccNum, tAmount);
													}
													catch (FileNotFoundException message) {
														System.out.println(message);
														System.exit(0);
													}
												}
										}
										
	
	public class systemManagement implements ActionListener {
		public void actionPerformed (ActionEvent e) {
			setReturn(5);
			hMenu.setVisible(false);
			menuFrame(systemMan, "System administration.");
			systemMan.setVisible(true);
			systemMan.setLayout(new BorderLayout());
			
			JPanel SMP = new JPanel();
			SMP.setLayout(new GridLayout(0,2));
			JButton newLogin = new JButton();
			JButton setInterestRate = new JButton();
			menuButton(newLogin, "Opret nyt login.");
			menuButton(setInterestRate, "Indstil rente");
			setInterestRate.addActionListener(new adjustRate());
			returnButton.addActionListener(new returnToHMenu());
			
			SMP.add(newLogin);
			SMP.add(setInterestRate);
			SMP.add(returnButton);
			
			systemMan.add(SMP, BorderLayout.WEST);
			
			
			}
		}
	
					public class adjustRate implements ActionListener {
							public void actionPerformed (ActionEvent e) {
							godkend.addActionListener(new acceptNewRate());
							systemMan.setVisible(false);
							rate.setVisible(true);
							menuFrame(rate, "Justér bankens rente.");
							rateF = new TextField(20);
							rate.setLayout(new GridLayout(0,2));
							rate.add(new JLabel("Indtast ny rente, f.eks. 1,010."));
							rate.add(rateF);
							rate.add(godkend);
							}
							}		
							
							public class acceptNewRate implements ActionListener {
								public void actionPerformed(ActionEvent e) {
								newRate = rateF.getText();
								account setTheRate = new account();
								
								double updatedRate = Double.parseDouble(newRate);
								
													try {
														setTheRate.setInterestRate(updatedRate);
													}
													catch (FileNotFoundException message) {
														System.out.println(message);
														System.exit(0);
														
													}
								}
							}
	
	public class backupManagement implements ActionListener {
		public void actionPerformed (ActionEvent e) {
			setReturn(10);
			hMenu.setVisible(false);
			menuFrame(backupMan, "Backup system.");
			backupMan.setVisible(true);
			
			returnButton.addActionListener(new returnToHMenu());
			}
		}
					
	public class returnToHMenu implements ActionListener {
		public void actionPerformed (ActionEvent e) {
			if(returnNum == 1) {
			accountMan.setVisible(false);
			}
			else if(returnNum == 2) {
			savTrans.setVisible(false);
			}
			else if(returnNum == 3) {
			curTrans.setVisible(false);
			}
			else if(returnNum == 4) {
			depo.setVisible(false);
			}
			else if(returnNum == 5) {
			systemMan.setVisible(false);
			}
			else if(returnNum == 6) {
			newAccMan.setVisible(true);
			}
			hMenu.setVisible(true);
		}
	}
					
		// Mutator til at lave menu framet med standard størrelse 600x400.		
	public void menuFrame (JFrame frame, String title){
			frame.setSize(500, 200);
			frame.setTitle("Bank-a-tron 2k. " + title);
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			frame.setLocationRelativeTo(null); 										//Placerer samtlige frames i midten af skærmen.
			frame.setBackground(Color.	WHITE);
		}
		
		public void menuButton (JButton button, String buttonText) {
			button.setText(buttonText);
			button.setPreferredSize(this.buttSize);
		}
		
		public void menuTextArea (String areaText) {
			new TextArea(areaText, 5, 20);
		}
		
		public void actionPerformed(ActionEvent e) {
		
		}
		
		public void setReturn (int menuNum) {
		this.returnNum = menuNum;
		}

}