Page 765 - Introduction to Programming with Java: A Problem Solving Approach
P. 765
17.15 Job Application Example 731
/*************************************************************
*
JobApplication.java
Dean & Dean
This program implements job application questions
with check boxes, radio buttons, and a combo box.
*************************************************************/
*
*
*
*
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
// for EmptyBorder
public class JobApplication extends JFrame
{
private static final int WIDTH = 250;
private static final int HEIGHT = 300;
private JCheckBox java;
private JCheckBox helpDesk;
private JCheckBox coffee;
// Java Sun certified?
// help-desk experience?
// good coffee maker?
private JRadioButton goodCitizen, criminal;
private JComboBox salary;
private String[] salaryOptions =
{"$20,000-$59,000", "$60,000-$100,000", "above $100,000"};
private JButton submit;
// submit the application
Apago PDF Enhancer
//**********************************************************
public JobApplication()
{
}
setTitle("Job Application Form");
setSize(WIDTH, HEIGHT);
setDefaultCloseOperation(EXIT_ON_CLOSE);
createContents();
setVisible(true);
// end JobApplication constructor
//**********************************************************
// Create components and add to window.
Figure 17.17a JobApplication program—part A
Problem 3: Components Are Touching Left Boundary
By default, containers have no margins. So if a container has left-aligned components, those components touch the container’s left boundary. That explains the left-boundary ugliness in Figure 17.18’s right picture. You can add a margin by calling setBorder like this:
<container>.setBorder(new EmptyBorder(<top>, <left>, <bottom>, <right>));
In calling setBorder, you’ll need to pass a border object as an argument. There are several different types of border classes. You should use the EmptyBorder class because an empty border produces a margin,