![]() |
| ||
| Postal code program, need help to get in right direction hi so i have just joined today but if i had known about this site i would have joined much sooner, i asked if anyone could help me with how i should post in the intro but dont wanna wait a day for a response so if i make any mistakes just let me know and ill change for the future. My teacher is asking me to create a barcode program that takes a zipcode inputed by the user and changed into a postal barcode. he has given me a starting point and although i know im suppose to create a construct i have had trouble creating it and getting variables across classes so if anyone could tell me how to begin the construct and maybe even the next few steps in vague detail to get me in the right direction it would be a life savior. requirements are Implement a class named PostalZipCode that; Has two instance variables (zipCode & barCode) of type String, Has a constructor that accepts a String input parameter for the, zipCode and determines and sets the barCode Has a method called getBarCode that returns the barCode String (theres other information such as which charecters to use for the digits and also i need to add a check digit system but i should be able to work something out for that with a little research once i get the basis for the program) sorry if i do this wrong. this is what i have been given: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PostOffice extends JFrame implements ActionListener { private JButton zipCodeButton; private JTextField zipCodeField, barCodeField; private JLabel zipCodeLabel; private PostalZipCode myZip; public static void main () { PostOffice myApplication = new PostOffice(); myApplication.setSize(400,140); myApplication.setTitle("Zip Code"); myApplication.createGUI(); myApplication.setVisible(true); } private void createGUI() { setDefaultCloseOperation(EXIT_ON_CLOSE); Container window = getContentPane(); window.setLayout(new FlowLayout()); zipCodeLabel = new JLabel(" Zip Code "); window.add(zipCodeLabel); zipCodeField = new JTextField(5); window.add(zipCodeField); barCodeField = new JTextField(20); barCodeField.setHorizontalAlignment(JTextField.CENTER); barCodeField.setFont(new Font("Sans erif", Font.BOLD, 20)); window.add(barCodeField); zipCodeButton = new JButton("Display Postal Bar Code"); zipCodeButton.addActionListener(this); window.add(zipCodeButton); } public void actionPerformed (ActionEvent e) { String userInput = zipCodeField.getText(); myZip = new PostalZipCode(userInput); barCodeField.setText(myZip.getBarCode()); } } |
| ||
| Re: Postal code program, need help to get in right direction public class PostalZipCode PS: Please use code tags in the future to post any size of code [code]YOUR CODE HERE[/code] |
| ||
| Re: Postal code program, need help to get in right direction Your professor gave you whats called a GUI. A GUI is just a window that, in this case, provides the user with a way to enter data. Now, to elaborate on that idea, I'll comment some of your professor's code to help you understand what he wants you to do. |
| ||
| Re: Postal code program, need help to get in right direction import java.awt.*; And here is an outline of what the class you are writing should look like and contain: public class PostalZipCode{You can compare Peter's code and my code to help you figure out how Java works. Both of our codes do the same thing. |
| ||
| Re: Postal code program, need help to get in right direction Thanks to both of you. This information has already helped me out tremendously in understanding whats being asked of me. I'll be sure to use the code tags from now on. |
| All times are GMT -4. The time now is 9:19 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC