Sample Program with GUI
Code:
public Reviewer() { //JFrame Name is Reviewer
setTitle("Student Application");//Title of my JFrame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 559, 399);
contentPane = new JPanel();
[Link](Color.LIGHT_GRAY);
[Link](new Color(205, 133, 63));
[Link](new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
[Link](null);
//Declaration of Labels with its corresponding properties
//Full Name Label
JLabel lblName = new JLabel("Full Name:");
[Link]([Link]);
[Link](new Font("Tahoma", [Link], 16));
[Link](10, 34, 88, 25);
[Link](lblName);
//Address Label
JLabel lblAdd = new JLabel("Address:");
[Link]([Link]);
[Link](new Font("Tahoma", [Link], 16));
[Link](10, 69, 88, 25);
[Link](lblAdd);
//Age Label
JLabel lblAge = new JLabel("Age:");
[Link]([Link]);
[Link](new Font("Tahoma", [Link], 16));
[Link](10, 104, 88, 25);
[Link](lblAge);
//Gender Label
JLabel lblGender = new JLabel("Gender:");
[Link]([Link]);
[Link](new Font("Tahoma", [Link], 16));
[Link](10, 139, 88, 25);
[Link](lblGender);
//Program Choice Label
JLabel lblProgChoice = new JLabel("Program Choice:");
[Link]([Link]);
[Link](new Font("Tahoma", [Link], 16));
[Link](10, 174, 149, 25);
[Link](lblProgChoice);
//Declaration of Text Fields with its corresponding properties
//Name Text Field
txtName = new JTextField();
[Link](new Font("Tahoma", [Link], 16));
[Link](102, 34, 405, 25);
[Link](txtName);
[Link](10);
//Address Text Field
txtAddress = new JTextField();
[Link](new Font("Tahoma", [Link], 16));
[Link](10);
[Link](102, 69, 405, 25);
[Link](txtAddress);
//Age Text Field
txtAge = new JTextField();
[Link](new Font("Tahoma", [Link], 16));
[Link](10);
[Link](102, 104, 80, 25);
[Link](txtAge);
//Declaration of Radio Button with its corresponding properties
//Male Radio Button
JRadioButton rdbMale = new JRadioButton("Male");
[Link](Color.LIGHT_GRAY);
[Link](new Font("Tahoma", [Link], 16));
[Link](115, 141, 80, 21);
[Link](rdbMale);
//Female Radio Button
JRadioButton rdbFemale = new JRadioButton("Female");
[Link](Color.LIGHT_GRAY);
[Link](new Font("Tahoma", [Link], 16));
[Link](198, 141, 103, 21);
[Link](rdbFemale);
//Grouping the rdb to select only one option
ButtonGroup grpGender = new ButtonGroup();
[Link](rdbFemale);
[Link](rdbMale);
//1-D Array for the list of option in combo box
String availableProg [] = {"BS in Information Technology",
"BS in Computer Science",
"BS in Accountancy",
"BS in Elementary Education",
"BS in Accountancy"};
//Declaration of Combo box with its corresponding properties
//availableProg is placed inside the parentheses to store the elements to become the
cmb items
JComboBox cmbProgram = new JComboBox(availableProg);
[Link](new Font("Tahoma", [Link], 16));
[Link](169, 174, 338, 25);
[Link](cmbProgram);
//Declaration of Text Area with its corresponding properties
JTextArea txtDisplay = new JTextArea();
[Link](true);
[Link](false); //to disable editable
[Link](new Font("Monospaced", [Link], 20));
[Link](42, 259, 470, 77);
[Link](txtDisplay);
//Declaration of Button with its corresponding properties
//Buttons are placed on the last part to avoid error when we call the other components
JButton btnApply = new JButton("APPLY");
//codes to be executed once the button was clicked
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
//declaration of variables for user input
String appName, add, age, program, gender;
int appNumber; //the program will generate application number
//initializing the value of appName, add, and age from the Text Field
appName = [Link]();
add = [Link]();
age = [Link]();
//initializing the value of gender from the selected radio button
//ternary operator is used to identify the gender
//ternary condition?True Output:False Output;
gender = ([Link]() == true)? "Male" : "Female";
//initializing the value of program from the selected item on the combo box
//(String) is used to convert the selected item from Object to String
program = (String)[Link]();
//initializing the value of appNumber from random number 1000-9999
//(int) to convert the random number from double to integer
//[Link]() function for random number
//1000 is the starting , 9999 is the ending
appNumber = ((int)([Link]()*(1000-9999+1)+9999));
//to show message dialog for the user to confirm the information
[Link](contentPane, "Confirm your input"
+ "\nName: " + appName
+ "\nAddress: " + add
+ "\nAge: " + age
+ "\nProgram Choice: " + program);
//for example BSIT and BSCS exceed the number of applicants
//conditional statement is used
//getSelectedIndex will return the selected item inside the cmb
//it will also represent the items(array elements)
if([Link]() == 0) {//BSIT
//will display No Slot Available on the text area
[Link]("No Slot Available");
}
else if([Link]() == 1) {//BSCS
[Link]("No Slot Available");
}
else{
//will display the ff. on the text area
//2024 + appNumber will return 2024 then the random generated number
[Link]("Application Successful! \nApplicant Number: " + 2024 +
appNumber);
}
}
});
[Link](new Font("Tahoma", [Link], 16));
[Link](221, 220, 115, 29);
[Link](btnApply);
}
Sample Output: