Please complate all TODO in the template 1 Overview In this
Please complate all \"//TODO\" in the template
1 Overview
In this lab, you will implement a Job application program similar to the one in the textbook.
Unlike the example in the book, this program has the choice of two positions: software engineeer and system engineer. Each position requires a different set of skills. Specifically, software engineer position asks for skills including Java programming, Web programming, and database system while system engineer position asks for skills including operating system, internetworking, and system programming.
Applicants must check at least 2 of the required skills for each position and does not ask salary higher than 100,000 for their applications to be accepted.
In the provided template, you will find a program that is mostly complete with the only method that you need to implement is the method JPanel addPositions(). In this method, you will add two radio buttons that represent the two positions to a panel and return that panel. You should add listeners to the radio buttons so that only the skills required for the position are displayed as check boxes.
Note that we use two panels systemPanel and softwarePanel to hold the checkboxes for each set of skills. Also note that in order for the panel to display changed content, you should call revalidate and repaint method on the centerPanel, which holds either systemPanel or softwarePanel.
2 Template
package lab12;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*; // for EmptyBorder
// The frame to hold all GUI objects
class JobAppFrame extends JFrame {
private static final long serialVersionUID = 5995615621534068977L;
private static final int WIDTH = 300;
private static final int HEIGHT = 400;
JobAppFrame() {
setTitle(\"Job Application Form\");
setSize(WIDTH, HEIGHT);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
}
public class Lab12 {
// check box arrays for software skills and system skills
private JCheckBox[]
softwareBoxes = { new JCheckBox(\"Java programming\"), new JCheckBox(\"Web programming\"), new JCheckBox(\"Database system\") },
systemBoxes = { new JCheckBox(\"Operating system\"), new JCheckBox(\"Internetworking\"), new JCheckBox(\"System programming\") };
// radio buttons for choice between software and system engineer
private JRadioButton softwareEngineer, systemEngineer;
// salary choice
private JComboBox<String> salary;
// system panel holds skill check boxes for system engineer
// software panel is similar
// center panel holds everything together
private JPanel systemPanel = addSkills(systemBoxes),
softwarePanel = addSkills(softwareBoxes),
centerPanel = new JPanel();
// add skills in the \"boxes\" array to a skill panel and return the panel
// the panel should use a grid layout so that it holds all skills as check boxes plus a label on top that says \"Skills (check all that apply):\"
JPanel addSkills(JCheckBox[] boxes) {
JPanel skillPanel = new JPanel(new GridLayout(boxes.length+1, 1));
skillPanel.add(new JLabel(\"Skills (check all that apply):\"));
for(JCheckBox box: boxes) {
skillPanel.add(box);
}
return skillPanel;
}
// return the number of check boxes that are selected in the \"boxes\" array
int selectedSkills(JCheckBox[] boxes) {
int ret = 0;
for(JCheckBox box: boxes) {
if(box.isSelected()) {
ret = ret + 1;
}
}
return ret;
}
// return true under the following conditions
// 1. salary requirement is not above 100,000
// 2. if software engineer position is selected, then at least 2 software skills are checked
// 3. if system engineer position is selected, then at least 2 system skills are checked
boolean checkSkills() {
return ((softwareEngineer.isSelected() && selectedSkills(softwareBoxes) >= 2) ||
(systemEngineer.isSelected() && selectedSkills(systemBoxes) >= 2))
&& (!salary.getSelectedItem().equals(\"above $100,000\"));
}
// add two radio buttons that represent software/system engineer positions to a panel and return the panel
// add action listeners to the radio button so that
// if software engineer position is selected, then the software skills are displayed as check boxes
// if system engineer position is selected, then the system skills are displayed as check boxes
JPanel addPositions() {
// TODO
}
// add salary combobox
JPanel addSalary() {
// centerPanel holds all components except button
JPanel salaryPanel = new JPanel(new GridLayout(2, 1));
String[] salaryOptions = {\"$20,000-$59,000\", \"$60,000-$100,000\", \"above $100,000\"};
salary = new JComboBox<>(salaryOptions);
salaryPanel.add(new JLabel(\"Salary requirements:\"));
salaryPanel.add(salary);
return salaryPanel;
}
public Lab12() {
JPanel windowPanel = new JPanel(new BorderLayout(0, 10));
windowPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
JPanel southPanel = new JPanel(new FlowLayout());
centerPanel.add(addPositions());
centerPanel.add(softwarePanel);
centerPanel.add(addSalary());
windowPanel.add(centerPanel, BorderLayout.CENTER);
JButton submit = new JButton(\"submit\");
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (checkSkills()) {
JOptionPane.showMessageDialog(null, \"Thank you for your application submission.\ \" +
\"We\'ll contact you after we process your information.\");
}
else {
JOptionPane.showMessageDialog(null, \"Sorry, no jobs at this time.\");
}
}
} );
southPanel.add(submit);
windowPanel.add(southPanel, BorderLayout.SOUTH);
new JobAppFrame().add(windowPanel);
}
public static void main(String[] args) {
new Lab12();
}
}
Solution
JRadioButton softengButton= new JRadioButton(softengString)
softengButton.setActioncommand(softengString)
softengButton.setselected(true)
JRadioButton sysengButton= new JRadioButton(sysengString)
sysengButton.setActioncommand(sysengString)
database button = new JCheckBox(\"database system\");
else
internetButton = new JCheckBox(\"internet working\");


