import [Link].
Color;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class NewAccount extends JInternalFrame implements ActionListener {
private JPanel jpInfo = new JPanel();
private JLabel lbAccountNo, lbStudName, lbStudAdd, lbStudCity, lbStudState,
lbStudContNo, lbDeposit, lbDeposit2, lbDeposit3, lbNotes;
private JTextField txAccountNo, txStudName, txStudAdd, txStudCity,
txStudState, txStudContNo, txDeposit, txDeposit2, txDeposit3, txNotes;
private JButton btnSave, btnCancel;
private int count = 0;
private int rows = 0;
private int total = 0;
// String Type Array use to Load Records From File.
private String records[][] = new String[500][10];
// String Type Array use to Save Records into File.
private String saves[][] = new String[500][10];
private FileInputStream fis;
private DataInputStream dis;
NewAccount() {
// super(Title, Resizable, Closable, Maximizable, Iconifiable)
super("Add New Student", true, true, true, true);
setSize(500, 500);
[Link](0, 0, 500, 115);
[Link](null);
lbAccountNo = new JLabel("Student Number: ");
[Link]([Link]);
[Link](15, 20, 100, 25);
lbStudName = new JLabel("Student Name:");
[Link]([Link]);
[Link](15, 55, 100, 25);
lbStudAdd = new JLabel("Address:");
[Link]([Link]);
[Link](15, 90, 100, 25);
lbStudCity = new JLabel("City:");
[Link]([Link]);
[Link](15, 125, 100, 25);
lbStudState = new JLabel("State:");
[Link]([Link]);
[Link](15, 160, 100, 25);
lbStudContNo = new JLabel("Mobile No.:");
[Link]([Link]);
[Link](15, 195, 100, 25);
lbDeposit = new JLabel("Enter Creativity:");
[Link]([Link]);
[Link](15, 265, 100, 25);
lbDeposit2 = new JLabel("Enter Action:");
[Link]([Link]);
[Link](15, 295, 100, 25);
lbDeposit3 = new JLabel("Enter Service:");
[Link]([Link]);
[Link](15, 325, 100, 25);
lbNotes = new JLabel("Enter Remarks:");
[Link]([Link]);
[Link](15, 355, 100, 25);
txAccountNo = new JTextField();
[Link]([Link]);
[Link](125, 20, 205, 25);
txStudName = new JTextField();
[Link](125, 55, 205, 25);
txStudAdd = new JTextField();
[Link](125, 90, 205, 25);
txStudCity = new JTextField();
[Link](125, 125, 205, 25);
txStudState = new JTextField();
[Link](125, 160, 205, 25);
txStudContNo = new JTextField();
[Link](125, 195, 205, 25);
txDeposit = new JTextField();
[Link]([Link]);
[Link](125, 265, 205, 25);
txDeposit2 = new JTextField();
[Link]([Link]);
[Link](125, 295, 205, 25);
txDeposit3 = new JTextField();
[Link]([Link]);
[Link](125, 325, 205, 25);
txNotes = new JTextField();
[Link](125, 355, 205, 25);
// Restricting The User Input to only Numerics in Student Number Box
// by using method if (!(([Link](c)
[Link](new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = [Link]();
if (!(([Link](c) || (c == KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep();
[Link]();
}
}
});
[Link](new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = [Link]();
if (!(([Link](c) || (c == KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep();
[Link]();
}
}
});
[Link](new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = [Link]();
if (!(([Link](c) || (c == KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep();
[Link]();
}
}
});
[Link](new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = [Link]();
if (!(([Link](c) || (c == KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep();
[Link]();
}
}
});
// input validation that restricts user to enter specific number
[Link](new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char keyChar = [Link]();
if(!([Link]() >= '5' && [Link]() <= '9')) {
getToolkit().beep();
[Link]();
}
}
});
[Link](new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = [Link]();
if (!(([Link](c) || (c == KeyEvent.VK_BACK_SPACE)))) {
getToolkit().beep();
[Link]();
}
}
});
// Restricting The User Input to only Letters/Digits/White spaces in Input Boxes
// accept only Characters, White spaces, BACK_SPACE, or DELETE
// by these methods: if (!([Link](c) || [Link](c)
[Link](new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = [Link]();
if (!([Link](c) || [Link](c) ||
c == KeyEvent.VK_BACK_SPACE ||
c == KeyEvent.VK_DELETE)){
getToolkit().beep();
[Link]();
}
}
});
// accept only UPPER CASE LETTERS, White spaces, BACK_SPACE, or DELETE
// by these methods: if (!([Link](c)
[Link](new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = [Link]();
if (!([Link](c) || [Link](c) ||
c == KeyEvent.VK_BACK_SPACE ||
c == KeyEvent.VK_DELETE)){
getToolkit().beep();
[Link]();
}
}
});
[Link](new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = [Link]();
if (!([Link](c) || [Link](c) ||
c == KeyEvent.VK_BACK_SPACE ||
c == KeyEvent.VK_DELETE)){
getToolkit().beep();
[Link]();
}
}
});
[Link](new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = [Link]();
if (!([Link](c) || [Link](c) ||
c == KeyEvent.VK_BACK_SPACE ||
c == KeyEvent.VK_DELETE)){
getToolkit().beep();
[Link]();
}
}
});
// accept both Characters & Digits, BACK_SPACE, or DELETE
// by using method if (!([Link](c) ||
[Link](new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = [Link]();
if (!([Link](c) || [Link](c) ||
c == KeyEvent.VK_BACK_SPACE ||
c == KeyEvent.VK_DELETE)){
getToolkit().beep();
[Link]();
}
}
});
// Aligning The Buttons.
btnSave = new JButton("Save");
[Link](20, 400, 120, 25);
[Link](this);
btnCancel = new JButton("Cancel");
[Link](185, 400, 120, 25);
[Link](this);
[Link](lbAccountNo);
[Link](txAccountNo);
[Link](lbStudName);
[Link](txStudName);
[Link](lbStudAdd);
[Link](txStudAdd);
[Link](lbStudCity);
[Link](txStudCity);
[Link](lbStudState);
[Link](txStudState);
[Link](lbStudContNo);
[Link](txStudContNo);
[Link](lbDeposit);
[Link](txDeposit);
[Link](lbDeposit2);
[Link](txDeposit2);
[Link](lbDeposit3);
[Link](txDeposit3);
[Link](lbNotes);
[Link](txNotes);
[Link](btnSave);
[Link](btnCancel);
// Adding Panel to Window.
getContentPane().add(jpInfo);
// In the End Showing the New Account Window.
setVisible(true);
// Function use By Buttons of Window to Perform Action as User Click Them.
public void actionPerformed(ActionEvent ae) {
Object obj = [Link]();
if (obj == btnSave) {
if ([Link]().equals("")
|| [Link]().equals("")
|| [Link]().equals("")
|| [Link]().equals("")
|| [Link]().equals("")
|| [Link]().equals("")
|| [Link]().equals("")
|| [Link]().equals("")
|| [Link]().equals("")
|| [Link]().equals("")) {
JOptionPane
.showMessageDialog(
null,
"Entries Empty: Fill in the required entries to Add a new Student!!!!!",
"CAS Management System",
JOptionPane.INFORMATION_MESSAGE);
} else {
populateArray(); // Load All Existing Records in Memory.
findRec(); // Finding if Student No. Already Exists or Not.
}
}
if (obj == btnCancel) {
txtClear();
setVisible(false);
dispose();
}
// Function use to load all Records from File when Application Execute.
void populateArray() {
try {
fis = new FileInputStream("[Link]");
dis = new DataInputStream(fis);
// Loop to Populate the Array.
while (true) {
for (int i = 0; i < 10; i++) {
records[rows][i] = [Link]();
}
rows++;
}
} catch (Exception ex) {
total = rows;
if (total == 0) {
} else {
try {
[Link]();
[Link]();
} catch (Exception exp) {
}
}
}
// Function use to Find Record by Matching the Contents of Records Array
// with ID TextBox.
void findRec() {
boolean found = false;
for (int x = 0; x < total; x++) {
if (records[x][0].equals([Link]())) {
found = true;
[Link](this,
"Invalid Entries: Student Number " +
[Link]()
+ "already exists!!!!!",
"CAS Management System", JOptionPane.PLAIN_MESSAGE);
txtClear();
break;
}
}
if (found == false) {
saveArray();
}
// Function use to add new Element to Array.
void saveArray() {
saves[count][0] = [Link]();
saves[count][1] = [Link]();
saves[count][2] = [Link]();
saves[count][3] = [Link]();
saves[count][4] = [Link]();
saves[count][5] = [Link]();
saves[count][6] = [Link]();
saves[count][7] = [Link]();
saves[count][8] = [Link]();
saves[count][9] = [Link]();
saveFile(); // Save This Array to File.
count++;
// Function use to Save new Record to the File.
void saveFile() {
try {
FileOutputStream fos = new FileOutputStream("[Link]", true);
DataOutputStream dos = new DataOutputStream(fos);
[Link](saves[count][0]);
[Link](saves[count][1]);
[Link](saves[count][2]);
[Link](saves[count][3]);
[Link](saves[count][4]);
[Link](saves[count][5]);
[Link](saves[count][6]);
[Link](saves[count][7]);
[Link](saves[count][8]);
[Link](saves[count][9]);
[Link](this,
"Record Saved: New Entry saved Successfully!!!!!",
"CAS Management System", JOptionPane.PLAIN_MESSAGE);
txtClear();
[Link]();
[Link]();
} catch (IOException ioe) {
}
// Function use to Clear all TextFields of Window.
void txtClear() {
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]("");
[Link]();
}
}