Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
COM4001M_Adam_Routledge
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
adam.routledge
COM4001M_Adam_Routledge
Commits
fa5c4206
Commit
fa5c4206
authored
Dec 20, 2020
by
addya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First commit. Not yet managed to pass variables between JFrame forms.
parents
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1369 additions
and
0 deletions
+1369
-0
pom.xml
SelfCheckout/pom.xml
+14
-0
CheckOut.form
SelfCheckout/src/main/java/CheckOut.form
+386
-0
CheckOut.java
SelfCheckout/src/main/java/CheckOut.java
+399
-0
SelectProducts.form
SelfCheckout/src/main/java/SelectProducts.form
+239
-0
SelectProducts.java
SelfCheckout/src/main/java/SelectProducts.java
+331
-0
No files found.
SelfCheckout/pom.xml
0 → 100644
View file @
fa5c4206
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.mycompany
</groupId>
<artifactId>
SelfCheckout
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<packaging>
jar
</packaging>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<maven.compiler.source>
15
</maven.compiler.source>
<maven.compiler.target>
15
</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
SelfCheckout/src/main/java/CheckOut.form
0 → 100644
View file @
fa5c4206
<?xml version="1.0" encoding="UTF-8" ?>
<Form
version=
"1.3"
maxVersion=
"1.9"
type=
"org.netbeans.modules.form.forminfo.JFrameFormInfo"
>
<NonVisualComponents>
<Component
class=
"javax.swing.JLabel"
name=
"jLabel1"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"36"
style=
"1"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Select Products"
/>
</Properties>
</Component>
</NonVisualComponents>
<Properties>
<Property
name=
"defaultCloseOperation"
type=
"int"
value=
"3"
/>
<Property
name=
"background"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty
name=
"formSizePolicy"
type=
"int"
value=
"1"
/>
<SyntheticProperty
name=
"generateCenter"
type=
"boolean"
value=
"false"
/>
</SyntheticProperties>
<AuxValues>
<AuxValue
name=
"FormSettings_autoResourcing"
type=
"java.lang.Integer"
value=
"0"
/>
<AuxValue
name=
"FormSettings_autoSetComponentName"
type=
"java.lang.Boolean"
value=
"false"
/>
<AuxValue
name=
"FormSettings_generateFQN"
type=
"java.lang.Boolean"
value=
"true"
/>
<AuxValue
name=
"FormSettings_generateMnemonicsCode"
type=
"java.lang.Boolean"
value=
"false"
/>
<AuxValue
name=
"FormSettings_i18nAutoMode"
type=
"java.lang.Boolean"
value=
"false"
/>
<AuxValue
name=
"FormSettings_layoutCodeTarget"
type=
"java.lang.Integer"
value=
"1"
/>
<AuxValue
name=
"FormSettings_listenerGenerationStyle"
type=
"java.lang.Integer"
value=
"0"
/>
<AuxValue
name=
"FormSettings_variablesLocal"
type=
"java.lang.Boolean"
value=
"false"
/>
<AuxValue
name=
"FormSettings_variablesModifier"
type=
"java.lang.Integer"
value=
"2"
/>
</AuxValues>
<Layout>
<DimensionLayout
dim=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"jPanel1"
alignment=
"0"
pref=
"615"
max=
"32767"
attributes=
"0"
/>
</Group>
</DimensionLayout>
<DimensionLayout
dim=
"1"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"jPanel1"
min=
"-2"
pref=
"378"
max=
"-2"
attributes=
"0"
/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container
class=
"javax.swing.JPanel"
name=
"jPanel1"
>
<Properties>
<Property
name=
"background"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"cc"
green=
"0"
red=
"0"
type=
"rgb"
/>
</Property>
<Property
name=
"preferredSize"
type=
"java.awt.Dimension"
editor=
"org.netbeans.beaninfo.editors.DimensionEditor"
>
<Dimension
value=
"[700, 360]"
/>
</Property>
</Properties>
<Layout>
<DimensionLayout
dim=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
attributes=
"0"
>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"jLabel2"
alignment=
"0"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<Component
id=
"jScrollPane1"
min=
"-2"
pref=
"156"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"separate"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"lbl5"
alignment=
"0"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lbl3"
alignment=
"0"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lbl4"
alignment=
"0"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lbl7"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
alignment=
"0"
groupAlignment=
"1"
max=
"-2"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"1"
attributes=
"0"
>
<Component
id=
"lbl2"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"162"
max=
"-2"
attributes=
"0"
/>
</Group>
<Group
type=
"102"
alignment=
"1"
attributes=
"0"
>
<Component
id=
"lblChance"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"separate"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"btnDraw"
min=
"-2"
pref=
"73"
max=
"-2"
attributes=
"0"
/>
</Group>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<Component
id=
"lbl1"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"32767"
attributes=
"0"
/>
<Component
id=
"lblYouGot"
min=
"-2"
pref=
"121"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
</Group>
</Group>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"lblBasket"
min=
"-2"
pref=
"127"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lblTotal"
alignment=
"0"
min=
"-2"
pref=
"127"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"lblDiscount"
min=
"-2"
pref=
"127"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lbl£"
alignment=
"1"
min=
"-2"
pref=
"18"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<Component
id=
"txfPayment"
min=
"-2"
pref=
"134"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"btnPay"
min=
"-2"
pref=
"66"
max=
"-2"
attributes=
"0"
/>
</Group>
<Component
id=
"lblErrorMessage"
min=
"-2"
pref=
"150"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
</Group>
<EmptySpace
min=
"194"
pref=
"133"
max=
"32767"
attributes=
"0"
/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout
dim=
"1"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"1"
attributes=
"0"
>
<Group
type=
"102"
attributes=
"0"
>
<Component
id=
"lblErrorMessage"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"unrelated"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"3"
attributes=
"0"
>
<Component
id=
"txfPayment"
alignment=
"3"
min=
"-2"
pref=
"30"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"btnPay"
alignment=
"3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
<Group
type=
"102"
attributes=
"0"
>
<Component
id=
"jLabel2"
min=
"-2"
pref=
"36"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"separate"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"jScrollPane1"
alignment=
"0"
min=
"-2"
pref=
"224"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<Group
type=
"103"
groupAlignment=
"3"
attributes=
"0"
>
<Component
id=
"lblChance"
alignment=
"3"
min=
"-2"
pref=
"38"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"btnDraw"
alignment=
"3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"3"
attributes=
"0"
>
<Component
id=
"lbl1"
alignment=
"3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lblYouGot"
alignment=
"3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lbl2"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lbl3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lbl4"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lbl5"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"3"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lbl7"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
attributes=
"0"
>
<EmptySpace
min=
"-2"
pref=
"20"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"3"
attributes=
"0"
>
<Component
id=
"lblBasket"
alignment=
"3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lblDiscount"
alignment=
"3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lblTotal"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"11"
max=
"-2"
attributes=
"0"
/>
</Group>
<Group
type=
"102"
alignment=
"1"
attributes=
"0"
>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lbl£"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
</Group>
</Group>
<EmptySpace
max=
"32767"
attributes=
"0"
/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component
class=
"javax.swing.JLabel"
name=
"jLabel2"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"36"
style=
"1"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Checkout"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"lblChance"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Random Discount Draw"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"lbl1"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"1>>>10% off"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"lbl2"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"2>>>20% off"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"lbl3"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"3>>>30% off"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"lbl4"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"4>>>40% off"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"lbl5"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"5>>>50% off"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"lblYouGot"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"22"
style=
"3"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"You got"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JButton"
name=
"btnDraw"
>
<Properties>
<Property
name=
"background"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Draw!"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"btnDrawActionPerformed"
/>
</Events>
</Component>
<Container
class=
"javax.swing.JScrollPane"
name=
"jScrollPane1"
>
<AuxValues>
<AuxValue
name=
"autoScrollPane"
type=
"java.lang.Boolean"
value=
"true"
/>
</AuxValues>
<Layout
class=
"org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"
/>
<SubComponents>
<Component
class=
"javax.swing.JTextArea"
name=
"txaBasket"
>
<Properties>
<Property
name=
"columns"
type=
"int"
value=
"20"
/>
<Property
name=
"rows"
type=
"int"
value=
"5"
/>
</Properties>
</Component>
</SubComponents>
</Container>
<Component
class=
"javax.swing.JLabel"
name=
"lblBasket"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Basket: £0.0"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"lblDiscount"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Discount: "
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"lblTotal"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Total:"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JButton"
name=
"btnPay"
>
<Properties>
<Property
name=
"background"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Pay"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"btnPayActionPerformed"
/>
</Events>
</Component>
<Component
class=
"javax.swing.JTextField"
name=
"txfPayment"
>
<Properties>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Enter payment amount"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"txfPaymentActionPerformed"
/>
</Events>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"lbl7"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"6-10>>>£5 off"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"lblErrorMessage"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"14"
style=
"2"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
".........."
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"lbl£"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"20"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"£"
/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>
SelfCheckout/src/main/java/CheckOut.java
0 → 100644
View file @
fa5c4206
import
java.util.Random
;
import
java.text.DecimalFormat
;
import
java.math.RoundingMode
;
/*
* 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.
*/
/**
*
* @author addya
*/
public
class
CheckOut
extends
javax
.
swing
.
JFrame
{
/**
* Creates new form CheckOut
*/
public
CheckOut
()
{
initComponents
();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings
(
"unchecked"
)
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private
void
initComponents
()
{
jLabel1
=
new
javax
.
swing
.
JLabel
();
jPanel1
=
new
javax
.
swing
.
JPanel
();
jLabel2
=
new
javax
.
swing
.
JLabel
();
lblChance
=
new
javax
.
swing
.
JLabel
();
lbl1
=
new
javax
.
swing
.
JLabel
();
lbl2
=
new
javax
.
swing
.
JLabel
();
lbl3
=
new
javax
.
swing
.
JLabel
();
lbl4
=
new
javax
.
swing
.
JLabel
();
lbl5
=
new
javax
.
swing
.
JLabel
();
lblYouGot
=
new
javax
.
swing
.
JLabel
();
btnDraw
=
new
javax
.
swing
.
JButton
();
jScrollPane1
=
new
javax
.
swing
.
JScrollPane
();
txaBasket
=
new
javax
.
swing
.
JTextArea
();
lblBasket
=
new
javax
.
swing
.
JLabel
();
lblDiscount
=
new
javax
.
swing
.
JLabel
();
lblTotal
=
new
javax
.
swing
.
JLabel
();
btnPay
=
new
javax
.
swing
.
JButton
();
txfPayment
=
new
javax
.
swing
.
JTextField
();
lbl7
=
new
javax
.
swing
.
JLabel
();
lblErrorMessage
=
new
javax
.
swing
.
JLabel
();
lbl
£
=
new
javax
.
swing
.
JLabel
();
jLabel1
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
1
,
36
));
// NOI18N
jLabel1
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
jLabel1
.
setText
(
"Select Products"
);
setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
setBackground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
jPanel1
.
setBackground
(
new
java
.
awt
.
Color
(
0
,
0
,
204
));
jPanel1
.
setPreferredSize
(
new
java
.
awt
.
Dimension
(
700
,
360
));
jLabel2
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
1
,
36
));
// NOI18N
jLabel2
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
jLabel2
.
setText
(
"Checkout"
);
lblChance
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
18
));
// NOI18N
lblChance
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lblChance
.
setText
(
"Random Discount Draw"
);
lbl1
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
18
));
// NOI18N
lbl1
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lbl1
.
setText
(
"1>>>10% off"
);
lbl2
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
18
));
// NOI18N
lbl2
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lbl2
.
setText
(
"2>>>20% off"
);
lbl3
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
18
));
// NOI18N
lbl3
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lbl3
.
setText
(
"3>>>30% off"
);
lbl4
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
18
));
// NOI18N
lbl4
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lbl4
.
setText
(
"4>>>40% off"
);
lbl5
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
18
));
// NOI18N
lbl5
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lbl5
.
setText
(
"5>>>50% off"
);
lblYouGot
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
3
,
22
));
// NOI18N
lblYouGot
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lblYouGot
.
setText
(
"You got"
);
btnDraw
.
setBackground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
btnDraw
.
setText
(
"Draw!"
);
btnDraw
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
btnDrawActionPerformed
(
evt
);
}
});
txaBasket
.
setColumns
(
20
);
txaBasket
.
setRows
(
5
);
jScrollPane1
.
setViewportView
(
txaBasket
);
lblBasket
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
18
));
// NOI18N
lblBasket
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lblBasket
.
setText
(
"Basket: £0.0"
);
lblDiscount
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
18
));
// NOI18N
lblDiscount
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lblDiscount
.
setText
(
"Discount: "
);
lblTotal
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
18
));
// NOI18N
lblTotal
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lblTotal
.
setText
(
"Total:"
);
btnPay
.
setBackground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
btnPay
.
setText
(
"Pay"
);
btnPay
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
btnPayActionPerformed
(
evt
);
}
});
txfPayment
.
setText
(
"Enter payment amount"
);
txfPayment
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
txfPaymentActionPerformed
(
evt
);
}
});
lbl7
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
18
));
// NOI18N
lbl7
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lbl7
.
setText
(
"6-10>>>£5 off"
);
lblErrorMessage
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
2
,
14
));
// NOI18N
lblErrorMessage
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lblErrorMessage
.
setText
(
".........."
);
lbl
£
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
20
));
// NOI18N
lbl
£
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lbl
£
.
setText
(
"£"
);
javax
.
swing
.
GroupLayout
jPanel1Layout
=
new
javax
.
swing
.
GroupLayout
(
jPanel1
);
jPanel1
.
setLayout
(
jPanel1Layout
);
jPanel1Layout
.
setHorizontalGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addComponent
(
jLabel2
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addComponent
(
jScrollPane1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
156
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
18
,
18
,
18
)
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addComponent
(
lbl5
)
.
addComponent
(
lbl3
)
.
addComponent
(
lbl4
)
.
addComponent
(
lbl7
)
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
false
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addComponent
(
lbl2
)
.
addGap
(
162
,
162
,
162
))
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addComponent
(
lblChance
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
btnDraw
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
73
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
,
jPanel1Layout
.
createSequentialGroup
()
.
addComponent
(
lbl1
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
)
.
addComponent
(
lblYouGot
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
121
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)))))
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addComponent
(
lblBasket
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
127
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
lblTotal
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
127
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addComponent
(
lblDiscount
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
127
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
lbl
£
,
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
18
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addComponent
(
txfPayment
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
134
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
btnPay
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
66
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addComponent
(
lblErrorMessage
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
150
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))))
.
addGap
(
133
,
133
,
Short
.
MAX_VALUE
))
);
jPanel1Layout
.
setVerticalGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addComponent
(
lblErrorMessage
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
UNRELATED
)
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
txfPayment
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
30
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
btnPay
)))
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addComponent
(
jLabel2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
36
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
18
,
18
,
18
)
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addComponent
(
jScrollPane1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
224
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
lblChance
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
38
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
btnDraw
))
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
lbl1
)
.
addComponent
(
lblYouGot
))
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
lbl2
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
lbl3
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
lbl4
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
lbl5
)
.
addGap
(
3
,
3
,
3
)
.
addComponent
(
lbl7
)))
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addGap
(
20
,
20
,
20
)
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
lblBasket
)
.
addComponent
(
lblDiscount
))
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
lblTotal
)
.
addGap
(
11
,
11
,
11
))
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
jPanel1Layout
.
createSequentialGroup
()
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
lbl
£
)))))
.
addContainerGap
(
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
))
);
javax
.
swing
.
GroupLayout
layout
=
new
javax
.
swing
.
GroupLayout
(
getContentPane
());
getContentPane
().
setLayout
(
layout
);
layout
.
setHorizontalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addComponent
(
jPanel1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
615
,
Short
.
MAX_VALUE
)
);
layout
.
setVerticalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addComponent
(
jPanel1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
378
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
);
pack
();
}
// </editor-fold>//GEN-END:initComponents
public
static
double
calcTotal
(
double
basketCost
,
double
discountPer
,
int
r
){
//this calculation works out the discount
double
totalCost
=
basketCost
*
discountPer
;
//if the draw number was above 5 then it is £5 off
if
(
r
>
5
){
totalCost
=
totalCost
-
5
;
}
//if the £5 discount brought the total below 0 (a negative number)
if
(
totalCost
<
0
){
//the total is made to be 0
totalCost
=
0
;
}
return
totalCost
;
}
public
static
double
shortenValue
(
double
value
){
DecimalFormat
df
=
new
DecimalFormat
(
"0.00"
);
double
shortened
=
Double
.
parseDouble
(
df
.
format
(
value
));
return
shortened
;
}
private
void
btnPayActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_btnPayActionPerformed
// TODO add your handling code here:
}
//GEN-LAST:event_btnPayActionPerformed
private
void
btnDrawActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_btnDrawActionPerformed
// TODO add your handling code here:
Random
rand
=
new
Random
();
//a random integer from 1-10 is used to pick the random discount
//rand.nextInt(9) would pick a number from 0-9, so we need to add 1
//this is because the random draw is from 1-10
int
r
=
rand
.
nextInt
(
9
)+
1
;
String
discountStr
=
""
;
double
discountPer
=
1
;
lblYouGot
.
setText
(
"You got "
+
r
+
"!"
);
//we disable use of the button so the user can't draw more than once
//btnDraw.setEnabled(false);
//the random number from 1-10 decides how much discount is received
switch
(
r
){
//if the variable r is 1 then a 10% discount is applied
case
1
:
discountStr
=
"10%"
;
discountPer
=
0.9
;
break
;
//if the variable r is 2 then a 20% discount is applied
case
2
:
discountStr
=
"20%"
;
discountPer
=
0.8
;
break
;
//if the variable r is 3 then a 30% discount is applied
case
3
:
discountStr
=
"30%"
;
discountPer
=
0.7
;
break
;
//if the variable r is 4 then a 40% discount is applied
case
4
:
discountStr
=
"40%"
;
discountPer
=
0.6
;
break
;
//if the variable r is 5 then a 50% discount is applied
case
5
:
discountStr
=
"50%"
;
discountPer
=
0.5
;
break
;
//if the variable r is 6, 7, 8, 9 or 10 then a £5 discount is applied
case
6
:
case
7
:
case
8
:
case
9
:
case
10
:
discountStr
=
"£5"
;
}
lblDiscount
.
setText
(
"Discount: "
+
discountStr
);
double
totalCost
=
calcTotal
(
11.11
,
discountPer
,
r
);
totalCost
=
109.777
;
totalCost
=
shortenValue
(
totalCost
);
lblTotal
.
setText
(
"Total: "
+
totalCost
);
}
//GEN-LAST:event_btnDrawActionPerformed
private
void
txfPaymentActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_txfPaymentActionPerformed
// TODO add your handling code here:
}
//GEN-LAST:event_txfPaymentActionPerformed
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
args
[])
{
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try
{
for
(
javax
.
swing
.
UIManager
.
LookAndFeelInfo
info
:
javax
.
swing
.
UIManager
.
getInstalledLookAndFeels
())
{
if
(
"Nimbus"
.
equals
(
info
.
getName
()))
{
javax
.
swing
.
UIManager
.
setLookAndFeel
(
info
.
getClassName
());
break
;
}
}
}
catch
(
ClassNotFoundException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
CheckOut
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
InstantiationException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
CheckOut
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
IllegalAccessException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
CheckOut
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
javax
.
swing
.
UnsupportedLookAndFeelException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
CheckOut
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
//</editor-fold>
/* Create and display the form */
java
.
awt
.
EventQueue
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
CheckOut
().
setVisible
(
true
);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private
javax
.
swing
.
JButton
btnDraw
;
private
javax
.
swing
.
JButton
btnPay
;
private
javax
.
swing
.
JLabel
jLabel1
;
private
javax
.
swing
.
JLabel
jLabel2
;
private
javax
.
swing
.
JPanel
jPanel1
;
private
javax
.
swing
.
JScrollPane
jScrollPane1
;
private
javax
.
swing
.
JLabel
lbl1
;
private
javax
.
swing
.
JLabel
lbl2
;
private
javax
.
swing
.
JLabel
lbl3
;
private
javax
.
swing
.
JLabel
lbl4
;
private
javax
.
swing
.
JLabel
lbl5
;
private
javax
.
swing
.
JLabel
lbl7
;
private
javax
.
swing
.
JLabel
lblBasket
;
private
javax
.
swing
.
JLabel
lblChance
;
private
javax
.
swing
.
JLabel
lblDiscount
;
private
javax
.
swing
.
JLabel
lblErrorMessage
;
private
javax
.
swing
.
JLabel
lblTotal
;
private
javax
.
swing
.
JLabel
lblYouGot
;
private
javax
.
swing
.
JLabel
lbl
£
;
private
javax
.
swing
.
JTextArea
txaBasket
;
private
javax
.
swing
.
JTextField
txfPayment
;
// End of variables declaration//GEN-END:variables
}
SelfCheckout/src/main/java/SelectProducts.form
0 → 100644
View file @
fa5c4206
<?xml version="1.0" encoding="UTF-8" ?>
<Form
version=
"1.3"
maxVersion=
"1.9"
type=
"org.netbeans.modules.form.forminfo.JFrameFormInfo"
>
<Properties>
<Property
name=
"defaultCloseOperation"
type=
"int"
value=
"3"
/>
<Property
name=
"background"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"cc"
green=
"0"
red=
"0"
type=
"rgb"
/>
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty
name=
"formSizePolicy"
type=
"int"
value=
"1"
/>
<SyntheticProperty
name=
"generateCenter"
type=
"boolean"
value=
"false"
/>
</SyntheticProperties>
<AuxValues>
<AuxValue
name=
"FormSettings_autoResourcing"
type=
"java.lang.Integer"
value=
"0"
/>
<AuxValue
name=
"FormSettings_autoSetComponentName"
type=
"java.lang.Boolean"
value=
"false"
/>
<AuxValue
name=
"FormSettings_generateFQN"
type=
"java.lang.Boolean"
value=
"true"
/>
<AuxValue
name=
"FormSettings_generateMnemonicsCode"
type=
"java.lang.Boolean"
value=
"false"
/>
<AuxValue
name=
"FormSettings_i18nAutoMode"
type=
"java.lang.Boolean"
value=
"false"
/>
<AuxValue
name=
"FormSettings_layoutCodeTarget"
type=
"java.lang.Integer"
value=
"1"
/>
<AuxValue
name=
"FormSettings_listenerGenerationStyle"
type=
"java.lang.Integer"
value=
"0"
/>
<AuxValue
name=
"FormSettings_variablesLocal"
type=
"java.lang.Boolean"
value=
"false"
/>
<AuxValue
name=
"FormSettings_variablesModifier"
type=
"java.lang.Integer"
value=
"2"
/>
</AuxValues>
<Layout>
<DimensionLayout
dim=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"jPanel1"
alignment=
"0"
max=
"32767"
attributes=
"0"
/>
</Group>
</DimensionLayout>
<DimensionLayout
dim=
"1"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"jPanel1"
alignment=
"0"
max=
"32767"
attributes=
"0"
/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container
class=
"javax.swing.JPanel"
name=
"jPanel1"
>
<Properties>
<Property
name=
"background"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"cc"
green=
"0"
red=
"0"
type=
"rgb"
/>
</Property>
</Properties>
<Layout>
<DimensionLayout
dim=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
attributes=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
attributes=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<EmptySpace
min=
"-2"
pref=
"27"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"cmbProducts"
min=
"-2"
pref=
"109"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"separate"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jScrollPane1"
min=
"-2"
pref=
"178"
max=
"-2"
attributes=
"0"
/>
</Group>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<EmptySpace
min=
"-2"
pref=
"200"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"lblTotalCost"
min=
"-2"
pref=
"127"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<EmptySpace
min=
"-2"
pref=
"10"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"btnCheckout"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
</Group>
<Component
id=
"btnAddItem"
alignment=
"0"
min=
"-2"
pref=
"88"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
</Group>
<EmptySpace
type=
"separate"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jScrollPane2"
min=
"-2"
pref=
"178"
max=
"-2"
attributes=
"0"
/>
</Group>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jLabel1"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
<EmptySpace
pref=
"97"
max=
"32767"
attributes=
"0"
/>
</Group>
<Group
type=
"103"
rootIndex=
"1"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"1"
attributes=
"0"
>
<EmptySpace
pref=
"381"
max=
"32767"
attributes=
"0"
/>
<Component
id=
"jLabel3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"149"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout
dim=
"1"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jLabel1"
min=
"-2"
pref=
"36"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
attributes=
"0"
>
<EmptySpace
min=
"-2"
pref=
"20"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"jScrollPane1"
min=
"-2"
pref=
"70"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"cmbProducts"
min=
"-2"
pref=
"30"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
min=
"-2"
pref=
"12"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"btnAddItem"
min=
"-2"
pref=
"33"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"separate"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"lblTotalCost"
min=
"-2"
pref=
"36"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"btnCheckout"
min=
"-2"
pref=
"33"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"12"
max=
"-2"
attributes=
"0"
/>
</Group>
<Group
type=
"102"
alignment=
"1"
attributes=
"0"
>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jScrollPane2"
min=
"-2"
pref=
"192"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
<EmptySpace
pref=
"31"
max=
"32767"
attributes=
"0"
/>
</Group>
<Group
type=
"103"
rootIndex=
"1"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<EmptySpace
min=
"-2"
pref=
"63"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jLabel3"
min=
"-2"
pref=
"36"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
pref=
"219"
max=
"32767"
attributes=
"0"
/>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component
class=
"javax.swing.JLabel"
name=
"jLabel1"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"36"
style=
"1"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Select Products"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JComboBox"
name=
"cmbProducts"
>
<Properties>
<Property
name=
"background"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"model"
type=
"javax.swing.ComboBoxModel"
editor=
"org.netbeans.modules.form.editors2.ComboBoxModelEditor"
>
<StringArray
count=
"4"
>
<StringItem
index=
"0"
value=
"Item 1"
/>
<StringItem
index=
"1"
value=
"Item 2"
/>
<StringItem
index=
"2"
value=
"Item 3"
/>
<StringItem
index=
"3"
value=
"Item 4"
/>
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"cmbProductsActionPerformed"
/>
</Events>
<AuxValues>
<AuxValue
name=
"JavaCodeGenerator_TypeParameters"
type=
"java.lang.String"
value=
"<String>"
/>
</AuxValues>
</Component>
<Container
class=
"javax.swing.JScrollPane"
name=
"jScrollPane1"
>
<AuxValues>
<AuxValue
name=
"autoScrollPane"
type=
"java.lang.Boolean"
value=
"true"
/>
</AuxValues>
<Layout
class=
"org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"
/>
<SubComponents>
<Component
class=
"javax.swing.JTextArea"
name=
"txaShowSelected"
>
<Properties>
<Property
name=
"editable"
type=
"boolean"
value=
"false"
/>
<Property
name=
"columns"
type=
"int"
value=
"20"
/>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"2"
/>
</Property>
<Property
name=
"rows"
type=
"int"
value=
"5"
/>
</Properties>
</Component>
</SubComponents>
</Container>
<Component
class=
"javax.swing.JButton"
name=
"btnAddItem"
>
<Properties>
<Property
name=
"background"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Add Item"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"btnAddItemActionPerformed"
/>
</Events>
</Component>
<Container
class=
"javax.swing.JScrollPane"
name=
"jScrollPane2"
>
<AuxValues>
<AuxValue
name=
"autoScrollPane"
type=
"java.lang.Boolean"
value=
"true"
/>
</AuxValues>
<Layout
class=
"org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"
/>
<SubComponents>
<Component
class=
"javax.swing.JTextArea"
name=
"txaBasket"
>
<Properties>
<Property
name=
"editable"
type=
"boolean"
value=
"false"
/>
<Property
name=
"columns"
type=
"int"
value=
"20"
/>
<Property
name=
"rows"
type=
"int"
value=
"5"
/>
</Properties>
</Component>
</SubComponents>
</Container>
<Component
class=
"javax.swing.JLabel"
name=
"lblTotalCost"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Total: £0.0"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"jLabel3"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Tahoma"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Your Basket"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JButton"
name=
"btnCheckout"
>
<Properties>
<Property
name=
"background"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"0"
green=
"ff"
red=
"ff"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Checkout"
/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>
SelfCheckout/src/main/java/SelectProducts.java
0 → 100644
View file @
fa5c4206
import
java.util.ArrayList
;
import
javax.swing.DefaultComboBoxModel
;
/*
* 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.
*/
/**
*
* @author addya
*/
public
class
SelectProducts
extends
javax
.
swing
.
JFrame
{
//arraylist of codes e.g. "01", "02", "03"...
public
ArrayList
<
String
>
codesArL
=
new
ArrayList
<
String
>();
//array of products
public
String
[]
products
=
{
"Pen"
,
"Book"
,
"Water"
,
"Drink"
,
"Snack"
,
"Sweet"
,
"Chocolate"
,
"Biscuits"
,
"Cake"
};
//array of prices
public
double
[]
prices
=
{
1
,
1
,
1
,
1
,
2
,
1
,
1
,
1
,
2
};
//array of how many of each item is in stock
public
ArrayList
<
Integer
>
stockArL
=
new
ArrayList
<
Integer
>();
//index will be the position of the currently selected item in these arrays
public
int
index
;
/**
* Creates new form SelectProducts
*/
public
SelectProducts
()
{
initComponents
();
//this variable is how many iterations the loop performs
//one iteration is done for eacah product
int
amountOfItems
=
products
.
length
;
for
(
int
i
=
0
;
i
==
9
;
i
++){
String
z
=
"0"
;
//if int i is below 10 then a "0" is added to the front
//e.g. "01, "02", "03"
//if int i is above or equal to 10 a "" (nothing) is added
//e.g. "10", "11", "12"
if
(
i
>=
10
)
{
z
=
""
;
}
else
{
z
=
"0"
;
}
//String z (either "0" or "") is added to int i
//after int i is converted to string
String
c
=
z
+
Integer
.
toString
(
i
);
//String c is the code and added to the array of codes
codesArL
.
add
(
c
);
//Each product starts off with a quantity of 20
//so 20 is added to the stock arraylist
stockArL
.
add
(
20
);
}
//on the form starting the combobox cmbItems
//is set to display the items in the products array
DefaultComboBoxModel
dm
=
new
DefaultComboBoxModel
(
products
);
cmbProducts
.
setModel
(
dm
);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings
(
"unchecked"
)
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private
void
initComponents
()
{
jPanel1
=
new
javax
.
swing
.
JPanel
();
jLabel1
=
new
javax
.
swing
.
JLabel
();
cmbProducts
=
new
javax
.
swing
.
JComboBox
<>();
jScrollPane1
=
new
javax
.
swing
.
JScrollPane
();
txaShowSelected
=
new
javax
.
swing
.
JTextArea
();
btnAddItem
=
new
javax
.
swing
.
JButton
();
jScrollPane2
=
new
javax
.
swing
.
JScrollPane
();
txaBasket
=
new
javax
.
swing
.
JTextArea
();
lblTotalCost
=
new
javax
.
swing
.
JLabel
();
jLabel3
=
new
javax
.
swing
.
JLabel
();
btnCheckout
=
new
javax
.
swing
.
JButton
();
setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
setBackground
(
new
java
.
awt
.
Color
(
0
,
0
,
204
));
jPanel1
.
setBackground
(
new
java
.
awt
.
Color
(
0
,
0
,
204
));
jLabel1
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
1
,
36
));
// NOI18N
jLabel1
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
jLabel1
.
setText
(
"Select Products"
);
cmbProducts
.
setBackground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
cmbProducts
.
setModel
(
new
javax
.
swing
.
DefaultComboBoxModel
<>(
new
String
[]
{
"Item 1"
,
"Item 2"
,
"Item 3"
,
"Item 4"
}));
cmbProducts
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
cmbProductsActionPerformed
(
evt
);
}
});
txaShowSelected
.
setEditable
(
false
);
txaShowSelected
.
setColumns
(
20
);
txaShowSelected
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
2
,
18
));
// NOI18N
txaShowSelected
.
setRows
(
5
);
jScrollPane1
.
setViewportView
(
txaShowSelected
);
btnAddItem
.
setBackground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
btnAddItem
.
setText
(
"Add Item"
);
btnAddItem
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
btnAddItemActionPerformed
(
evt
);
}
});
txaBasket
.
setEditable
(
false
);
txaBasket
.
setColumns
(
20
);
txaBasket
.
setRows
(
5
);
jScrollPane2
.
setViewportView
(
txaBasket
);
lblTotalCost
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
18
));
// NOI18N
lblTotalCost
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
lblTotalCost
.
setText
(
"Total: £0.0"
);
jLabel3
.
setFont
(
new
java
.
awt
.
Font
(
"Tahoma"
,
0
,
18
));
// NOI18N
jLabel3
.
setForeground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
jLabel3
.
setText
(
"Your Basket"
);
btnCheckout
.
setBackground
(
new
java
.
awt
.
Color
(
255
,
255
,
0
));
btnCheckout
.
setText
(
"Checkout"
);
javax
.
swing
.
GroupLayout
jPanel1Layout
=
new
javax
.
swing
.
GroupLayout
(
jPanel1
);
jPanel1
.
setLayout
(
jPanel1Layout
);
jPanel1Layout
.
setHorizontalGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addGap
(
27
,
27
,
27
)
.
addComponent
(
cmbProducts
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
109
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
jScrollPane1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
178
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addGap
(
200
,
200
,
200
)
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addComponent
(
lblTotalCost
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
127
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addGap
(
10
,
10
,
10
)
.
addComponent
(
btnCheckout
))
.
addComponent
(
btnAddItem
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
88
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))))
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
jScrollPane2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
178
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addComponent
(
jLabel1
)))
.
addContainerGap
(
97
,
Short
.
MAX_VALUE
))
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
jPanel1Layout
.
createSequentialGroup
()
.
addContainerGap
(
381
,
Short
.
MAX_VALUE
)
.
addComponent
(
jLabel3
)
.
addGap
(
149
,
149
,
149
)))
);
jPanel1Layout
.
setVerticalGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addComponent
(
jLabel1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
36
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addGap
(
20
,
20
,
20
)
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addComponent
(
jScrollPane1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
70
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
cmbProducts
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
30
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addGap
(
12
,
12
,
12
)
.
addComponent
(
btnAddItem
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
33
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
lblTotalCost
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
36
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
btnCheckout
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
33
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
12
,
12
,
12
))
.
addGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
jPanel1Layout
.
createSequentialGroup
()
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
jScrollPane2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
192
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)))
.
addContainerGap
(
31
,
Short
.
MAX_VALUE
))
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addGap
(
63
,
63
,
63
)
.
addComponent
(
jLabel3
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
36
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addContainerGap
(
219
,
Short
.
MAX_VALUE
)))
);
javax
.
swing
.
GroupLayout
layout
=
new
javax
.
swing
.
GroupLayout
(
getContentPane
());
getContentPane
().
setLayout
(
layout
);
layout
.
setHorizontalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addComponent
(
jPanel1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
)
);
layout
.
setVerticalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addComponent
(
jPanel1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
)
);
pack
();
}
// </editor-fold>//GEN-END:initComponents
private
void
cmbProductsActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_cmbProductsActionPerformed
// TODO add your handling code here:
String
display
;
String
find
=
cmbProducts
.
getSelectedItem
().
toString
();
String
current
=
""
;
for
(
int
i
=
0
;
i
<
products
.
length
;
i
++){
current
=
products
[
i
];
if
(
current
==
find
){
//index is equal to i
//this is the position of the product we want to find
index
=
i
;
display
=
"Item: "
+
products
[
i
]+
"\nPrice: £"
+
prices
[
i
];
txaShowSelected
.
setText
(
display
);
}
else
{
}
}
/*
String display;
int index=4;
display="Code: "+codesArL.get(index)+"\nPrice: " + products[index]
+ "\n£" + prices[index] + "\nIn stock: "+stockArL.get(index);
//method .setText() will set the text area to the display string
txaShowSelected.append(display);
//we want to find the selected item in the products array
String find=cmbProducts.getSelectedItem().toString();
//find the index of the selected item
String current="";
//index wil be the index of the item when we find it
//int index=0;
for (int i=0;i<products.length; i++){
current=products[i];
if (current==find){
index=i;
}
else{
}
}
//String display is what we will show in the text area txaShowSelected
//we take the corresponding code, product, price and quantity from each array
display="Code: "+codesArL.get(index)+"\nPrice: " + products[index]
+ "\n£" + prices[index] + "\nIn stock: "+stockArL.get(index);
//method .setText() will set the text area to the display string
txaShowSelected.append(display);
*/
}
//GEN-LAST:event_cmbProductsActionPerformed
//the variable for the total cost must be defined outside of the action event
//otherwise it would be reset to 0 each time the button was clicked
double
total
=
0
;
private
void
btnAddItemActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_btnAddItemActionPerformed
// TODO add your handling code here:
//when the 'Add Item' button is pressed
//the item in the display should go into the basket
txaBasket
.
append
(
products
[
index
]+
"\t"
+
prices
[
index
]+
"\n"
);
//we add the item to an arraylist for the basket too
//somehow we need to pass this arraylist to the second JFrameForm
ArrayList
<
String
>
BasketArL
=
new
ArrayList
<
String
>();
BasketArL
.
add
(
products
[
index
]);
//we will add the price of the added item to the total cost
total
=
total
+
prices
[
index
];
//then display it with the total label
lblTotalCost
.
setText
(
"Total: £"
+
total
);
}
//GEN-LAST:event_btnAddItemActionPerformed
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
args
[])
{
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try
{
for
(
javax
.
swing
.
UIManager
.
LookAndFeelInfo
info
:
javax
.
swing
.
UIManager
.
getInstalledLookAndFeels
())
{
if
(
"Nimbus"
.
equals
(
info
.
getName
()))
{
javax
.
swing
.
UIManager
.
setLookAndFeel
(
info
.
getClassName
());
break
;
}
}
}
catch
(
ClassNotFoundException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
SelectProducts
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
InstantiationException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
SelectProducts
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
IllegalAccessException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
SelectProducts
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
javax
.
swing
.
UnsupportedLookAndFeelException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
SelectProducts
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
//</editor-fold>
/* Create and display the form */
java
.
awt
.
EventQueue
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
SelectProducts
().
setVisible
(
true
);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private
javax
.
swing
.
JButton
btnAddItem
;
private
javax
.
swing
.
JButton
btnCheckout
;
private
javax
.
swing
.
JComboBox
<
String
>
cmbProducts
;
private
javax
.
swing
.
JLabel
jLabel1
;
private
javax
.
swing
.
JLabel
jLabel3
;
private
javax
.
swing
.
JPanel
jPanel1
;
private
javax
.
swing
.
JScrollPane
jScrollPane1
;
private
javax
.
swing
.
JScrollPane
jScrollPane2
;
private
javax
.
swing
.
JLabel
lblTotalCost
;
private
javax
.
swing
.
JTextArea
txaBasket
;
private
javax
.
swing
.
JTextArea
txaShowSelected
;
// End of variables declaration//GEN-END:variables
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment