/*+--------------------------------------------------------------------------+* *| |* *| B a r C o d e A p p l e t . j a v a |* *| |* *| ITSE2417 Introduction to Java: Project 2 |* *| BarCodesApplet.java |* *| Due 03/26/01 |* *| |* *| Jim Connelley |* *| |* *| This Applet makes user of the BarCode class to compute a US Postal |* *| Service Barcode, given an input ZIP code. |* *| |* *| This applet actually does very little other than placing and populating|* *| various text fields on the Applet screen. |* *| |* *+--------------------------------------------------------------------------+* */ import java.awt.*; import java.applet.Applet; public class BarCodeApplet extends Applet { //Private class variables private BarCode ZipCode; // saved BarCode private Graphics gContext; // saved BarCode Graphics context /** Initializes the applet BarCodeApplet */ public void init () { initComponents (); ZipCode = new BarCode("xxxxx"); //error initially } //Paint the BarCode public void paint (Graphics g) { gContext = g.create(); ZipCode.DrawBarCode(g); } /** This method is called from within the init() method to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents() {//GEN-BEGIN:initComponents label2 = new java.awt.Label(); textField1 = new java.awt.TextField(); label4 = new java.awt.Label(); textField2 = new java.awt.TextField(); label5 = new java.awt.Label(); textField3 = new java.awt.TextField(); label6 = new java.awt.Label(); textField4 = new java.awt.TextField(); button1 = new java.awt.Button(); setLayout(null); label2.setFont(new java.awt.Font ("Dialog", 0, 11)); label2.setName("Label_Enter_Code"); label2.setBackground(new java.awt.Color (204, 204, 204)); label2.setForeground(java.awt.Color.black); label2.setText("Enter 5 Digit ZIP Code or 32 Character Bar Code:"); add(label2); label2.setBounds(123, 77, 251, 26); textField1.setBackground(java.awt.Color.white); textField1.setName("Text_5_Digit_ZIP_Code"); textField1.setFont(new java.awt.Font ("Courier New", 1, 12)); textField1.setForeground(java.awt.Color.black); add(textField1); textField1.setBounds(389, 76, 313, 33); label4.setFont(new java.awt.Font ("Dialog", 0, 11)); label4.setName("Label_output_Zip_Code"); label4.setBackground(new java.awt.Color (204, 204, 204)); label4.setForeground(java.awt.Color.black); label4.setText("Computed 5-Digit ZIP Code "); add(label4); label4.setBounds(217, 122, 160, 26); textField2.setBackground(new java.awt.Color (212, 208, 200)); textField2.setName("Text_Out_5_Digit_ZIP"); textField2.setEditable(false); textField2.setFont(new java.awt.Font ("Courier New", 1, 12)); textField2.setForeground(java.awt.Color.black); add(textField2); textField2.setBounds(392, 118, 161, 34); label5.setFont(new java.awt.Font ("Dialog", 0, 11)); label5.setName("label6"); label5.setBackground(new java.awt.Color (204, 204, 204)); label5.setForeground(java.awt.Color.black); label5.setText("Computed Binary BarCode:"); add(label5); label5.setBounds(222, 165, 146, 22); textField3.setBackground(java.awt.Color.white); textField3.setName("TextBox_Computed_Binary_Code"); textField3.setEditable(false); textField3.setFont(new java.awt.Font ("Dialog", 0, 11)); textField3.setForeground(java.awt.Color.black); add(textField3); textField3.setBounds(388, 160, 325, 37); label6.setFont(new java.awt.Font ("Dialog", 0, 11)); label6.setName("label7"); label6.setBackground(new java.awt.Color (204, 204, 204)); label6.setForeground(java.awt.Color.black); label6.setText("Error Message (If Error detected):"); add(label6); label6.setBounds(197, 213, 171, 33); textField4.setBackground(java.awt.Color.white); textField4.setName("Text_Error_Message"); textField4.setEditable(false); textField4.setFont(new java.awt.Font ("Dialog", 0, 11)); textField4.setForeground(java.awt.Color.black); textField4.setText(" "); add(textField4); textField4.setBounds(390, 202, 353, 34); button1.setFont(new java.awt.Font ("Dialog", 0, 11)); button1.setLabel("Press When Complete"); button1.setName("Button1"); button1.setBackground(java.awt.Color.white); button1.setForeground(java.awt.Color.black); button1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { Button_pressed(evt); } } ); add(button1); button1.setLocation(397, 21); button1.setSize(button1.getPreferredSize()); }//GEN-END:initComponents private void Button_pressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Button_pressed // Add your handling code here: // User has clicked on the button. This will cause the code here to activate. The code // here instantiates BarCode object using whatever value the user has entered into textfield1 // We check the error indicator and populate some output text fields accordingly. // We unconditionally call the Accessor method DrawBarCode, passing it a previously // recorded graphics context. The DrawBarCode method will fill a rectangle, and if the // value passed on instantiation was valid, the BarCode will be graphically rendered. ZipCode = new BarCode(textField1.getText()); if(ZipCode.getErrorInd() == false){ textField1.setText(""); // clear for next time textField2.setText("" + ZipCode.getZipCode()); textField3.setText(ZipCode.getBinary()); } else{ textField2.setText("Error"); textField3.setText("Error"); } textField4.setText(ZipCode.getErrorMsg()); ZipCode.DrawBarCode(gContext); // Draw the BarCode }//GEN-LAST:event_Button_pressed // Variables declaration - do not modify//GEN-BEGIN:variables private java.awt.Label label2; private java.awt.TextField textField1; private java.awt.Label label4; private java.awt.TextField textField2; private java.awt.Label label5; private java.awt.TextField textField3; private java.awt.Label label6; private java.awt.TextField textField4; private java.awt.Button button1; // End of variables declaration//GEN-END:variables }