Help!! I am new to Java and just don't know enough to complete my project!!

Hi, I need help! Below is listed my code for a bar code scanning project that my company has asked me to write. I want to read a barcode, make sure that it is not already in my file, if not in file write to file(this part works - the write to file), if in file pop up an error message. I am reading barcodes off pallets of boxes and need to reset the current pallet after it is complete but don't reset the total pallets until exit. Could you please look at my code -- the first half of the code is the GUI -- and make suggestions. My vectors are not working and I have not completed the error handeling. I need to finish by Friday. Tall order for someone who has only had the basics and this is my first project. Sorry I don't have any Duke dollars left -- so this one is for free.
//-------------------Buffalo Offline Scan Program------------
//This program will allow the Buffalo user to continue scanning cases on pallets
//when the AS\400 is down. The scans will be sent to a flat file that will be
//FTPed to the AS\400 when it is back up and update the proper files.
//Program Author: Susan Riggin and Dean Smith
//RFSS # 01080701
package javalab;
import javabook.*;
import javalab.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.applet.*;
import java.io.*;
import java.io.File.*;
import java.util.*;
public class Bscan extends Applet implements ActionListener//, TextListener
//               Data Members
     //Variables
     private int scanCount = 0;
     private int sessionCount = 0;
     //Labels
     private Label buffaloLabel = new Label();
     private Label scanLabel = new Label();
     private Label cPalletLabel = new Label();
     private Label cCountLabel = new Label();
     private Label tPalletLabel = new Label();
     private Label tCountLabel = new Label();
     private Label rButtonLabel = new Label();
     private Label eButtonLabel = new Label();
     private Label caseCountLabel = new Label();
     private Label pButtonLabel = new Label();
     private Label errorLabel = new Label();
     //TextFields
     private TextField scanTextField = new TextField();
     private TextField caseCount = new TextField("0");
     //Buttons
     private Button eButton = new Button("Exit");
     //Text Areas
     private TextArea cTextArea = new TextArea();
     private TextArea tTextArea = new TextArea();
     String scanText = scanTextField.getText();
     Vector v = new Vector(24,5);
     Vector v2 = new Vector(24,5);
//               Constructor
public Bscan()
     //Attach the GUI objects so they will appear on the screen.
     setLayout (null);
     buffaloLabel.setBounds(203, 5, 300, 27);
     buffaloLabel.setFont(new Font ("dialog",Font.BOLD, 18));
     buffaloLabel.setAlignment(Label.CENTER);
     buffaloLabel.setBackground(Color.red);
     buffaloLabel.setText("Buffalo OffLine Scan");
     cPalletLabel.setBounds(18, 60, 341, 23);
     cPalletLabel.setFont(new Font ("dialog", Font.BOLD, 14));
     cPalletLabel.setAlignment(Label.CENTER);
     cPalletLabel.setText("Current Pallet");
     cPalletLabel.setBackground(Color.cyan);
     tPalletLabel.setBounds(372, 62, 341, 23);
     tPalletLabel.setFont(new Font ("dialog", Font.BOLD, 14));
     tPalletLabel.setAlignment(Label.CENTER);
     tPalletLabel.setText("Total Pallets");
     tPalletLabel.setBackground(Color.yellow);
     eButton.setBounds(542, 485, 56, 23);
     eButton.setBackground(Color.yellow);
     eButton.setLabel("Exit");
     cCountLabel.setBounds(18, 88, 341, 23);
     cCountLabel.setFont(new Font("dialog", Font.BOLD, 12));
     cCountLabel.setAlignment(Label.CENTER);
     cCountLabel.setText("Current Pallet Case Count = " + scanCount);
     cCountLabel.setBackground(Color.lightGray);
     tCountLabel.setBounds(372, 88, 341, 23);
     tCountLabel.setFont(new Font("dialog", Font.BOLD, 12));
     tCountLabel.setAlignment(Label.CENTER);
     tCountLabel.setText("Total Pallet Case Count = " + sessionCount);
     tCountLabel.setBackground(Color.lightGray);
     scanLabel.setBounds(360, 33, 160, 23);
     scanLabel.setFont(new Font("dialog", Font.BOLD, 14));
     scanLabel.setBackground(Color.red);
     scanLabel.setAlignment(Label.CENTER);
     scanLabel.setText(" Current Barcode Scan: ");
     caseCountLabel.setBounds(18, 33, 200, 23);
     caseCountLabel.setFont(new Font("dialog", Font.BOLD, 14));
     caseCountLabel.setBackground(Color.red);
     caseCountLabel.setAlignment(Label.CENTER);
     caseCountLabel.setText("#Parts in Case:");
     caseCount.setBounds(250, 34, 58, 23);
     caseCount.setBackground(Color.white);
     scanTextField.setBounds(545, 34, 88, 23);
     scanTextField.setBackground(Color.white);
     eButtonLabel.setBounds(372, 460, 341, 23);
     eButtonLabel.setAlignment(Label.CENTER);
     eButtonLabel.setBackground(Color.yellow);
     eButtonLabel.setText("Press Exit to end Program.");
     rButtonLabel.setBounds(18, 460, 341, 23);
     rButtonLabel.setAlignment(Label.CENTER);
     rButtonLabel.setBackground(Color.cyan);
     rButtonLabel.setText("Scan Reset barcode for next pallet scan.");
     pButtonLabel.setBounds(200, 485, 315, 23);
     pButtonLabel.setAlignment(Label.CENTER);
     pButtonLabel.setFont(new Font ("dialog", Font.BOLD, 12));
     pButtonLabel.setBackground(Color.green);
     pButtonLabel.setText("Scan Partial Case Bar Code to enter correct # parts.");
     errorLabel.setBounds(18, 500, 682, 25);
     errorLabel.setAlignment(Label.CENTER);
     errorLabel.setFont(new Font ("dialog", Font.BOLD, 16));
     errorLabel.setBackground(Color.red);
     errorLabel.setText("Error - Barcode already scanned - scan next box!!!");
     cTextArea.setBounds(18, 118, 341, 333);
     cTextArea.setBackground(Color.cyan);
     tTextArea.setBounds(372, 118, 341, 333);
     tTextArea.setBackground(Color.yellow);
     //Place the GUI objects on the applet.
     add(buffaloLabel);
     add(scanLabel);
     add(cPalletLabel);
     add(cCountLabel);
     add(tCountLabel);
     add(tPalletLabel);
     add(cCountLabel);
     add(rButtonLabel);
     add(eButtonLabel);
     add(pButtonLabel);
     add(caseCountLabel);
     add(scanTextField);
     add(caseCount);
     add(eButton);
     add(cTextArea);
     add(tTextArea);
     //Add applet as an action listener.
     //caseCount.addTextListener(this);
     caseCount.addActionListener(this);
     scanTextField.addActionListener(this);
     eButton.addActionListener(this);
//               Methods that make the program work
//-------method adds the Abbott "A" and Buffalo to the screen--
     //Adds the Abbott "A" & Buffalo to the screen
     public void paint(Graphics g){
     Toolkit kit = Toolkit.getDefaultToolkit();
     Image imageA = kit.getImage("c:\\\\javaproj\\javalab\\abbott.gif");
     Image imageB = kit.getImage("c:\\\\javaproj\\javalab\\bison.gif");
     g.drawImage(imageA, 650, 5, 50, 50, this);
     g.drawImage(imageB, 713, 5, 50, 50, this);
//---------method for action performed and action event---------
     public void actionPerformed(ActionEvent event)
     String scanText,caseb, cTime, cDate, pCount;
     scanText = scanTextField.getText();
     caseb = caseCount.getText();
     caseCount.setText("0");
     //tests the barcode to see if reset or count needed
     if (event.getSource() == eButton) exit();
     else     
     if (scanText.equals ("99999999999999")) reset();
     else
     if (scanText.equals ("88888888888888")) count();
     else
     checker();
     //scanText = scanTextField.getText();
     Clock myClock = new Clock();
     cTime = myClock.getCurrentTime();
     cDate = myClock.getCurrentDate();
     ++scanCount;
     ++sessionCount;
     pCount = caseb;
     File scan = new File ("\\\\beast2\\riggisl\\scan", "scan.txt");
     cTextArea.append(scanCount+"->"+scanText+" "+cDate+" "+cTime+" "+pCount);
     cCountLabel.setText("Current Pallet Case Count = " + scanCount);
     cTextArea.append("\r\n");
     tTextArea.append(sessionCount+"->"+scanText+" "+cDate+" "+cTime+" "+pCount );
     tCountLabel.setText("Total Pallet Case Count = " + sessionCount);
     tTextArea.append("\r\n");
     write();
     scanTextField.setText("");
//-------------method for pressing the exit button---------------
     private void exit()
     v.clear();
     System.exit(0);
//------------method for pressing the reset button---------------
     private void reset()
     scanCount = 0;
     scanTextField.setText("");
     cTextArea.setText("");
     cCountLabel.setText("Current Pallet Case Count = " + scanCount);
     scanTextField.requestFocus();
     v.clear();     
//------------method for writing to the file---------------------
     private void write ()
     String cTime, cDate;
     Clock myClock = new Clock();
     cTime = myClock.getCurrentTime();
     cDate = myClock.getCurrentDate();
     String pCount = caseCount.getText();     
          try
     //FileWriter outputFile = new FileWriter("\\\\bfpscr01\\ftpdata\\scan\\scan.txt", true);
     //FileWriter outputFile = new FileWriter("c:\\\\javaproj\\javalab\\scan.txt", true);
     FileWriter outputFile = new FileWriter("\\\\beast2\\riggisl\\scan\\scan.txt", true);
     outputFile.write(scanTextField.getText());
     outputFile.write(myClock.getCurrentDate());
     outputFile.write(myClock.getCurrentTime());
     outputFile.write(pCount);
     outputFile.write("\r\n");
     outputFile.close();
catch (IOException e)
     scanTextField.setText("");
//               method for partial case count
     public void count()
     String caseb, scanText;
     caseCount.setText("");
     scanTextField.setText("");
     caseb = caseCount.getText();
     scanText = scanTextField.getText();
     checker();
//               method for error
     public void error()
     add(errorLabel);
//               method for checking barcode
     public void checker()
     String barcode = scanText;
     v.add(barcode);
     if(v == v2)
     error();
     else
     v2.add(barcode);
}     

I have a feeling you've already figured it out but I'll give a quick example. I didn't see where you're actually reading from the scan.txt file so I'm assuming that you're starting from scratch every time. It seems to me that you only need one Vector too - the one that contains all of the previously scanned codes.
Let's rename v to scannedList.
public void checker() {
  String barcode = scanText;
  if (scannedList.contains(barcode)) {
    error();
  else {
    scannedList.add(barcode);
    // write barcode to file
}You might want to read the scan.txt file on program startup and fill the scannedList with the codes already there:
Vector scannedList = new Vector();
BufferedReader f = new BufferedReader(new FileReader("scan.txt"));
String line;
while ((line = f.readLine()) != null) {
  scannedList.add(line);
f.close();

Similar Messages

  • Hi. I tried switching my Apple ID email address to my new email address and I don't know how to switch it for iCloud and iTunes. Please help!! It seems like Apple thinks I have two separate accounts, when I just tried to simply change it!

    Hi. I tried switching my Apple ID email address to my new email address and I don't know how to switch it for iCloud and iTunes. Please help!! It seems like Apple thinks I have two separate accounts, when I just tried to simply change it!

    Settings > Store > Sign Out.
    Sign in with the correct ID.

  • Hi all, i just bought the new macbook pro and just want to know if i can install Vista or Xp on it?

    Hi all, i just bought the new macbook pro and just want to know if i can install Vista or Xp on it?

    Yes.
    Windows on Intel Macs
    There are presently several alternatives for running Windows on Intel Macs.
    1. Install the Apple Boot Camp software.  Purchase Windows XP w/Service Pak2, Vista, or Windows 7.  Follow instructions in the Boot Camp documentation on installation of Boot Camp, creating Driver CD, and installing Windows.  Boot Camp enables you to boot the computer into OS X or Windows.
    2. Parallels Desktop for Mac and Windows XP, Vista Business, Vista Ultimate, or Windows 7.  Parallels is software virtualization that enables running Windows concurrently with OS X.
    3. VM Fusionand Windows XP, Vista Business, Vista Ultimate, or Windows 7.  VM Fusion is software virtualization that enables running Windows concurrently with OS X.
    4. CrossOver which enables running many Windows applications without having to install Windows.  The Windows applications can run concurrently with OS X.
    5. VirtualBox is a new Open Source freeware virtual machine such as VM Fusion and Parallels that was developed by Solaris.  It is not as fully developed for the Mac as Parallels and VM Fusion.
    Note that Parallels and VM Fusion can also run other operating systems such as Linux, Unix, OS/2, Solaris, etc.  There are performance differences between dual-boot systems and virtualization.  The latter tend to be a little slower (not much) and do not provide the video performance of the dual-boot system.
    See MacTech.com's Virtualization Benchmarking for comparisons of Boot Camp, Parallels, and VM Fusion.  Boot Camp is only available with Leopard or Snow Leopard. Except for Crossover and a couple of similar alternatives like DarWine you must have a valid installer disc for Windows. You must also have an internal optical drive for installing Windows. Windows cannot be installed from an external optical drive.

  • I bought a new ipod touch today and it connects to my wifi automatically... But I forgot my wifi password for my new iPod touch and I don't know how to find it in my old iPod?

    I bought a new ipod touch today and it connects to my wifi automatically... But I forgot my wifi password for my new iPod touch and I don't know how to find it in my old iPod?

    You can usually find the wi-fi password on your router itself if you know the router's ID and password (not the wi-fi password).  You can log into your router by putting its address (usually 192.168.1.1) into your browser's address window. 

  • Help...been told something and I don't know if its true.

    Just before I got my Nano, my Dad told me that your Nano will only work on one pc - so if you change pc/laptop, your nano will no longer work.
    Surely this cant be the case as if you got a new laptop you would need to buy another mp3 player and thats a ripoff!!
    Please help...don't know whether to play with my new toy now or when my replacement laptop comes at the weekend!!

    *my Dad told me that your Nano will only work on one pc - so if you change pc/laptop, your nano will no longer work.*
    That is incorrect. To be precise, if you update your iPod automatically you can only update it in that mode from one library. If you are changing computers you can copy your library from one to another and sync your iPod over again. To use an iPod with multiple libraries or computers you can set your iPod to manual update. In this mode you can directly access the content of the iPod and play it through iTunes and you can drag and drop whatever you want to the iPod from either library:
    Using iPod with Multiple computers
    Managing content manually on iPod
    iPod 101: Fill 'er Up
    Something else to be aware of when using an iPod in manual mode is that the "Do Not Disconnect" message will remain on the display until you physically eject the device. In that case use Safely Remove Hardware icon in the Windows system tray on your desktop or check this link: Safely Disconnect IPod

  • I just got a new ipod touch and I don't know how to connect it to iTunes. Help ?

    I've plugged it in and everything but it won't come up , already updated iTunes and restarted computer

    See:
    iOS: Device not recognized in iTunes for Windows
    or
    iPhone, iPad, iPod touch: Device not recognized in iTunes for Mac OS X
    Syncing with iTunes on a Mac or PC requires:
    Mac: OS X v10.6.8 or later for iOS 6 (10.5.8 for iOS 5)
    PC: Windows 7; Windows Vista; or Windows XP Home or Professional with Service Pack 3 or later
    iTunes 10.7 or later (free download from www.itunes.com/download) for iOS 6 (10.5 for iOS 5)

  • Please HELP!!! I'm new at this and I don't know how to buy a moie!!!!!

    I wonder if somebody would be so kind to tell me how can I find the movies in the iTunes Store.
    I just bought muy 30G video iPod and a $20 iTunes Card, but I have no idea how to get the movies.
    Please tell me how to buy movies and where to find them in the iTunes Store. Thank you!!!!!

    Hi Laruss:
    Welcome to discussions!
    You should ask this very question in the proper forum.
    Go here:
    http://discussions.apple.com/forum.jspa?forumID=797
    And ask again!
    Sue

  • I can no longer see my iPods names with the new look iTunes and also don't know where to sync it when I've added songs.

    The old  version I could see the name of my iPod but now I can't! I also used to be able to sync my iPod but I can't see anywhere to do this now! Any help greatfully received!

    The main differences between iTunes 11 and earlier versions are the loss of coverflow and ability to have multiple windows open.
    In Windows, you can restore much of the look & feel of iTunes 10.7 with these shortcuts:
    ALT to temporarily display the menu bar
    CTRL+B to show or hide the menu bar
    CTRL+S to show or hide the sidebar
    CTRL+/ to show or hide the status bar (won't hide for me on Win XP)
    Click the magnifying glass top right and untick Search Entire Library to restore the old search behaviour
    Use View > Hide <Media Kind> in the cloud or Edit > Preferences > Store and untick Show iTunes in the cloud purchases to hide the cloud items. The second method eliminates the cloud status column (and may let iTunes start up more quickly)
    If you don't like having different coloured background & text in the Album (Grid) view use Edit > Preferences > General and untick Use custom colours for open albums, movies, etc.
    With iTunes 11.0.3 and later you can enable artwork in the Songs view from View > Show View Options (CTRL+J) making it more like the old Album List view
    View > Show View Options (CTRL+J) also contains options to change the sorting of grid based views
    Turning on the sidebar should make things easier.
    tt2

  • I'm new to apple, and I don't know how to review my new apple ID, so I can get apps and songs

    I really want to tart getting some apps but when I do it's says I have to review my new apple ID to the iTunes and App Store. But I follow the instructions and then it's says I have to enter these billing information, but I don't want to buy anything so what do I do, I really want to start getting some apps but it won't let me

    If yo set up an account the normal way you have to add a valid payment method, like a credit card or redeem an iTunes gift card.
    Yo can however create a NEW account using these instructions. Make sure you follow the instructions. Many do not and if you do not you will not get the None option. You must use an email address that you have not used with Apple before.
    Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card

  • Help my ps4 suddenly started smoking and i don't know what to do

    It could be worse, it could be on the Buckfast.

    hayzink wrote:
    I tried patches but nothing works
    But how are your download speeds? Are they faster? Cause if so I think you've just solved the recent PSN download problem

  • Help, i made a terminal command and i don't know how to undo it.

    i found my long lost folder of terminal commands.. and i forgot what this one did, so i clicked it (i made the commands into a "unix executable file").. and all my files on my desktop are now hidden.. the only way to find them is to type in the file name into finder.
    the command i typed in was
    while (true) do
    chflags hidden ~/Desktop/*
    done
    and now everything on my desktop is gone, and i dont know how to undo it, I undid once about 3 months ago when i wrote it, but i forgot what i did. I tried counterering the command with others but it isn't doing anything. thank you
    edit: i know this command cant destroy my system because it wasn't a sudo, but still, i had all my class work on my laptop and now it's all invisible

    Hi, try this...
    while (true) do
    chflags nohidden ~/Desktop/*
    done

  • Im new to java and hope somebody can help me with my question

    Hi!
    Im quite new to java and I just have some simple questions..
    can someone please tell what kinds of error are considered as language violation for java? where can I find more info about these errors?
    can someone give me a simple example on a kind of error that cannot be caught in both compilation and runtime? I hope someone can help me out. Thanks in advance!!

    knightz211 wrote:
    Im just asking about errors that might go against the language definition but cant be detected.. If it "goes against the language defintion," it will be detected by the compiler. That's half of the compiler's job is to tell you what you've done that violates the language spec.
    because it confuses me when they say that such errors might occur so I just want to know what might these errors be.. sorry for that..Who's "they"? What exactly* did "they" say about "such errors"? It sounds to me like you're just confused, and you think there's something mysterious and inexplicable going on but you don't know what and don't even know what you're asking.
    I would suggest not worrying about hypothetical problems that you can't even put into words and focussing on learning Java. Along the way, if you encounter real, specific, actual problems, ask about them, and you'll probably get answers about the problems themselves and the language or theory behind them.

  • Hi, I just put a new internal hard disk to my MacBook after formattimg it and I don't know how to install the OS X? Any help please

    Hi, I just put a new internal hard disk to my MacBook after formattimg it and I don't know how to install the OS X? Any help please

    Be sure you have prepared the new drive correctly:
    Drive Preparation
    1.  Boot from your OS X Installer Disc. After the installer loads select your language and click on the Continue button.  When the menu bar appears select Disk Utility from the Utilities menu.
    2. After DU loads select your hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Note the SMART status of the drive in DU's status area.  If it does not say "Verified" then the drive is failing or has failed and will need replacing.  SMART info will not be reported  on external drives. Otherwise, click on the Partition tab in the DU main window.
    3. Under the Volume Scheme heading set the number of partitions from the drop down menu to one. Set the format type to Mac OS Extended (Journaled.) Click on the Options button, set the partition scheme to GUID (for Intel Macs) or APM (for PPC Macs) then click on the OK button. Click on the Partition button and wait until the process has completed.
    4. Select the volume you just created (this is the sub-entry under the drive entry) from the left side list. Click on the Erase tab in the DU main window.
    5. Set the format type to Mac OS Extended (Journaled.) Click on the Options button, check the button for Zero Data and click on OK to return to the Erase window.
    6. Click on the Erase button. The format process can take up to several hours depending upon the drive size.
    Steps 4-6 are optional but should be used on a drive that has never been formatted before, if the format type is not Mac OS Extended, if the partition scheme has been changed, or if a different operating system (not OS X) has been installed on the drive.
    When formatting has completed quit DU and return to the installer.  Complete the OS X installation.

  • I am new to Apple and just got an iPad Air.  Any suggestions on migrating my Windows Vista Contacts and IE Favorites to the iPad?  The suggested method of using iCloud is restricted to Windows 7 and 8.  Thanks.

    I am new to Apple and just got my iPad Air.  Does anyone have a suggestion on how I can migrate Contacts from Windows Mail and Favorites from IE that are on a Windows Vista desktop ?   The recommendation that I have seen are via using iCloud but that does not appear to work for Windows Vista, just Windows 7 and 8.  Thanks.

    You could try putting your contacts in through Gmail and then signing in with that Gmail on your iPad. You could also try searching for some kind of app that will transfer data easily (I'll look into it and update it if I find anything). I don't have any Microsoft products so I'm not sure if I'm much help but I'll definitely try. You'll definitely love coming to Apple it's much simpler and easier!

  • I have a iPod touch and i installed it on my other laptop until i had just got another one it says unable to connect to iTunes and i forgot my password and i delete the email and i don't know how i can get my i pod touch to work with my new one email

    I have a iPod touch and i installed it on my other laptop until i had just got another one it says unable to connect to iTunes and i forgot my password and i delete the email and i don't know how i can get my i pod touch to work with my new one email.
    I JUST NEED HELP

    I would contact Apple under your warranty.  I doubt you received a new iPod since Apple's policy is to give you a refurbished iPod. 

Maybe you are looking for