meljun cortes documentation
Post on 04-Apr-2018
230 Views
Preview:
TRANSCRIPT
-
7/31/2019 MELJUN CORTES Documentation
1/42
Version 1.0
Maria Pamela C. David
-
7/31/2019 MELJUN CORTES Documentation
2/42
Ang Bulilit Liga Athlete Record Maintenance SystemTechnical Documentation
Preface
The athlete record maintenance system was designed to allow authorized system users to quicklyretrieve and view existing athlete records, edit these, or add records in cases where no hits to a valid search
are obtained. It uses a modular architecture (package-based), which makes it easily extensible in the event
that additional features or functions will be required. The record maintenance system was developed using
mySQL and Java, which interfaces via JDBC/ODBC.
Features
Security
System modules (Find Athlete, Edit Records and Add Athlete) are protected by a log-in facility,
which is connected to a database table containing the list of authorized users and their corresponding
passwords. A successful log-in (Figure 1a) results in the creation of a Find Athlete instance (Figure 2). The
system is able to detect errors resulting from the non-existence of the username, or the invalidity of the
password (Figures 1b and 1c).
A
B
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
2
-
7/31/2019 MELJUN CORTES Documentation
3/42
-
7/31/2019 MELJUN CORTES Documentation
4/42
Figure 2. Finding athletes using single (A,B) and multiple (C,D) parameter searches.Supported single-parameter searches include search by athlete status, athlete ID, last name, first name, or middle initial. Multiple-parameter searches are more restrictive, and are more likely to yield single records than single-parameter searches.
A B
C D
To retrieve a record from the list of matches, it is necessary to select a name from the list beforeusing the Get Record button. Failure to do so results in an error (Figure 3). Otherwise, retrieval is
successful, and the appropriate record is displayed; retrieval is restricted to single selection, but it is
possible to display multiple records at a given time (Figure 4). Records retrieved are, by default, non-
editable, since their primary purpose is for viewing information. However, it is possible to edit the record
contents by using theEdit button.
Record Editing
The record editing facility is embedded within the record itself, and is triggered when the user opts
to edit it. This results in the transformation of selected non-editable fields to editable fields (Figure 5). The
athlete ID and the athlete gender are left non-editable in order to minimize possible sources of errors.
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
4
-
7/31/2019 MELJUN CORTES Documentation
5/42
Figure 3. Erroneous recordretrieval.Error that results fromattempting to retrieve a recordwithout a valid selection.
Figure 4. Record retrieval.It is possible to open multiple records from separate searches. All fields are, by default,non-editable. Note that theSave button, which could only be applied when a record is edited, is inactivated.
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
5
-
7/31/2019 MELJUN CORTES Documentation
6/42
Figure 5. Record editing.Records are edited in the same window as the read-only record; the option to save isactivated concurrently with the conversion of editable to non-editable fields.
Upon completion of editing, the user may opt to save the changes. A save message confirmation is
presented (Figure 6a), which the user may opt to cancel by closing the dialog box. In the event that the user opts to proceed with the record update, the update may or may not be implemented, depending on the
completeness of the data indicated. Of all the fields in the record, only the secondary sport field is optional.
The omission of one or more of the required fields (Figure 6c) results in an error which specifies that one or
more of these have been left blank. A record update is successful in the event that all the required
information are complete and valid (Figure 6d). After the update, all fields revert to the original, non-editable
state.
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
6
-
7/31/2019 MELJUN CORTES Documentation
7/42
Figure 6. Updating records.When a user opts to save changes made to a record, aconfirmation message appears prior to theactual database update (A). This preventsunwanted changes from being made to arecord prior to user approval. It is possible tocancel the update by closing the dialog box, inwhich case the user is informed that nochanges were made (B). Assuming, however,that the user opts to save the changes, twopossible scenarios may emerge. In the eventthat one or more of the required fields wereleft blank (C), an error message appearsindicating that this is the case. Changes willnot be made to the record until all informationis complete; if this is the case, the user isinformed that the record has been updated(D). Note that the athlete ID, which is theprimary key for athlete records, and which isclosely related to the primary key for guardianrecords, is left non-editable to minimize thechances of error.
A
B
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
7
-
7/31/2019 MELJUN CORTES Documentation
8/42
C
D
Record Creation
The Add Athlete facility for record creation is only activated in the event that valid search
parameters (at least, as expected by the users) do not yield matches. This restriction was imposed primarilybecause record creation is routinely made elsewhere, and is not a primary functionality of the record
maintenance system. However, for convenience, a similar facility could be activated from this module. When
this happens, the user is asked whether s/he would like to create a new record (Figures 7a and 7b). If the
user opts to do so, an instance of the Add Athlete form is created, where the user has to input all athlete
data (Figure 7c). As in the case of record updating, the completeness of the information is checked prior to
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
8
-
7/31/2019 MELJUN CORTES Documentation
9/42
the inclusion of the record in the database (Figure 7d). Simultaneous insertions are performed on the
athlete, guardian and assignGuardian tables in a single execution of add athlete. The event flow is basically
the same as in record editing, where the user is prompted to confirm the addition of the record to the
database. The scenario in which data could be incomplete is also addressed by a similar error message;
successful record insertions are also indicated. Record insertions may fail in the event that an invalid entryor a duplicate entry exists (for the primary key); the corresponding SQL error is also indicated in the error
message to allow the user to quickly identify and correct the problem (Figure 8).
Figure 7. Athlete record creation from the athlete record maintenance system.The add athlete facility is activatedonly after an unsuccessful search (A and B); when the user opts to create a record, an add athlete form appears, which
has to be completed by the user. In the event of successful insertions, the user is notified that the record has beenadded to the database.
A B
C D
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
9
-
7/31/2019 MELJUN CORTES Documentation
10/42
Figure 8. Unsuccessful recordinsertion.Such errors may occur if the primary key is duplicated, or if some of the data are invalid (i.e.inclusion of characters whereintegers are expected). The SQLerror is indicated in the error message to enable the user toquickly identify the problem.
Selectivity
An added feature of the system is its ability to discriminate between club staff members and
coaches. For consistency purposes, the addition of records and full record updating capabilities are granted
to club staff members only. Coach updates are restricted to status changes only. The views, however, are
generally the same, with the exception of the Record view, where fields remain non-editable when a coach
opts to make changes to the record.
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
10
-
7/31/2019 MELJUN CORTES Documentation
11/42
Appendix I. mySQL Table creation scripts
Create table users(username varchar(30) primary key,password varchar(20) not null,userLastName varchar(30) not null,
userFirstName varchar(30) not null,userMI varchar(1) not null,userType varchar(10) not null) type = innoDB;
CREATE table athlete(athleteID varchar(10) primary key,athleteLastName varchar(30) not null,athleteFirstName varchar(30) not null,athleteMI varchar(1) not null,athleteStreetAddress varchar(50) not null,athleteCityAddress varchar(20) not null,ZipCode varchar(4) not null,athleteContactNo varchar(11) not null,athleteBirthDate Date,athleteGender varchar(1) not null,athletePrimarySport varchar(15) not null,athleteSecondarySport varchar(15),athleteStatus varchar(15) not null,guardianID varchar(11) NOT NULL) type = innoDB;
CREATE table guardian(guardianID varchar(11) primary key,guardianLastName varchar(30) not null,guardianFirstName varchar(30) not null,guardianMI varchar(1) not null,guardianStreetAddress varchar(50) not null,
guardianCityAddress varchar(20) not null,guardianZipCode varchar(4) not null,guardianContactNo varchar(11) not null) type = innoDB;
CREATE table assignGuardian(athleteID varchar(10),guardianID varchar(11),constraint pk primary key (athleteID, guardianID)) type = innoDB;
ALTER table assignGuardian add constraint fk foreign key (athleteID)references athlete (athleteID)ON UPDATE CASCADE ON DELETE CASCADE;
ALTER table assignGuardian add constraint fk1 foreign key (guardianID)references guardian (guardianID)ON UPDATE CASCADE ON DELETE CASCADE;
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
11
-
7/31/2019 MELJUN CORTES Documentation
12/42
Appendix II. Source Codes
Main Window
import java.awt.*;import java.awt.event.*;
import javax.swing.*;
import angBulilitLiga.UserLogIn;import angBulilitLiga.About;
public class ABLMain extends JFrame{
private JButton loginButton, aboutButton, pic;
public ABLMain() {super ( "Ang Bulilit Liga " );
Container container = getContentPane();container.setLayout( new FlowLayout () );
Icon abl = new ImageIcon( "abl.jpg" );
loginButton = new JButton( "Log In" );aboutButton = new JButton( "About ABL" );pic = new JButton("", abl );container.add( pic );container.add( loginButton );container.add( aboutButton );
ButtonHandler handler = new ButtonHandler();loginButton.addActionListener( handler );aboutButton.addActionListener( handler );
setSize( 816, 300 );setVisible( true );
}
public static void main(String[] args){
ABLMain application = new ABLMain();application.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE );
}
private class ButtonHandler implements ActionListener{
public void actionPerformed( ActionEvent e ){if (e.getActionCommand() == "Log In"){
UserLogIn ui = new UserLogIn();}
if (e.getActionCommand() == "About ABL"){
JTextArea info = new JTextArea();String text = "Ang Bulilit Liga\n";text += "Athlete Record Maintenance System\n";text += "Version 1.0\n";text += "Developed by Maria Pamela C. David\n\n";
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
12
-
7/31/2019 MELJUN CORTES Documentation
13/42
text += "Ang Bulilit Liga was established ten (10)years ago by a group of individuals who loved\n";
text += "to coach basketball teams that competeduring the summer months. It is a training club\n";
text += "for young boys ages 8 to 13 years old. Itteaches them the sport, basketball, with the\n";
text += "emphasis on the playful and social aspectsof the game while also learning technical\n";
text += "skills. The owners envisioned a club that(1) will foster camaraderie among its young\n";
text += "athletes through training and competing as ateam in junior sports events, and (2) will\n";
text += "instill sportsmanship among them.\n\n";text += "The club's teams have consistently competed
on junior basketball tournaments, both local\n";text += "and national.Their performance has been
excellent throughout the years. Most members have\n";text += "gone on to play professional basketball.
Currently, they have over 150 members.\n\n";text += "This system was developed to cater to the
club's growing database requirements\n";text += "concurrent with its expansion.";
info.setText( text );
JOptionPane.showMessageDialog( null, info,"About", JOptionPane.INFORMATION_MESSAGE );
}}
}}
User Log In Facility
package angBulilitLiga;
import java.sql.*;
import javax.swing.*;import java.awt.*;import java.awt.event.*;
import angBulilitLiga.FindRecord;import angBulilitLiga.CoachFindRecord;
public class UserLogIn extends JFrameimplements ActionListener {
private Connection connection;
private Container container;private FlowLayout layout;
private static String OK = "ok";private static String CANCEL = "cancel";
private JTextField usernameField;private JPasswordField passwordField;
public UserLogIn() {
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
13
-
7/31/2019 MELJUN CORTES Documentation
14/42
-
7/31/2019 MELJUN CORTES Documentation
15/42
cancelButton.setActionCommand(CANCEL);okButton.addActionListener(this);cancelButton.addActionListener(this);
setSize( 300, 150 );setVisible( true );
}
public void actionPerformed(ActionEvent e) {String cmd = e.getActionCommand();
//Statement statement;ResultSet resultSet;
if (CANCEL.equals(cmd)){
System.exit(0);}
if (OK.equals(cmd)) {//Process usernameString user = usernameField.getText();
try {if ( !user.equals( "" ) ) {
Statement statement =connection.createStatement();String query = "SELECT username, password, userType FROM
users " +"WHERE username = '" +user + "'";
ResultSet rs = statement.executeQuery( query );
//call method for checking if the username andpassword match
check( rs );
statement.close();} else {JOptionPane.showMessageDialog(null,
"Please enter your username!","Error Message",
JOptionPane.ERROR_MESSAGE);}
}
catch ( SQLException sqlex ) {sqlex.printStackTrace();
}}
}
public void check( ResultSet rs ) throws SQLException {try {rs.next();
String username = rs.getString( 1 );String usernamein = usernameField.getText();
if (username.equals(usernamein)) {//check if password matches hereString password = rs.getString( 2 );String enteredPassword = passwordField.getText();
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
15
-
7/31/2019 MELJUN CORTES Documentation
16/42
if (enteredPassword.equals(password)){
//get user typeString type = rs.getString( 3 );
if (type.equals("club staff")){
FindRecord findRecord = new FindRecord();}
if (type.equals("coach")){
CoachFindRecord coachFind = newCoachFindRecord();
}
} else {JOptionPane.showMessageDialog(null,"Invalid password. Try again.",
"Error Message", JOptionPane.ERROR_MESSAGE);}
}
}
catch ( SQLException sqlex ) {JOptionPane.showMessageDialog(null,
"User name does not exist. Please contact\n"+ "the database administrator.\n",
"Error Message", JOptionPane.ERROR_MESSAGE);sqlex.printStackTrace();
}}
public static void main(String[] args) {
UserLogIn application = new UserLogIn();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}}
/*UserLogIn.javaWritten by Maria Pamela C. Davidin partial fulfillment of the requirementsin CS192*/
Athlete Record Retrieval facility
package angBulilitLiga;
import java.sql.*;
import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;
import java.util.StringTokenizer;
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
16
-
7/31/2019 MELJUN CORTES Documentation
17/42
import angBulilitLiga.AddAthlete;import angBulilitLiga.Record;
public class FindRecord extends JFrame implements ActionListener{
private Connection connection;
private Container container;private GridBagLayout layout;private GridBagConstraints constraints;
private static String FIND = "findAthlete";private static String CANCEL = "cancel";
private static String SELECT = "getRecord";
public static List matchList;
//public DefaultListModel athleteNames;
private JTextField athleteIDfield, athleteLastNameField,athleteFirstNameField, athleteMIField;
private JLabel athleteIDlabel, athleteLastNameLabel,athleteFirstNameLabel, athleteMILabel,
athleteSearchbyStatusLabel, athleteMatchLabel;private JLabel space, space1, space2;private JButton findAthleteButton, getRecordButton, cancelButton;private JComboBox athleteStatusComboBox;
private String athleteStatus[] = {"Active", "Injured", "Unavailable","Suspended", "Blacklisted",
"Inactive", "Graduated"};
public FindRecord(){
super( "Find Athlete" );
//For connecting to databaseString url = "jdbc:odbc:angbulilitliga";String username = "root";String password = "password";
try{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );connection = DriverManager.getConnection(
url, username, password );}catch ( ClassNotFoundException cnfex ){
System.err.println( "Failed to load JDBC/ODBC driver." );cnfex.printStackTrace();
System.exit(1);}
catch (SQLException sqlex ) {System.err.println( "Unable to connect" );sqlex.printStackTrace();
}
container = getContentPane();layout = new GridBagLayout();
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
17
-
7/31/2019 MELJUN CORTES Documentation
18/42
container.setLayout( layout );
constraints = new GridBagConstraints();
athleteIDlabel = new JLabel( "Athlete ID ");athleteLastNameLabel = new JLabel("Last Name ");athleteFirstNameLabel = new JLabel("First Name ");athleteMILabel = new JLabel("MI ");athleteSearchbyStatusLabel = new JLabel("Status ");athleteMatchLabel = new JLabel("Match(es) ");
JScrollPane matchListScrollPane = new JScrollPane(matchList);
space = new JLabel(" ");space1 = new JLabel(" ");space2 = new JLabel(" ");
athleteIDfield = new JTextField( 5 );athleteLastNameField = new JTextField( 10 );athleteFirstNameField = new JTextField( 10 );athleteMIField = new JTextField( 1 );
athleteStatusComboBox = new JComboBox( athleteStatus );athleteStatusComboBox.setSelectedIndex(0); //default status is
activeathleteStatusComboBox.setMaximumRowCount(3);
athleteStatusComboBox.addActionListener(this);
matchList = new List( 10 );
findAthleteButton = new JButton( "Find Athlete" );getRecordButton = new JButton( "Get Record" );cancelButton = new JButton( "Cancel" );
constraints.fill = GridBagConstraints.HORIZONTAL;addComponent( athleteIDlabel, 0, 0, 1, 1);
addComponent( athleteIDfield, 0, 1, 1, 1);addComponent( athleteLastNameLabel, 3, 0, 1, 1);addComponent( athleteLastNameField, 3, 1, 1, 1);addComponent( athleteFirstNameLabel, 3, 2, 1, 1);addComponent( athleteFirstNameField, 3, 3, 1, 1);addComponent( athleteMILabel, 3, 4, 1, 1);addComponent( athleteMIField, 3, 5, 1, 1);addComponent( athleteSearchbyStatusLabel, 5, 0, 1, 1);addComponent( athleteStatusComboBox, 7, 0, 1, 1);addComponent( space, 8, 0, 1, 1);addComponent( athleteMatchLabel, 9, 0, 1, 1);addComponent( space1, 10, 0, 1, 1);addComponent( new JScrollPane( matchList ), 11, 0, 10, 20);addComponent( space2, 31, 0, 1, 1);
constraints.fill = GridBagConstraints.SOUTH;addComponent( findAthleteButton, 32, 1, 1, 1 );addComponent( getRecordButton, 32, 2, 1, 1 );addComponent( cancelButton, 32, 3, 1, 1 );
findAthleteButton.setActionCommand(FIND);getRecordButton.setActionCommand(SELECT);cancelButton.setActionCommand(CANCEL);
athleteIDfield.addActionListener(this);athleteLastNameField.addActionListener(this);
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
18
-
7/31/2019 MELJUN CORTES Documentation
19/42
athleteFirstNameField.addActionListener(this);athleteMIField.addActionListener(this);athleteStatusComboBox.addActionListener(this);findAthleteButton.addActionListener(this);getRecordButton.addActionListener(this);cancelButton.addActionListener(this);
matchList.addActionListener(this);
athleteIDfield.setActionCommand(FIND);athleteLastNameField.setActionCommand(FIND);athleteFirstNameField.setActionCommand(FIND);athleteMIField.setActionCommand(FIND);athleteStatusComboBox.setActionCommand(FIND);
setSize( 500, 375 );setVisible( true );
}
private void addComponent( Component component,int row, int column, int width, int height )
{constraints.gridx = column;constraints.gridy = row;constraints.gridwidth = width;constraints.gridheight = height;
layout.setConstraints(component, constraints );container.add( component );
}
public void actionPerformed(ActionEvent e) {String cmd = e.getActionCommand();
if (CANCEL.equals(cmd)){System.exit(0);
}
if (FIND.equals(cmd)){
String id = athleteIDfield.getText();String lastName = athleteLastNameField.getText();String firstName = athleteFirstNameField.getText();String mi = athleteMIField.getText();
//initialize listint listContent = matchList.getItemCount();matchList.removeAll();
//for retrieving queriestry {
//Error checkif (id.equals("")&& lastName.equals("") &&
firstName.equals("") && mi.equals("")){
//By default, use athlete status selectionString status =
(String)athleteStatusComboBox.getSelectedItem();
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
19
-
7/31/2019 MELJUN CORTES Documentation
20/42
Statement statement = connection.createStatement();String query = "SELECT athleteID, athleteLastName,
athleteFirstName, athleteMI "+ "FROM athlete " + "WHERE athleteStatus = '"
+ status + "'";ResultSet rs = statement.executeQuery( query );
get( rs );statement.close();
}
//single parameter searches//search by id number
if ( !id.equals( "" ) && lastName.equals("") &&firstName.equals("") && mi.equals("")) {
Statement statement =connection.createStatement();String query = "SELECT athleteID, athleteLastName,
athleteFirstName, athleteMI "+ "FROM athlete " + "WHERE
athleteID = '" + id + "'";ResultSet rs = statement.executeQuery( query );
get( rs );statement.close();}
//search by last nameif ( !lastName.equals( "" ) && id.equals("") &&
firstName.equals("") && mi.equals("")) {Statement statement =connection.createStatement();
String query = "SELECT athleteID, athleteLastName,athleteFirstName, athleteMI "
+ "FROM athlete " + "WHEREathleteLastName = '" + lastName + "'";
ResultSet rs = statement.executeQuery( query );//System.out.println(query + "\n");
get( rs );statement.close();}
//search by first nameif ( !firstName.equals( "" ) && id.equals("") &&
lastName.equals("") && mi.equals("")) {Statement statement =connection.createStatement();
String query = "SELECT athleteID, athleteLastName,athleteFirstName, athleteMI "
+ "FROM athlete " + "WHEREathleteFirstName = '" + firstName + "'";
ResultSet rs = statement.executeQuery( query );
get( rs );statement.close();}
//search by mi; included though a very unlikely searchparameter
if ( !mi.equals( "" ) && id.equals("") &&lastName.equals("") && firstName.equals("")) {
Statement statement =connection.createStatement();String query = "SELECT athleteID, athleteLastName,
athleteFirstName, athleteMI "
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
20
-
7/31/2019 MELJUN CORTES Documentation
21/42
+ "FROM athlete " + "WHEREathleteMI = '" + mi + "'";
ResultSet rs = statement.executeQuery( query );
get( rs );statement.close();}
//multiple parameter searches//athleteID + last nameif ( !id.equals( "" ) && !lastName.equals("") &&
firstName.equals("") && mi.equals("")) {Statement statement =connection.createStatement();
String query = "SELECT athleteID, athleteLastName,athleteFirstName, athleteMI "
+ "FROM athlete " + "WHEREathleteID = '" + id + "' "
+ "AND athleteLastName = '" +lastName + "'";
ResultSet rs = statement.executeQuery( query );
get( rs );statement.close();}
//last name + first nameif ( !lastName.equals( "" ) && !firstName.equals("") &&
id.equals("") && mi.equals("")) {Statement statement =connection.createStatement();
String query = "SELECT athleteID, athleteLastName,athleteFirstName, athleteMI "
+ "FROM athlete " + "WHEREathleteLastName = '" + lastName + "' "
+ "AND athleteFirstName = '" +firstName + "'";
ResultSet rs = statement.executeQuery( query );
get( rs );statement.close();
}
//athleteID + last name + first nameif ( !lastName.equals( "" ) && !firstName.equals("") &&
!id.equals("") && mi.equals("")) {Statement statement =connection.createStatement();
String query = "SELECT athleteID, athleteLastName,athleteFirstName, athleteMI "
+ "FROM athlete " + "WHEREathleteLastName = '" + lastName + "' "
+ "AND athleteFirstName = '" +firstName + "'" + "AND athleteID = '"
+ id + "'";ResultSet rs = statement.executeQuery( query );
get( rs );statement.close();}
//last name + first name + miif ( !lastName.equals( "" ) && !firstName.equals("") &&
id.equals("") && !mi.equals("")) {Statement statement =connection.createStatement();
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
21
-
7/31/2019 MELJUN CORTES Documentation
22/42
String query = "SELECT athleteID, athleteLastName,athleteFirstName, athleteMI "
+ "FROM athlete " + "WHEREathleteLastName = '" + lastName + "' "
+ "AND athleteFirstName = '" +firstName + "'"
+ "AND athleteMI = '" + mi + "'";ResultSet rs = statement.executeQuery( query );
get( rs );statement.close();}
//all search parameters, except statusif ( !lastName.equals( "" ) && !firstName.equals("") &&
!id.equals("") && !mi.equals("")) {Statement statement =connection.createStatement();
String query = "SELECT athleteID, athleteLastName,athleteFirstName, athleteMI " +
"FROM athlete " + "WHEREathleteLastName = '" + lastName + "' "
+ "AND athleteFirstName = '" +firstName + "'"
+ "AND athleteMI = '" + mi + "'"+ "AND athleteID = '" + id + "'";
ResultSet rs = statement.executeQuery( query );
get( rs );statement.close();}
}
catch ( SQLException sqlex ) {sqlex.printStackTrace();
}
}
//Retrieve recordif (SELECT.equals(cmd)){
String retrieveRecord = matchList.getSelectedItem();//System.out.println("retrieveRecord: " + retrieveRecord);if (retrieveRecord != null){
//test; record should be based on name, which has tobe
//tokenized...StringTokenizer st = new StringTokenizer(
retrieveRecord );
if ( st.hasMoreTokens()){//just get athlete id, which is always the
first argument,//and which is the primary keyString aid = st.nextToken();
//get all information to populate new recordtry {
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
22
-
7/31/2019 MELJUN CORTES Documentation
23/42
-
7/31/2019 MELJUN CORTES Documentation
24/42
String athleteLastName = rs.getString( 2 );String athleteFirstName = rs.getString( 3 );String athleteMI = rs.getString( 4 );int counter = 1;
/*inclusion of athleteID in result string would be forcases, however unlikely,
that two members will have the same name, up to the middleinitial. The athleteID
will also be used for parsing*/
String name = athleteID + " " + athleteLastName +", " + athleteFirstName + " "
+ athleteMI;
//populate match listmatchList.add(name, counter);counter++;} while ( rs.next() );
}}
catch ( SQLException sqlex ) {sqlex.printStackTrace();
}}//end get
public static void getRecord( ResultSet rs, ResultSet rs1 ) throws SQLException{
try {//get record contents
rs.next();rs1.next();
String aid = rs.getString( 1 );String aln = rs.getString( 2 );
String afn = rs.getString( 3 );String ami = rs.getString( 4 );String asa = rs.getString( 5 );String aca = rs.getString( 6 );String azc = rs.getString( 7 );String acn = rs.getString( 8 ); //contact numberString abd = rs.getString( 9 );String agd = rs.getString( 10 );//genderString aps = rs.getString( 11 );String ass = rs.getString( 12 );String ast = rs.getString( 13 ); //status
String gln = rs1.getString( 1 );String gfn = rs1.getString( 2 );String gmi = rs1.getString( 3 );
String gsa = rs1.getString( 4 );String gca = rs1.getString( 5 );String gzc = rs1.getString( 6 );String gpn = rs1.getString( 7 );
//transfer to getRecord methodRecord record = new Record();
//populate record with retrieved resultsrecord.athleteIDfield.setText(aid);record.athleteLastNameField.setText(aln);
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
24
-
7/31/2019 MELJUN CORTES Documentation
25/42
record.athleteFirstNameField.setText(afn);record.athleteMIField.setText(ami);record.streetAddressField.setText(asa);record.cityField.setText(aca);record.zipCodeField.setText(azc);record.phoneNumberField.setText(acn);record.primarySportField.setText(aps);record.secondarySportField.setText(ass);record.birthdayField.setText(abd);
//fill in guardian detailsrecord.guardianLastNameField.setText(gln);record.guardianFirstNameField.setText(gfn);record.guardianMIField.setText(gmi);record.gStreetAddressField.setText(gsa);record.gCityField.setText(gca);record.gZipCodeField.setText(gzc);record.gPhoneNumberField.setText(gpn);
//set gender radio buttonif (agd.equals("M")){
record.mButton.setSelected( true );} else {
record.fButton.setSelected( true );}
//set statusif (ast.equals("Active")){
record.athleteStatusComboBox.setSelectedIndex(0);}
if (ast.equals("Injured")){record.athleteStatusComboBox.setSelectedIndex(1);
}
if (ast.equals("Unavailable")){
record.athleteStatusComboBox.setSelectedIndex(2);}
if (ast.equals("Suspended")){record.athleteStatusComboBox.setSelectedIndex(3);
}
if (ast.equals("Blacklisted")){record.athleteStatusComboBox.setSelectedIndex(4);
}
if (ast.equals("Inactive")){record.athleteStatusComboBox.setSelectedIndex(5);
}
if (ast.equals("Graduated")){record.athleteStatusComboBox.setSelectedIndex(5);}
}catch ( SQLException sqlex ) {sqlex.printStackTrace();
}}//end getRecord
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
25
-
7/31/2019 MELJUN CORTES Documentation
26/42
public static void main(String[] args){
FindRecord application = new FindRecord();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
/*FindRecord.javaWritten by Maria Pamela C. Davidin partial fulfillment of the requirementsin CS192*/
Athlete Record
package angBulilitLiga;
import java.sql.*;
import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;
public class Record extends JFrame implements ActionListener{
private Connection connection;
private static String OK = "okay";private static String EDIT = "edit";private static String SAVE = "save";
private Container container;
private GridBagLayout layout;private GridBagConstraints constraints;
public JTextField athleteIDfield, athleteLastNameField,athleteFirstNameField, athleteMIField,
streetAddressField, cityField, provinceField, zipCodeField,phoneNumberField, primarySportField,
secondarySportField;public JTextField guardianLastNameField, guardianFirstNameField,
guardianMIField,gStreetAddressField, gCityField, gProvinceField, gZipCodeField,
gPhoneNumberField,birthdayField;
private JLabel athleteIDlabel, athleteLastNameLabel,athleteFirstNameLabel, athleteMILabel,
streetAddressLabel, cityLabel, provinceLabel, zipCodeLabel,phoneNumberLabel, genderLabel,
primarySportLabel, secondarySportLabel, statusLabel,birthdayLabel;
private JLabel guardianLabel, guardianLastNameLabel,guardianFirstNameLabel, guardianMILabel,
gStreetAddressLabel, gCityLabel, gProvinceLabel, gZipCodeLabel,gPhoneNumberLabel;
private JLabel space, space1, space2;private JButton okayButton, editButton, saveButton;public JRadioButton mButton, fButton;
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
26
-
7/31/2019 MELJUN CORTES Documentation
27/42
private ButtonGroup radioGroup;public JComboBox athleteStatusComboBox;private String athleteStatus[] = {"Active", "Injured", "Unavailable",
"Suspended", "Blacklisted","Inactive", "Graduated"};
public static String gender;
public Record(){
super( "Record" );
String url = "jdbc:odbc:angbulilitliga";String username = "root";String password = "password";
try{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );connection = DriverManager.getConnection(
url, username, password );}catch ( ClassNotFoundException cnfex ){
System.err.println( "Failed to load JDBC/ODBC driver." );cnfex.printStackTrace();System.exit(1);
}
catch (SQLException sqlex ) {System.err.println( "Unable to connect" );sqlex.printStackTrace();
}
container = getContentPane();layout = new GridBagLayout();
container.setLayout( layout );
constraints = new GridBagConstraints();
athleteIDlabel = new JLabel( "Athlete ID ");athleteLastNameLabel = new JLabel("Last Name ");athleteFirstNameLabel = new JLabel("First Name ");athleteMILabel = new JLabel("MI ");genderLabel = new JLabel("Sex ");primarySportLabel = new JLabel("Primary Sport ");secondarySportLabel = new JLabel("Secondary Sport ");statusLabel = new JLabel("Status ");
streetAddressLabel = new JLabel("Street Address ");cityLabel = new JLabel("City ");
provinceLabel = new JLabel("Province ");zipCodeLabel = new JLabel("Zip Code ");phoneNumberLabel = new JLabel("Telephone number ");
gStreetAddressLabel = new JLabel("Street Address ");gCityLabel = new JLabel("City ");gProvinceLabel = new JLabel("Province ");gZipCodeLabel = new JLabel("Zip Code ");gPhoneNumberLabel = new JLabel("Telephone number ");
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
27
-
7/31/2019 MELJUN CORTES Documentation
28/42
birthdayLabel = new JLabel("Date of birth ");
guardianLabel = new JLabel("Guardian Information");space = new JLabel(" ");space1 = new JLabel(" ");space2 = new JLabel(" ");guardianLastNameLabel = new JLabel("Last Name ");guardianFirstNameLabel = new JLabel("First Name" );guardianMILabel = new JLabel("MI ");
athleteIDfield = new JTextField( "2005-11143" );athleteLastNameField = new JTextField( "Santos" );athleteFirstNameField = new JTextField( "Rogelio" );athleteMIField = new JTextField( "D" );streetAddressField = new JTextField( "270 Commonwealth Avenue");cityField = new JTextField( "Quezon City " );zipCodeField = new JTextField( "1109" );phoneNumberField = new JTextField( "9513990" );primarySportField = new JTextField( "Basketball" );secondarySportField = new JTextField( " " );birthdayField = new JTextField( "01/12/1993");
athleteIDfield.setEditable(false);athleteLastNameField.setEditable(false);athleteFirstNameField.setEditable(false);athleteMIField.setEditable(false);streetAddressField.setEditable(false);cityField.setEditable(false);zipCodeField.setEditable(false);phoneNumberField.setEditable(false);primarySportField.setEditable(false);secondarySportField.setEditable(false);birthdayField.setEditable(false);
athleteIDfield.addActionListener(this);
athleteLastNameField.addActionListener(this);athleteFirstNameField.addActionListener(this);athleteMIField.addActionListener(this);streetAddressField.addActionListener(this);cityField.addActionListener(this);zipCodeField.addActionListener(this);phoneNumberField.addActionListener(this);primarySportField.addActionListener(this);secondarySportField.addActionListener(this);birthdayField.addActionListener(this);
guardianLastNameField = new JTextField( "Santos ");guardianFirstNameField = new JTextField( "Romeo ");guardianMIField = new JTextField( "C ");
gStreetAddressField = new JTextField( "270 Commonwealth Avenue");gCityField = new JTextField( "Quezon City " );gZipCodeField = new JTextField( "1109" );gPhoneNumberField = new JTextField( "9513990" );
guardianLastNameField.setEditable(false);guardianFirstNameField.setEditable(false);guardianMIField.setEditable(false);gStreetAddressField.setEditable(false);gCityField.setEditable(false);gZipCodeField.setEditable(false);
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
28
-
7/31/2019 MELJUN CORTES Documentation
29/42
gPhoneNumberField.setEditable(false);
guardianLastNameField.setEditable(false);guardianFirstNameField.setEditable(false);guardianMIField.setEditable(false);gStreetAddressField.setEditable(false);gCityField.setEditable(false);gZipCodeField.setEditable(false);gPhoneNumberField.setEditable(false);
guardianLastNameField.addActionListener(this);guardianFirstNameField.addActionListener(this);guardianMIField.addActionListener(this);gStreetAddressField.addActionListener(this);gCityField.addActionListener(this);gZipCodeField.addActionListener(this);gPhoneNumberField.addActionListener(this);
athleteIDfield.setActionCommand(SAVE);athleteLastNameField.setActionCommand(SAVE);athleteFirstNameField.setActionCommand(SAVE);athleteMIField.setActionCommand(SAVE);streetAddressField.setActionCommand(SAVE);cityField.setActionCommand(SAVE);zipCodeField.setActionCommand(SAVE);phoneNumberField.setActionCommand(SAVE);primarySportField.setActionCommand(SAVE);secondarySportField.setActionCommand(SAVE);birthdayField.setActionCommand(SAVE);guardianLastNameField.setActionCommand(SAVE);guardianFirstNameField.setActionCommand(SAVE);guardianMIField.setActionCommand(SAVE);gStreetAddressField.setActionCommand(SAVE);gCityField.setActionCommand(SAVE);gZipCodeField.setActionCommand(SAVE);
gPhoneNumberField.setActionCommand(SAVE);
//no selected gendermButton = new JRadioButton( "M", false );fButton = new JRadioButton( "F", false );
//create logical relationships between buttons//these will be non-editableradioGroup = new ButtonGroup();radioGroup.add( mButton );radioGroup.add( fButton );
athleteStatusComboBox = new JComboBox( athleteStatus );
okayButton = new JButton( "OK" );
editButton = new JButton( "Edit" );saveButton = new JButton( "Save" );
//constraints.fill = GridBagConstraints.BOTH;
constraints.fill = GridBagConstraints.HORIZONTAL;addComponent( athleteIDlabel, 0, 0, 1, 1);addComponent( athleteIDfield, 0, 1, 1, 1);addComponent( athleteLastNameLabel, 3, 0, 1, 1);addComponent( athleteLastNameField, 3, 1, 1, 1);
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
29
-
7/31/2019 MELJUN CORTES Documentation
30/42
addComponent( athleteFirstNameLabel, 3, 2, 1, 1);addComponent( athleteFirstNameField, 3, 3, 1, 1);addComponent( athleteMILabel, 3, 4, 1, 1);addComponent( athleteMIField, 3, 5, 1, 1);addComponent( genderLabel, 4, 0, 1, 1);addComponent( mButton, 4, 1, 1, 1 );addComponent( fButton, 4, 2, 1, 1 );addComponent( streetAddressLabel, 5, 0, 1, 1);addComponent( streetAddressField, 5, 1, 1, 1);addComponent( cityLabel, 5, 2, 1, 1);addComponent( cityField, 5, 3, 1, 1);addComponent( zipCodeLabel, 7, 0, 1, 1);addComponent( zipCodeField, 7, 1, 1, 1);addComponent( phoneNumberLabel, 8, 0, 1, 1);addComponent( phoneNumberField, 8, 1, 1, 1);addComponent( birthdayLabel, 9, 0, 1, 1);addComponent( birthdayField, 9, 1, 1, 1);addComponent( primarySportLabel, 10, 0, 1, 1);addComponent( primarySportField, 10, 1, 1, 1);addComponent( secondarySportLabel, 11, 0, 1, 1);addComponent( secondarySportField, 11, 1, 1, 1);addComponent( statusLabel, 12, 0, 1, 1);addComponent( athleteStatusComboBox, 12, 1, 1, 1);addComponent( space, 13, 0, 1, 1);
//Start hereJPanel guardianPane = new JPanel();GridBagLayout gridbag = new GridBagLayout();GridBagConstraints c = new GridBagConstraints();
guardianPane.setLayout(gridbag);addComponent( guardianLabel, 14, 0, 1, 1);addComponent( space1, 15, 0, 1, 1);addComponent( guardianLastNameLabel, 16, 0, 1, 1);addComponent( guardianLastNameField, 16, 1, 1, 1);addComponent( guardianFirstNameLabel, 16, 2, 1, 1);addComponent( guardianFirstNameField, 16, 3, 1, 1);
addComponent( guardianMILabel, 16, 4, 1, 1);addComponent( guardianMIField, 16, 5, 1, 1);addComponent( gStreetAddressLabel, 17, 0, 1, 1);addComponent( gStreetAddressField, 17, 1, 1, 1);addComponent( gCityLabel, 17, 2, 1, 1);addComponent( gCityField, 17, 3, 1, 1);//add province later!addComponent( gZipCodeLabel, 18, 0, 1, 1);addComponent( gZipCodeField, 18, 1, 1, 1);addComponent( gPhoneNumberLabel, 19, 0, 1, 1);addComponent( gPhoneNumberField, 19, 1, 1, 1);addComponent( space2, 20, 1, 1, 1);c.gridwidth = GridBagConstraints.REMAINDER; //last
c.anchor = GridBagConstraints.SOUTH;c.weightx = 1.0;
guardianPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Guardian"),BorderFactory.createEmptyBorder(5,5,5,5)));
//end here
constraints.fill = GridBagConstraints.SOUTH;addComponent( okayButton, 31, 1, 1, 1 );addComponent( editButton, 31, 2, 1, 1 );addComponent( saveButton, 31, 3, 1, 1 );
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
30
-
7/31/2019 MELJUN CORTES Documentation
31/42
okayButton.addActionListener(this);editButton.addActionListener(this);saveButton.addActionListener(this);saveButton.setEnabled(false);
okayButton.setActionCommand(OK);editButton.setActionCommand(EDIT);saveButton.setActionCommand(SAVE);
setSize( 500, 450 );setVisible( true );
}
private void addComponent( Component component,int row, int column, int width, int height )
{constraints.gridx = column;constraints.gridy = row;constraints.gridwidth = width;constraints.gridheight = height;
layout.setConstraints(component, constraints );container.add( component );
}
public void actionPerformed(ActionEvent e) {String cmd = e.getActionCommand();
String id = athleteIDfield.getText();String lastName = athleteLastNameField.getText();String firstName = athleteFirstNameField.getText();String mi = athleteMIField.getText();String asa = streetAddressField.getText();
String aca = cityField.getText();String azc = zipCodeField.getText();String apn = phoneNumberField.getText();String psf = primarySportField.getText();String ssf = secondarySportField.getText();String bday = birthdayField.getText();String gln = guardianLastNameField.getText();String gfn = guardianFirstNameField.getText();String gmi = guardianMIField.getText();String gsa = gStreetAddressField.getText();String gca = gCityField.getText();String gzc = gZipCodeField.getText();String gpn = gPhoneNumberField.getText();
//get athlete status from combo box
String status = (String)athleteStatusComboBox.getSelectedItem();
if (OK.equals(cmd)){
System.exit(1);}
else if (EDIT.equals(cmd)){
/*change status of fields to editable, except
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
31
-
7/31/2019 MELJUN CORTES Documentation
32/42
for the athleteIDField, which would remainuneditable*/athleteLastNameField.setEditable(true);athleteFirstNameField.setEditable(true);athleteMIField.setEditable(true);streetAddressField.setEditable(true);cityField.setEditable(true);zipCodeField.setEditable(true);phoneNumberField.setEditable(true);primarySportField.setEditable(true);secondarySportField.setEditable(true);birthdayField.setEditable(true);
guardianLastNameField.setEditable(true);guardianFirstNameField.setEditable(true);guardianMIField.setEditable(true);gStreetAddressField.setEditable(true);gCityField.setEditable(true);gZipCodeField.setEditable(true);gPhoneNumberField.setEditable(true);
saveButton.setEnabled(true);
}
if (SAVE.equals(cmd)){
//Check completeness of records firstif
(id.equals("")||lastName.equals("")||firstName.equals("")||
mi.equals("")||asa.equals("")||aca.equals("")||azc.equals("")||
apn.equals("")||psf.equals("")||bday.equals("")||gln.equals("")||
gfn.equals("")||gmi.equals("")||gsa.equals("")||gsa.equals("")||
gca.equals("")||gzc.equals("")||gpn.equals("")){
JOptionPane.showMessageDialog(null, "One ormore of the required fields\n" +
"have been left blank! Please recheckentries.",
"Error", JOptionPane.ERROR_MESSAGE);}
else {JOptionPane.showMessageDialog(null, "Save changes to
record?","Save Record Confirmation",
JOptionPane.QUESTION_MESSAGE);
try{
Statement statement =connection.createStatement();
//insertion without specification oftarget columns --
//it is imperative that the insertionformat is correct!
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
32
-
7/31/2019 MELJUN CORTES Documentation
33/42
//value for gender is obtained in aseparate method.
String query = "UPDATE athlete SETathleteLastName = '" +
lastName + "', athleteFirstName ='" + firstName +
"', athleteMI = '" + mi + "',athleteStreetAddress = '" + asa +
"', athleteCityAddress = '" + aca+ "', ZipCode = '" + azc +
"', athleteContactNo = '" + apn +"', athleteBirthDate = '" + bday +
"', athletePrimarySport = '" +psf +
"', athleteSecondarySport = '" +ssf + "', athleteStatus = '"
+ status + "' WHERE athleteID ='" + id + "'";
//for update of guardian recordsString query1 = "UPDATE guardian SET
guardianLastName = '" +gln + "', guardianFirstName = '"
+ gfn + "', guardianMI = '"+ gmi + "', guardianStreetAddress
= '" + gsa+ "', guardianCityAddress = '" +
gca + "', guardianZipCode = '"+ gzc + "', guardianContactNo =
'" + gpn + "' WHERE "+ "guardianID = '" + id + "g'";
int result = statement.executeUpdate( query );int result1 = statement.executeUpdate(
query1 );
if ( result == 1 || result1 == 1){
JOptionPane.showMessageDialog(null,"Record updated!");
//revert to read-only again
athleteLastNameField.setEditable(false);
athleteFirstNameField.setEditable(false);
athleteMIField.setEditable(false);
streetAddressField.setEditable(false);
cityField.setEditable(false);zipCodeField.setEditable(false);
phoneNumberField.setEditable(false);
primarySportField.setEditable(false);
secondarySportField.setEditable(false);birthdayField.setEditable(false);
guardianLastNameField.setEditable(false);
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
33
-
7/31/2019 MELJUN CORTES Documentation
34/42
guardianFirstNameField.setEditable(false);
guardianMIField.setEditable(false);
gStreetAddressField.setEditable(false);gCityField.setEditable(false);gZipCodeField.setEditable(false);
gPhoneNumberField.setEditable(false);
statement.close();
} else {
JOptionPane.showMessageDialog(null, "No changes were made.");}
}
catch ( SQLException sqlex ) {sqlex.printStackTrace();
}
}}
}
public static void main(String[] args){
Record application = new Record();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
/*Record.javaWritten by Maria Pamela C. Davidin partial fulfillment of the requirementsin CS192*/
Athlete Record Addition Facility
package angBulilitLiga;
import java.sql.*;
import java.awt.*;import java.awt.event.*;import javax.swing.*;
public class AddAthlete extends JFrame implements ActionListener{
private Connection connection;
private static String CANCEL = "cancel";private static String SAVE = "save";
private Container container;private GridBagLayout layout;private GridBagConstraints constraints;
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
34
-
7/31/2019 MELJUN CORTES Documentation
35/42
-
7/31/2019 MELJUN CORTES Documentation
36/42
constraints = new GridBagConstraints();
athleteIDlabel = new JLabel( "Athlete ID ");athleteLastNameLabel = new JLabel("Last Name ");athleteFirstNameLabel = new JLabel("First Name ");athleteMILabel = new JLabel("MI ");genderLabel = new JLabel("Sex ");primarySportLabel = new JLabel("Primary Sport ");secondarySportLabel = new JLabel("Secondary Sport ");statusLabel = new JLabel("Status ");
streetAddressLabel = new JLabel("Street Address ");cityLabel = new JLabel("City ");provinceLabel = new JLabel("Province ");zipCodeLabel = new JLabel("Zip Code ");phoneNumberLabel = new JLabel("Telephone number ");
gStreetAddressLabel = new JLabel("Street Address ");gCityLabel = new JLabel("City ");gProvinceLabel = new JLabel("Province ");gZipCodeLabel = new JLabel("Zip Code ");gPhoneNumberLabel = new JLabel("Telephone number ");
birthdayLabel = new JLabel("Date of birth ");
guardianLabel = new JLabel("Guardian Information");space = new JLabel(" ");space1 = new JLabel(" ");space2 = new JLabel(" ");guardianLastNameLabel = new JLabel("Last Name ");guardianFirstNameLabel = new JLabel("First Name" );guardianMILabel = new JLabel("MI ");
athleteIDfield = new JTextField( 5 );athleteLastNameField = new JTextField( 10 );
athleteFirstNameField = new JTextField( 10 );athleteMIField = new JTextField( 1 );streetAddressField = new JTextField( 10);cityField = new JTextField( 5 );zipCodeField = new JTextField( 5 );phoneNumberField = new JTextField( 10 );primarySportField = new JTextField( 10 );secondarySportField = new JTextField( 10 );birthdayField = new JTextField( 5 );
athleteIDfield.addActionListener(this);athleteLastNameField.addActionListener(this);athleteFirstNameField.addActionListener(this);athleteMIField.addActionListener(this);streetAddressField.addActionListener(this);
cityField.addActionListener(this);zipCodeField.addActionListener(this);phoneNumberField.addActionListener(this);primarySportField.addActionListener(this);secondarySportField.addActionListener(this);birthdayField.addActionListener(this);
guardianLastNameField = new JTextField( 10 );guardianFirstNameField = new JTextField( 10 );guardianMIField = new JTextField( 1 );gStreetAddressField = new JTextField( 10 );
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
36
-
7/31/2019 MELJUN CORTES Documentation
37/42
gCityField = new JTextField( 5 );gZipCodeField = new JTextField( 5 );gPhoneNumberField = new JTextField( 10 );
guardianLastNameField.addActionListener(this);guardianFirstNameField.addActionListener(this);guardianMIField.addActionListener(this);gStreetAddressField.addActionListener(this);gCityField.addActionListener(this);gZipCodeField.addActionListener(this);gPhoneNumberField.addActionListener(this);
athleteIDfield.setActionCommand(SAVE);athleteLastNameField.setActionCommand(SAVE);athleteFirstNameField.setActionCommand(SAVE);athleteMIField.setActionCommand(SAVE);streetAddressField.setActionCommand(SAVE);cityField.setActionCommand(SAVE);zipCodeField.setActionCommand(SAVE);phoneNumberField.setActionCommand(SAVE);primarySportField.setActionCommand(SAVE);secondarySportField.setActionCommand(SAVE);birthdayField.setActionCommand(SAVE);guardianLastNameField.setActionCommand(SAVE);guardianFirstNameField.setActionCommand(SAVE);guardianMIField.setActionCommand(SAVE);gStreetAddressField.setActionCommand(SAVE);gCityField.setActionCommand(SAVE);gZipCodeField.setActionCommand(SAVE);gPhoneNumberField.setActionCommand(SAVE);
mButton = new JRadioButton( "M", true ); //set as defaultfButton = new JRadioButton( "F", false );
//create logical relationships between buttons
radioGroup = new ButtonGroup();radioGroup.add( mButton );radioGroup.add( fButton );
//event handler for buttonsRadioButtonHandler handler = new RadioButtonHandler();mButton.addItemListener( handler );fButton.addItemListener( handler );
athleteStatusComboBox = new JComboBox( athleteStatus );
saveButton = new JButton( "Save" );cancelButton = new JButton( "Cancel" );
cancelButton.addActionListener(this);saveButton.addActionListener(this);
cancelButton.setActionCommand(CANCEL);saveButton.setActionCommand(SAVE);
constraints.fill = GridBagConstraints.HORIZONTAL;addComponent( athleteIDlabel, 0, 0, 1, 1);addComponent( athleteIDfield, 0, 1, 1, 1);addComponent( athleteLastNameLabel, 3, 0, 1, 1);
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
37
-
7/31/2019 MELJUN CORTES Documentation
38/42
addComponent( athleteLastNameField, 3, 1, 1, 1);addComponent( athleteFirstNameLabel, 3, 2, 1, 1);addComponent( athleteFirstNameField, 3, 3, 1, 1);addComponent( athleteMILabel, 3, 4, 1, 1);addComponent( athleteMIField, 3, 5, 1, 1);addComponent( genderLabel, 4, 0, 1, 1);addComponent( mButton, 4, 1, 1, 1 );addComponent( fButton, 4, 2, 1, 1 );addComponent( streetAddressLabel, 5, 0, 1, 1);addComponent( streetAddressField, 5, 1, 1, 1);addComponent( cityLabel, 5, 2, 1, 1);addComponent( cityField, 5, 3, 1, 1);addComponent( zipCodeLabel, 7, 0, 1, 1);addComponent( zipCodeField, 7, 1, 1, 1);addComponent( phoneNumberLabel, 8, 0, 1, 1);addComponent( phoneNumberField, 8, 1, 1, 1);addComponent( birthdayLabel, 9, 0, 1, 1);addComponent( birthdayField, 9, 1, 1, 1);addComponent( primarySportLabel, 10, 0, 1, 1);addComponent( primarySportField, 10, 1, 1, 1);addComponent( secondarySportLabel, 11, 0, 1, 1);addComponent( secondarySportField, 11, 1, 1, 1);addComponent( statusLabel, 12, 0, 1, 1);addComponent( athleteStatusComboBox, 12, 1, 1, 1);addComponent( space, 13, 0, 1, 1);
//Start hereJPanel guardianPane = new JPanel();GridBagLayout gridbag = new GridBagLayout();GridBagConstraints c = new GridBagConstraints();
guardianPane.setLayout(gridbag);addComponent( guardianLabel, 14, 0, 1, 1);addComponent( space1, 15, 0, 1, 1);addComponent( guardianLastNameLabel, 16, 0, 1, 1);addComponent( guardianLastNameField, 16, 1, 1, 1);addComponent( guardianFirstNameLabel, 16, 2, 1, 1);
addComponent( guardianFirstNameField, 16, 3, 1, 1);addComponent( guardianMILabel, 16, 4, 1, 1);addComponent( guardianMIField, 16, 5, 1, 1);addComponent( gStreetAddressLabel, 17, 0, 1, 1);addComponent( gStreetAddressField, 17, 1, 1, 1);addComponent( gCityLabel, 17, 2, 1, 1);addComponent( gCityField, 17, 3, 1, 1);addComponent( gZipCodeLabel, 18, 0, 1, 1);addComponent( gZipCodeField, 18, 1, 1, 1);addComponent( gPhoneNumberLabel, 19, 0, 1, 1);addComponent( gPhoneNumberField, 19, 1, 1, 1);addComponent( space2, 20, 1, 1, 1);c.gridwidth = GridBagConstraints.REMAINDER; //last
c.anchor = GridBagConstraints.SOUTH;c.weightx = 1.0;
guardianPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Guardian"),BorderFactory.createEmptyBorder(5,5,5,5)));
//end here
constraints.fill = GridBagConstraints.SOUTH;addComponent( saveButton, 31, 1, 1, 1 );addComponent( cancelButton, 31, 2, 1, 1 );
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
38
-
7/31/2019 MELJUN CORTES Documentation
39/42
setSize( 500, 450 );setVisible( true );
}
private void addComponent( Component component,int row, int column, int width, int height )
{constraints.gridx = column;constraints.gridy = row;constraints.gridwidth = width;constraints.gridheight = height;
layout.setConstraints(component, constraints );container.add( component );
}
public void actionPerformed(ActionEvent e) {String cmd = e.getActionCommand();
String id = athleteIDfield.getText();String lastName = athleteLastNameField.getText();String firstName = athleteFirstNameField.getText();String mi = athleteMIField.getText();String asa = streetAddressField.getText();String aca = cityField.getText();String azc = zipCodeField.getText();String apn = phoneNumberField.getText();String psf = primarySportField.getText();String ssf = secondarySportField.getText();String bday = birthdayField.getText();String gln = guardianLastNameField.getText();String gfn = guardianFirstNameField.getText();String gmi = guardianMIField.getText();String gsa = gStreetAddressField.getText();String gca = gCityField.getText();
String gzc = gZipCodeField.getText();String gpn = gPhoneNumberField.getText();
//get athlete status from combo boxString status = (String)athleteStatusComboBox.getSelectedItem();String gender = "";if (e.getSource() == mButton )
{//set gendergender = "M";
}if (e.getSource() == fButton){
//set gendergender = "F";
}
if (CANCEL.equals(cmd)){
System.exit(0);}
else if (SAVE.equals(cmd)){
//Check completeness of records first
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
39
-
7/31/2019 MELJUN CORTES Documentation
40/42
if(id.equals("")||lastName.equals("")||firstName.equals("")||
mi.equals("")||asa.equals("")||aca.equals("")||azc.equals("")||
apn.equals("")||psf.equals("")||bday.equals("")||gln.equals("")||
gfn.equals("")||gmi.equals("")||gsa.equals("")||gsa.equals("")||
gca.equals("")||gzc.equals("")||gpn.equals("")){
JOptionPane.showMessageDialog(null, "One ormore of the required fields\n" +
"have been left blank! Please recheckentries.",
"Error", JOptionPane.ERROR_MESSAGE);}
else {JOptionPane.showMessageDialog(null, "Save changes to
record?","Save Record Confirmation",
JOptionPane.QUESTION_MESSAGE);
try{
Statement statement =connection.createStatement();
//insertion without specification oftarget columns --
//it is imperative that the insertionformat is correct!
//value for gender is obtained in aseparate method.
String query = "INSERT into athleteVALUES ('" +
id + "', '" + lastName + "', '" +
firstName + "', '" + mi + "', '" + asa + "','" + aca +
"', '" + azc + "', '" + apn + "','" + bday +
"', '" + gender + "', '" + psf +"', '" + ssf + "', '"
+ status + "', '" + id + "g')";
//for update of guardian recordsString query1 = "INSERT into guardian
VALUES ('" +id + "g', '" + gln + "', '" + gfn
+ "', '" + gmi +"', '" + gsa + "', '" + gca + "',
'" + gzc + "', '" + gpn + "')";
//for update of assign guardian recordsString query2 = "INSERT into
assignGuardian VALUES ('" +id + "', '" + id + "g')";
int result = statement.executeUpdate( query );int result1 = statement.executeUpdate(
query1 );
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
40
-
7/31/2019 MELJUN CORTES Documentation
41/42
int result2 = statement.executeUpdate(query2 );
if ( result == 1 || result1 == 1 ||result2 == 1)
{
JOptionPane.showMessageDialog(null,"One record added to the database.");
//reset all fieldsathleteIDfield.setText("");athleteLastNameField.setText("");
athleteFirstNameField.setText("");athleteMIField.setText("");streetAddressField.setText("");cityField.setText("");zipCodeField.setText("");phoneNumberField.setText("");primarySportField.setText("");secondarySportField.setText("");birthdayField.setText("");
guardianLastNameField.setText("");
guardianFirstNameField.setText("");guardianMIField.setText("");gStreetAddressField.setText("");gCityField.setText("");gZipCodeField.setText("");gPhoneNumberField.setText("");
}}
catch ( SQLException sqlex ) {sqlex.printStackTrace();JOptionPane.showMessageDialog(null,
"Insertion failed!\n" +sqlex,"Error", JOptionPane.ERROR_MESSAGE);
}
}}
}
public static void main(String[] args){
AddAthlete application = new AddAthlete();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class RadioButtonHandler implements ItemListener{
public void itemStateChanged( ItemEvent e ) {if (e.getSource() == mButton ){
Ang Bulilit Liga Athlete Record Maintenance SystemMaria Pamela C. David
41
-
7/31/2019 MELJUN CORTES Documentation
42/42
//set gendergender = "M";
} else {gender = "F";
}}
}}
/*AddAthlete.javaWritten by Maria Pamela C. Davidin partial fulfillment of the requirementsin CS192*/
top related