import javax.swing.*; import java.awt.*; import java.awt.event.*; import postal.*; public class PostalGUI extends JFrame implements ActionListener { private JLabel lblZip; private JTextField txtZip; private JButton btnZip; private JPanel pnlZip; private PostalBarCode barCode; private int table[][]; private int ZIPcode; /** * Answers a PostalFrame object to create a simple GUI * to produce a postal bar code for the user's zip code **/ public PostalGUI() { setSize(280,125); setLocation(100,100); lblZip = new JLabel("Zip Code:"); txtZip = new JTextField(7); btnZip = new JButton("Bar Code"); pnlZip = new JPanel(); pnlZip.add(lblZip); pnlZip.add(txtZip); pnlZip.add(btnZip); btnZip.addActionListener(this); Container c = getContentPane(); c.add(pnlZip, BorderLayout.NORTH); barCode = new PostalBarCode(); c.add(barCode, BorderLayout.CENTER); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); table = new int[10][5]; initTable(); } /* Extract the individual digits stored in the ZIP code * and store their values as private data */ private void extractDigits() { barCode.clearCode(); } /* Calculate correction digit and draw it * ...used by actionPerformed */ private void calculateAndDrawCDigit() { } /* Retrieve the value (zero or one) * stored in the ith row and jth column * of the ZIP code table * @param int i ith row * int j jth column * @return zero or one as an integer */ private int getValue(int i, int j) { return table[i][j]; } /* Draw the bar code for the zip code * using the drawSmallBar and drawFullBar methods provided * in PostalBarCode object * ...invoked from actionPerformed() */ private void drawZIPCode() { } public void actionPerformed(ActionEvent e) { String zipcode = new String(); if (e.getSource() == btnZip) { // take text from textfield and trim off any // whitespace at either end zipcode = txtZip.getText().trim(); if (zipcode.length() == 5) { ZIPcode = Integer.parseInt(zipcode); extractDigits(); //5 digits drawZIPCode(); // use the PostalBarCode object // to draw a full or half // bar for each digit calculateAndDrawCDigit(); //calculate and //draw the the check digit } } } private void initTable() { table[0][0] = 1; table[0][1] = 1; table[0][2] = 0; table[0][3] = 0; table[0][4] = 0; table[1][0] = 0; table[1][1] = 0; table[1][2] = 0; table[1][3] = 1; table[1][4] = 1; table[2][0] = 0; table[2][1] = 0; table[2][2] = 1; table[2][3] = 0; table[2][4] = 1; table[3][0] = 0; table[3][1] = 0; table[3][2] = 1; table[3][3] = 1; table[3][4] = 0; table[4][0] = 0; table[4][1] = 1; table[4][2] = 0; table[4][3] = 0; table[4][4] = 1; table[5][0] = 0; table[5][1] = 1; table[5][2] = 0; table[5][3] = 1; table[5][4] = 0; table[6][0] = 0; table[6][1] = 1; table[6][2] = 1; table[6][3] = 0; table[6][4] = 0; table[7][0] = 1; table[7][1] = 0; table[7][2] = 0; table[7][3] = 0; table[7][4] = 1; table[8][0] = 1; table[8][1] = 0; table[8][2] = 0; table[8][3] = 1; table[8][4] = 0; table[9][0] = 1; table[9][1] = 0; table[9][2] = 1; table[9][3] = 0; table[9][4] = 0; } public static void main(String [] args) { PostalGUI gui = new PostalGUI(); } }