diff --git a/build.xml b/build.xml
new file mode 100644
index 0000000..f49032f
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
+
+
+ Builds, tests, and runs the project Barcode Reader.
+
+
+
diff --git a/data.txt b/data.txt
new file mode 100644
index 0000000..53f81a8
--- /dev/null
+++ b/data.txt
@@ -0,0 +1,6 @@
+0
+Howw
+1
+3
+14234
+Step A
diff --git a/manifest.mf b/manifest.mf
new file mode 100644
index 0000000..1574df4
--- /dev/null
+++ b/manifest.mf
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+X-COMMENT: Main-Class will be added automatically by build
+
diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml
new file mode 100644
index 0000000..874cbcb
--- /dev/null
+++ b/nbproject/build-impl.xml
@@ -0,0 +1,1413 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set src.dir
+ Must set test.src.dir
+ Must set build.dir
+ Must set dist.dir
+ Must set build.classes.dir
+ Must set dist.javadoc.dir
+ Must set build.test.classes.dir
+ Must set build.test.results.dir
+ Must set build.classes.excludes
+ Must set dist.jar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ No tests executed.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set JVM to use for profiling in profiler.info.jvm
+ Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ To run this application from the command line without Ant, try:
+
+ java -jar "${dist.jar.resolved}"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set debug.class
+
+
+
+
+ Must select one file in the IDE or set debug.class
+
+
+
+
+ Must set fix.includes
+
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set profile.class
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+
+ Must select some files in the IDE or set test.includes
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Some tests failed; see details above.
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set test.includes
+
+
+
+ Some tests failed; see details above.
+
+
+
+ Must select some files in the IDE or set test.class
+ Must select some method in the IDE or set test.method
+
+
+
+ Some tests failed; see details above.
+
+
+
+
+ Must select one file in the IDE or set test.class
+
+
+
+ Must select one file in the IDE or set test.class
+ Must select some method in the IDE or set test.method
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
new file mode 100644
index 0000000..3570cb0
--- /dev/null
+++ b/nbproject/genfiles.properties
@@ -0,0 +1,8 @@
+build.xml.data.CRC32=c7c77651
+build.xml.script.CRC32=0caee828
+build.xml.stylesheet.CRC32=8064a381@1.75.2.48
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=c7c77651
+nbproject/build-impl.xml.script.CRC32=efeff4f0
+nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
diff --git a/nbproject/project.properties b/nbproject/project.properties
new file mode 100644
index 0000000..985942d
--- /dev/null
+++ b/nbproject/project.properties
@@ -0,0 +1,79 @@
+annotation.processing.enabled=true
+annotation.processing.enabled.in.editor=false
+annotation.processing.processor.options=
+annotation.processing.processors.list=
+annotation.processing.run.all.processors=true
+annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java,**/*.form
+# This directory is removed when the project is cleaned:
+build.dir=build
+build.generated.dir=${build.dir}/generated
+build.generated.sources.dir=${build.dir}/generated-sources
+# Only compile against the classpath explicitly listed here:
+build.sysclasspath=ignore
+build.test.classes.dir=${build.dir}/test/classes
+build.test.results.dir=${build.dir}/test/results
+# Uncomment to specify the preferred debugger connection transport:
+#debug.transport=dt_socket
+debug.classpath=\
+ ${run.classpath}
+debug.test.classpath=\
+ ${run.test.classpath}
+# Files in build.classes.dir which should be excluded from distribution jar
+dist.archive.excludes=
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.jar=${dist.dir}/Barcode_Reader.jar
+dist.javadoc.dir=${dist.dir}/javadoc
+excludes=
+file.reference.zxing-1.6-core.jar=C:\\Users\\Nehal\\Desktop\\zxing-1.6-core.jar
+file.reference.zxing-javase.jar=C:\\Users\\Nehal\\Desktop\\zxing-javase.jar
+file.reference.zxing.jar=C:\\Users\\Nehal\\Desktop\\zxing.jar
+includes=**
+jar.compress=false
+javac.classpath=\
+ ${file.reference.zxing.jar}:\
+ ${file.reference.zxing-1.6-core.jar}:\
+ ${file.reference.zxing-javase.jar}
+# Space-separated list of extra javac options
+javac.compilerargs=
+javac.deprecation=false
+javac.processorpath=\
+ ${javac.classpath}
+javac.source=1.8
+javac.target=1.8
+javac.test.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+javac.test.processorpath=\
+ ${javac.test.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=${source.encoding}
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+main.class=barcode.reader.BarcodeReader
+manifest.file=manifest.mf
+meta.inf.dir=${src.dir}/META-INF
+mkdist.disabled=false
+platform.active=default_platform
+run.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+# Space-separated list of JVM arguments used when running the project.
+# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
+# To set system properties for unit tests define test-sys-prop.name=value:
+run.jvmargs=
+run.test.classpath=\
+ ${javac.test.classpath}:\
+ ${build.test.classes.dir}
+source.encoding=UTF-8
+src.dir=src
+test.src.dir=test
diff --git a/nbproject/project.xml b/nbproject/project.xml
new file mode 100644
index 0000000..7a54cf0
--- /dev/null
+++ b/nbproject/project.xml
@@ -0,0 +1,15 @@
+
+
+ org.netbeans.modules.java.j2seproject
+
+
+ Barcode Reader
+
+
+
+
+
+
+
+
+
diff --git a/src/barcode/reader/BarCode.java b/src/barcode/reader/BarCode.java
new file mode 100644
index 0000000..6456c0a
--- /dev/null
+++ b/src/barcode/reader/BarCode.java
@@ -0,0 +1,69 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package barcode.reader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.Scanner;
+
+
+public class BarCode {
+ private ArrayList tokens;
+
+// BarCode(File storedData) {
+// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+// }
+
+ public ArrayList getTokens() {
+ return tokens;
+ }
+
+ public void setTokens(ArrayList tokens) {
+ this.tokens = tokens;
+ }
+
+ BarCode(File input) throws FileNotFoundException{
+ tokens = new ArrayList();
+ loadFromFile(input);
+ System.out.println("the data already in the list");
+ }
+
+ public void loadFromFile(File inputFile) throws FileNotFoundException{
+ if(inputFile.canRead()){
+ Scanner reader = new Scanner(inputFile);
+ while(reader.hasNext()){
+ Data temp = new Data();
+ temp.setGeneratedNumber(Integer.parseInt(reader.nextLine()));
+ temp.setPackageData(reader.nextLine());
+ temp.setDataSent(reader.nextLine());
+ temp.setRecievedData(reader.nextLine());
+ temp.setIDNumber(Integer.parseInt(reader.nextLine()));
+ temp.setChoice(reader.nextLine());
+ tokens.add(temp);
+ }
+ System.out.println(1);
+ reader.close();
+ }
+ else{
+ System.out.println(0);
+ tokens = null;
+ }
+ }
+ public int FindWithGeneratedCode(int number){
+ int i = 0;
+ while(i < tokens.size() ){
+ if(tokens.get(i).getGeneratedNumber() == number){
+ return i;
+ }
+ i++;
+ }
+ return -1;
+ }
+
+ public void addToList(Data temp){
+ tokens.add(temp);
+ }
+}
diff --git a/src/Mainwindow.java b/src/barcode/reader/BarcodeReader.java
similarity index 95%
rename from src/Mainwindow.java
rename to src/barcode/reader/BarcodeReader.java
index d778104..19a3882 100644
--- a/src/Mainwindow.java
+++ b/src/barcode/reader/BarcodeReader.java
@@ -1,420 +1,423 @@
-import java.awt.Color;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Scanner;
-
-import javax.swing.ButtonGroup;
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JRadioButton;
-import javax.swing.JTextField;
-
-import com.google.zxing.BarcodeFormat;
-import com.google.zxing.WriterException;
-import com.google.zxing.client.j2se.MatrixToImageWriter;
-import com.google.zxing.common.BitMatrix;
-import com.google.zxing.oned.Code128Writer;
-
-public class Mainwindow extends JFrame {
- private JTextField barCodeText;
- private int newrakam;
- private BufferedImage image;
- private JFrame parent;
- private JPanel panel;
- private JPanel panel_3;
-
- /*
- * User input fields
- */
- private JTextField textField_1;
- private JTextField textField_2;
- private JTextField textField_3;
- private JTextField textField_4;
-
- private JLabel label;
- private JRadioButton rdbtnStepA;
- private JRadioButton rdbtnStepB;
- private JRadioButton rdbtnStepC;
- private JLabel view_package;
- private JLabel view_datasent;
- private JLabel view_recieved;
- private JLabel view_id;
-
- /*
- * Thread waiting for input from barcode reader
- */
- private Thread th;
-
- private BarCode tokens;
- private File storedData;
- private boolean fileNotGenerated;
-
- public static void main(String[] args) throws FileNotFoundException {
- new Mainwindow();
- }
-
- @SuppressWarnings("deprecation")
- Mainwindow() throws FileNotFoundException {
- storedData = null;
-
- setSize(532, 462);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- getContentPane().setLayout(null);
- parent = this;
-
- panel_3 = new JPanel();
- panel_3.setBounds(0, 0, 265, 424);
- getContentPane().add(panel_3);
- panel_3.hide();
-
- textField_4 = new JTextField();
- textField_4.setBounds(92, 173, 163, 20);
- textField_4.setColumns(10);
-
- textField_3 = new JTextField();
- textField_3.setBounds(92, 142, 163, 20);
- textField_3.setColumns(10);
-
- textField_1 = new JTextField();
- textField_1.setBounds(92, 80, 163, 20);
- textField_1.setColumns(10);
-
- textField_2 = new JTextField();
- textField_2.setBounds(92, 111, 163, 20);
- textField_2.setColumns(10);
- panel_3.setLayout(null);
- panel_3.add(textField_4);
- panel_3.add(textField_3);
- panel_3.add(textField_1);
- panel_3.add(textField_2);
- JButton btnBack = new JButton("Back");
- btnBack.addActionListener(new ActionListener() {
- @SuppressWarnings("deprecation")
- public void actionPerformed(ActionEvent e) {
- panel_3.hide();
- panel.show();
- label.setIcon(null);
- textField_4.setText("");
- textField_3.setText("");
- textField_1.setText("");
- textField_2.setText("");
- rdbtnStepA.setSelected(false);
- rdbtnStepB.setSelected(false);
- rdbtnStepC.setSelected(false);
- view_datasent.setText("");
- view_id.setText("");
- view_package.setText("");
- view_recieved.setText("");
- }
- });
- btnBack.setBounds(75, 25, 89, 23);
- panel_3.add(btnBack);
-
- JButton btnSubmit = new JButton("Submit");
- btnSubmit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- add();
- search(newrakam);
- panel.show();
- panel_3.hide();
- label.setIcon(null);
- textField_4.setText("");
- textField_3.setText("");
- textField_1.setText("");
- textField_2.setText("");
- rdbtnStepA.setSelected(false);
- rdbtnStepB.setSelected(false);
- rdbtnStepC.setSelected(false);
- view_datasent.setText("");
- view_id.setText("");
- view_package.setText("");
- view_recieved.setText("");
- }
- });
- btnSubmit.setBounds(75, 345, 89, 23);
- panel_3.add(btnSubmit);
-
- ButtonGroup group = new ButtonGroup();
-
- rdbtnStepA = new JRadioButton("step A");
- rdbtnStepA.setBounds(55, 225, 109, 23);
- panel_3.add(rdbtnStepA);
-
- rdbtnStepB = new JRadioButton("step B");
- rdbtnStepB.setBounds(55, 247, 109, 23);
- panel_3.add(rdbtnStepB);
-
- rdbtnStepC = new JRadioButton("step B");
- rdbtnStepC.setBounds(55, 273, 109, 23);
- panel_3.add(rdbtnStepC);
-
- group.add(rdbtnStepA);
- group.add(rdbtnStepB);
- group.add(rdbtnStepC);
-
- JLabel lblNewLabel = new JLabel("Package");
- lblNewLabel.setBounds(10, 83, 72, 14);
- panel_3.add(lblNewLabel);
-
- JLabel lblDataSent = new JLabel("Data sent");
- lblDataSent.setBounds(10, 114, 72, 14);
- panel_3.add(lblDataSent);
-
- JLabel lblDataReceived = new JLabel("Data received");
- lblDataReceived.setBounds(10, 145, 72, 14);
- panel_3.add(lblDataReceived);
-
- JLabel lblIdNumber = new JLabel("ID Number");
- lblIdNumber.setBounds(10, 176, 72, 14);
- panel_3.add(lblIdNumber);
- panel = new JPanel();
- panel.setBounds(0, 0, 265, 424);
- getContentPane().add(panel);
- panel.setLayout(null);
-
- tokens = null;
- // //////////////////////////////////////////////////////////////
- storedData = new File("data.txt");
- if(!storedData.exists())
- try {
- storedData.createNewFile();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- tokens = new BarCode(storedData);
- if (tokens == null) {
- fileNotGenerated = true;
- }
- // /////////////////////////////////////////////////////////////
- JButton btnNewBarcode = new JButton("New Barcode");
- btnNewBarcode.addActionListener(new ActionListener() {
- @SuppressWarnings("deprecation")
- public void actionPerformed(ActionEvent e) {
- panel.hide();
- panel_3.show();
- }
- });
- btnNewBarcode.setBounds(42, 42, 177, 23);
- panel.add(btnNewBarcode);
- barCodeText = new JTextField();
- barCodeText.setBounds(42, 184, 177, 20);
- panel.add(barCodeText);
- barCodeText.setColumns(10);
-
- JButton searchButton = new JButton("Enter Barcode");
- searchButton.addActionListener(new ActionListener() {
- String valueOfBarCodeText = null;
-
- public void actionPerformed(ActionEvent e) {
- valueOfBarCodeText = barCodeText.getText();
- if (valueOfBarCodeText != null) {
- try {
- newrakam=Integer.parseInt(valueOfBarCodeText);
- search(newrakam);
- barCodeText.setText("");
- } catch (Exception ex) {
- // this mean that the input was not a number
- System.out.println("wrong entery");
- barCodeText.setText("");
- }
-
- }
- }
- });
-
- searchButton.setBounds(42, 215, 177, 23);
- panel.add(searchButton);
-
- JButton btnExit = new JButton("Exit");
- btnExit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- parent.dispose();
- System.exit(0);
- }
- });
- btnExit.setBounds(42, 328, 177, 23);
- panel.add(btnExit);
-
- JPanel panel_1 = new JPanel();
- panel_1.setBackground(Color.GRAY);
- panel_1.setBounds(264, 0, 252, 424);
- getContentPane().add(panel_1);
- panel_1.setLayout(null);
-
- // this thread waits for input
- th = new Thread(new Runnable() {
- public void run() {
- Scanner sc = new Scanner(System.in);
- while (true) {
- // must check if not in adding case or program is not in
- // error case
- newrakam = sc.nextInt();
- search(newrakam);
- }
- }
- });
- th.start();
-
- label = new JLabel();
- label.setBounds(52, 47, 150, 80);
- panel_1.add(label);
-
- JLabel lblPackage = new JLabel("Package");
- lblPackage.setBounds(10, 193, 60, 14);
- panel_1.add(lblPackage);
-
- JLabel label_1 = new JLabel("Data sent");
- label_1.setBounds(10, 218, 72, 14);
- panel_1.add(label_1);
-
- JLabel label_2 = new JLabel("Data received");
- label_2.setBounds(10, 243, 99, 14);
- panel_1.add(label_2);
-
- JLabel label_3 = new JLabel("ID Number");
- label_3.setBounds(10, 268, 72, 14);
- panel_1.add(label_3);
-
- view_package = new JLabel("");
- view_package.setBounds(114, 193, 128, 14);
- panel_1.add(view_package);
-
- view_datasent = new JLabel("");
- view_datasent.setBounds(114, 218, 128, 14);
- panel_1.add(view_datasent);
-
- view_recieved = new JLabel("");
- view_recieved.setBounds(114, 243, 128, 14);
- panel_1.add(view_recieved);
-
- view_id = new JLabel("");
- view_id.setBounds(114, 268, 128, 14);
- panel_1.add(view_id);
-
- Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
- public void run() {
- save();
- }
-
- }));
-
- show();
- }
-
- /**
- * This function views the barcode image for a given barcode.
- *
- * @param barcode
- */
- void make_bar_code(int barcode) {
-
- BitMatrix bitMatrix = null;
- try {
- bitMatrix = new Code128Writer().encode(String.valueOf(barcode),
- BarcodeFormat.CODE_128, 150, 80, null);
- image = MatrixToImageWriter.toBufferedImage(bitMatrix);
- } catch (WriterException e) {
- e.printStackTrace();
- }
- label.setIcon(new ImageIcon(image));
- }
-
- /**
- * This function search for barcode in files If found an element view it
- * else open a window to register new element
- *
- * @param barcode
- * @throws FileNotFoundException
- */
- private void search(int barcode) {
- boolean found = false;
- int result = tokens.FindWithGeneratedCode(barcode);
- if (result == -1) {
- found = false;
- } else {
- found = true;
- }
- if (found) {
- view(result);
- } else {
- view_datasent.setText("");
- view_id.setText("");
- view_package.setText("");
- view_recieved.setText("");
- label.setIcon(null);
- make_bar_code(barcode);
- panel.hide();
- panel_3.show();
- }
- }
-
- private void add() {
- System.out.println(newrakam);
- Data temp = new Data();
- String choice = null;
- temp.setGeneratedNumber(newrakam);
- temp.setPackageData(textField_1.getText());
- temp.setDataSent(textField_2.getText());
- temp.setRecievedData(textField_3.getText());
- temp.setIDNumber(Integer.parseInt(textField_4.getText()));
- choice = getSellectedButton();
- temp.setChoice(choice);
- tokens.addToList(temp);
- }
-
- private String getSellectedButton() {
- String value = null;
- if (rdbtnStepA.isSelected()) {
- value = "Step A";
- } else if (rdbtnStepB.isSelected()) {
- value = "Step B";
- } else if (rdbtnStepC.isSelected()) {
- value = "Step C";
- }
- return value;
- }
-
- void save(){
- ArrayList allData = tokens.getTokens();
- try {
- PrintWriter writer = new PrintWriter(storedData);
- for(int i = 0; i < allData.size(); i++){
- writer.println(allData.get(i).getGeneratedNumber());
- writer.println(allData.get(i).getPackageData());
- writer.println(allData.get(i).getDataSent());
- writer.println(allData.get(i).getRecievedData());
- writer.println(allData.get(i).getIDNumber());
- writer.println(allData.get(i).getChoice());
- }
- writer.flush();writer.close();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- /**
- * This function initialzie the view panel with the element data of the
- * given barcode.
- *
- * @param barcode
- */
- private void view(int res) {
- make_bar_code(tokens.getTokens().get(res).getGeneratedNumber());
- view_package.setText(tokens.getTokens().get(res).getPackageData());
- view_id.setText(String.valueOf(tokens.getTokens().get(res).getIDNumber()));
- view_datasent.setText(tokens.getTokens().get(res).getDataSent());
- view_recieved.setText(tokens.getTokens().get(res).getRecievedData());
- }
-}
+package barcode.reader;
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Scanner;
+
+import javax.swing.ButtonGroup;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.JTextField;
+
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.WriterException;
+import com.google.zxing.client.j2se.MatrixToImageWriter;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.oned.Code128Writer;
+
+public class BarcodeReader extends JFrame {
+ private JTextField barCodeText;
+ private int newrakam;
+ private BufferedImage image;
+ private JFrame parent;
+ private JPanel panel;
+ private JPanel panel_3;
+
+ /*
+ * User input fields
+ */
+ private JTextField textField_1;
+ private JTextField textField_2;
+ private JTextField textField_3;
+ private JTextField textField_4;
+
+ private JLabel label;
+ private JRadioButton rdbtnStepA;
+ private JRadioButton rdbtnStepB;
+ private JRadioButton rdbtnStepC;
+ private JLabel view_package;
+ private JLabel view_datasent;
+ private JLabel view_recieved;
+ private JLabel view_id;
+
+ /*
+ * Thread waiting for input from barcode reader
+ */
+ private Thread th;
+
+ private BarCode tokens;
+ private File storedData;
+ private boolean fileNotGenerated;
+
+ public static void main(String[] args) throws FileNotFoundException {
+ new BarcodeReader();
+ }
+
+ @SuppressWarnings("deprecation")
+ BarcodeReader() throws FileNotFoundException {
+ storedData = null;
+
+ setSize(532, 462);
+ setDefaultCloseOperation(EXIT_ON_CLOSE);
+ getContentPane().setLayout(null);
+ parent = this;
+
+ panel_3 = new JPanel();
+ panel_3.setBounds(0, 0, 265, 424);
+ getContentPane().add(panel_3);
+ panel_3.hide();
+
+ textField_4 = new JTextField();
+ textField_4.setBounds(92, 173, 163, 20);
+ textField_4.setColumns(10);
+
+ textField_3 = new JTextField();
+ textField_3.setBounds(92, 142, 163, 20);
+ textField_3.setColumns(10);
+
+ textField_1 = new JTextField();
+ textField_1.setBounds(92, 80, 163, 20);
+ textField_1.setColumns(10);
+
+ textField_2 = new JTextField();
+ textField_2.setBounds(92, 111, 163, 20);
+ textField_2.setColumns(10);
+ panel_3.setLayout(null);
+ panel_3.add(textField_4);
+ panel_3.add(textField_3);
+ panel_3.add(textField_1);
+ panel_3.add(textField_2);
+ JButton btnBack = new JButton("Back");
+ btnBack.addActionListener(new ActionListener() {
+ @SuppressWarnings("deprecation")
+ public void actionPerformed(ActionEvent e) {
+ panel_3.hide();
+ panel.show();
+ label.setIcon(null);
+ textField_4.setText("");
+ textField_3.setText("");
+ textField_1.setText("");
+ textField_2.setText("");
+ rdbtnStepA.setSelected(false);
+ rdbtnStepB.setSelected(false);
+ rdbtnStepC.setSelected(false);
+ view_datasent.setText("");
+ view_id.setText("");
+ view_package.setText("");
+ view_recieved.setText("");
+ }
+ });
+ btnBack.setBounds(75, 25, 89, 23);
+ panel_3.add(btnBack);
+
+ JButton btnSubmit = new JButton("Submit");
+ btnSubmit.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ add();
+ search(newrakam);
+ panel.show();
+ panel_3.hide();
+ label.setIcon(null);
+ textField_4.setText("");
+ textField_3.setText("");
+ textField_1.setText("");
+ textField_2.setText("");
+ rdbtnStepA.setSelected(false);
+ rdbtnStepB.setSelected(false);
+ rdbtnStepC.setSelected(false);
+ view_datasent.setText("");
+ view_id.setText("");
+ view_package.setText("");
+ view_recieved.setText("");
+ }
+ });
+ btnSubmit.setBounds(75, 345, 89, 23);
+ panel_3.add(btnSubmit);
+
+ ButtonGroup group = new ButtonGroup();
+
+ rdbtnStepA = new JRadioButton("step A");
+ rdbtnStepA.setBounds(55, 225, 109, 23);
+ panel_3.add(rdbtnStepA);
+
+ rdbtnStepB = new JRadioButton("step B");
+ rdbtnStepB.setBounds(55, 247, 109, 23);
+ panel_3.add(rdbtnStepB);
+
+ rdbtnStepC = new JRadioButton("step B");
+ rdbtnStepC.setBounds(55, 273, 109, 23);
+ panel_3.add(rdbtnStepC);
+
+ group.add(rdbtnStepA);
+ group.add(rdbtnStepB);
+ group.add(rdbtnStepC);
+
+ JLabel lblNewLabel = new JLabel("Package");
+ lblNewLabel.setBounds(10, 83, 72, 14);
+ panel_3.add(lblNewLabel);
+
+ JLabel lblDataSent = new JLabel("Data sent");
+ lblDataSent.setBounds(10, 114, 72, 14);
+ panel_3.add(lblDataSent);
+
+ JLabel lblDataReceived = new JLabel("Data received");
+ lblDataReceived.setBounds(10, 145, 72, 14);
+ panel_3.add(lblDataReceived);
+
+ JLabel lblIdNumber = new JLabel("ID Number");
+ lblIdNumber.setBounds(10, 176, 72, 14);
+ panel_3.add(lblIdNumber);
+ panel = new JPanel();
+ panel.setBounds(0, 0, 265, 424);
+ getContentPane().add(panel);
+ panel.setLayout(null);
+
+ tokens = null;
+ // //////////////////////////////////////////////////////////////
+ storedData = new File("data.txt");
+ if(!storedData.exists())
+ try {
+ storedData.createNewFile();
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ tokens = new BarCode(storedData);
+ if (tokens == null) {
+ fileNotGenerated = true;
+ }
+ // /////////////////////////////////////////////////////////////
+ JButton btnNewBarcode = new JButton("New Barcode");
+ btnNewBarcode.addActionListener(new ActionListener() {
+ @SuppressWarnings("deprecation")
+ public void actionPerformed(ActionEvent e) {
+ panel.hide();
+ panel_3.show();
+ }
+ });
+ btnNewBarcode.setBounds(42, 42, 177, 23);
+ panel.add(btnNewBarcode);
+ barCodeText = new JTextField();
+ barCodeText.setBounds(42, 184, 177, 20);
+ panel.add(barCodeText);
+ barCodeText.setColumns(10);
+
+ JButton searchButton = new JButton("Enter Barcode");
+ searchButton.addActionListener(new ActionListener() {
+ String valueOfBarCodeText = null;
+
+ public void actionPerformed(ActionEvent e) {
+ valueOfBarCodeText = barCodeText.getText();
+ if (valueOfBarCodeText != null) {
+ try {
+ newrakam=Integer.parseInt(valueOfBarCodeText);
+ search(newrakam);
+ barCodeText.setText("");
+ } catch (Exception ex) {
+ // this mean that the input was not a number
+ System.out.println("wrong entery");
+ barCodeText.setText("");
+ }
+
+ }
+ }
+ });
+
+ searchButton.setBounds(42, 215, 177, 23);
+ panel.add(searchButton);
+
+ JButton btnExit = new JButton("Exit");
+ btnExit.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ parent.dispose();
+ System.exit(0);
+ }
+ });
+ btnExit.setBounds(42, 328, 177, 23);
+ panel.add(btnExit);
+
+ JPanel panel_1 = new JPanel();
+ panel_1.setBackground(Color.GRAY);
+ panel_1.setBounds(264, 0, 252, 424);
+ getContentPane().add(panel_1);
+ panel_1.setLayout(null);
+
+ // this thread waits for input
+ th = new Thread(new Runnable() {
+ public void run() {
+ Scanner sc = new Scanner(System.in);
+ while (true) {
+ // must check if not in adding case or program is not in
+ // error case
+ newrakam = sc.nextInt();
+ search(newrakam);
+ }
+ }
+ });
+ th.start();
+
+ label = new JLabel();
+ label.setBounds(52, 47, 150, 80);
+ panel_1.add(label);
+
+ JLabel lblPackage = new JLabel("Package");
+ lblPackage.setBounds(10, 193, 60, 14);
+ panel_1.add(lblPackage);
+
+ JLabel label_1 = new JLabel("Data sent");
+ label_1.setBounds(10, 218, 72, 14);
+ panel_1.add(label_1);
+
+ JLabel label_2 = new JLabel("Data received");
+ label_2.setBounds(10, 243, 99, 14);
+ panel_1.add(label_2);
+
+ JLabel label_3 = new JLabel("ID Number");
+ label_3.setBounds(10, 268, 72, 14);
+ panel_1.add(label_3);
+
+ view_package = new JLabel("");
+ view_package.setBounds(114, 193, 128, 14);
+ panel_1.add(view_package);
+
+ view_datasent = new JLabel("");
+ view_datasent.setBounds(114, 218, 128, 14);
+ panel_1.add(view_datasent);
+
+ view_recieved = new JLabel("");
+ view_recieved.setBounds(114, 243, 128, 14);
+ panel_1.add(view_recieved);
+
+ view_id = new JLabel("");
+ view_id.setBounds(114, 268, 128, 14);
+ panel_1.add(view_id);
+
+ Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
+ public void run() {
+ save();
+ }
+
+ }));
+
+ show();
+ }
+
+ /**
+ * This function views the barcode image for a given barcode.
+ *
+ * @param barcode
+ */
+ void make_bar_code(int barcode) {
+
+ BitMatrix bitMatrix = null;
+ try {
+ bitMatrix = new Code128Writer().encode(String.valueOf(barcode),
+ BarcodeFormat.CODE_128, 150, 80, null);
+ image = MatrixToImageWriter.toBufferedImage(bitMatrix);
+ } catch (WriterException e) {
+ e.printStackTrace();
+ }
+ label.setIcon(new ImageIcon(image));
+ }
+
+ /**
+ * This function search for barcode in files If found an element view it
+ * else open a window to register new element
+ *
+ * @param barcode
+ * @throws FileNotFoundException
+ */
+ private void search(int barcode) {
+ boolean found = false;
+ int result = tokens.FindWithGeneratedCode(barcode);
+ if (result == -1) {
+ found = false;
+ } else {
+ found = true;
+ }
+ if (found) {
+ view(result);
+ } else {
+ view_datasent.setText("");
+ view_id.setText("");
+ view_package.setText("");
+ view_recieved.setText("");
+ label.setIcon(null);
+ make_bar_code(barcode);
+ panel.hide();
+ panel_3.show();
+ }
+ }
+
+ private void add() {
+ System.out.println(newrakam);
+ Data temp = new Data();
+ String choice = null;
+ temp.setGeneratedNumber(newrakam);
+ temp.setPackageData(textField_1.getText());
+ temp.setDataSent(textField_2.getText());
+ temp.setRecievedData(textField_3.getText());
+ temp.setIDNumber(Integer.parseInt(textField_4.getText()));
+ choice = getSellectedButton();
+ temp.setChoice(choice);
+ tokens.addToList(temp);
+ }
+
+ private String getSellectedButton() {
+ String value = null;
+ if (rdbtnStepA.isSelected()) {
+ value = "Step A";
+ } else if (rdbtnStepB.isSelected()) {
+ value = "Step B";
+ } else if (rdbtnStepC.isSelected()) {
+ value = "Step C";
+ }
+ return value;
+ }
+
+ void save(){
+ ArrayList allData = tokens.getTokens();
+ try {
+ PrintWriter writer = new PrintWriter(storedData);
+ for(int i = 0; i < allData.size(); i++){
+ writer.println(allData.get(i).getGeneratedNumber());
+ writer.println(allData.get(i).getPackageData());
+ writer.println(allData.get(i).getDataSent());
+ writer.println(allData.get(i).getRecievedData());
+ writer.println(allData.get(i).getIDNumber());
+ writer.println(allData.get(i).getChoice());
+ }
+ writer.flush();writer.close();
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * This function initialzie the view panel with the element data of the
+ * given barcode.
+ *
+ * @param barcode
+ */
+ private void view(int res) {
+ make_bar_code(tokens.getTokens().get(res).getGeneratedNumber());
+ view_package.setText(tokens.getTokens().get(res).getPackageData());
+ view_id.setText(String.valueOf(tokens.getTokens().get(res).getIDNumber()));
+ view_datasent.setText(tokens.getTokens().get(res).getDataSent());
+ view_recieved.setText(tokens.getTokens().get(res).getRecievedData());
+ }
+
+
+}
diff --git a/src/barcode/reader/Data.java b/src/barcode/reader/Data.java
new file mode 100644
index 0000000..b1f0c24
--- /dev/null
+++ b/src/barcode/reader/Data.java
@@ -0,0 +1,52 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package barcode.reader;
+public class Data {
+
+ private int generatedNumber;
+ private String packageData;
+ private String dataSent;
+ private String recievedData;
+ private int IDNumber;
+ private String choice;
+
+ public int getGeneratedNumber() {
+ return generatedNumber;
+ }
+ public void setGeneratedNumber(int generatedNumber) {
+ this.generatedNumber = generatedNumber;
+ }
+ public String getPackageData() {
+ return packageData;
+ }
+ public void setPackageData(String packageData) {
+ this.packageData = packageData;
+ }
+ public String getDataSent() {
+ return dataSent;
+ }
+ public void setDataSent(String dataSent) {
+ this.dataSent = dataSent;
+ }
+ public String getRecievedData() {
+ return recievedData;
+ }
+ public void setRecievedData(String recievedData) {
+ this.recievedData = recievedData;
+ }
+ public int getIDNumber() {
+ return IDNumber;
+ }
+ public void setIDNumber(int iDNumber) {
+ IDNumber = iDNumber;
+ }
+ public String getChoice() {
+ return choice;
+ }
+ public void setChoice(String choice) {
+ this.choice = choice;
+ }
+}
\ No newline at end of file