Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
VendingMachine_Thomas_Barraclough_Resit
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
thomas.barraclough
VendingMachine_Thomas_Barraclough_Resit
Commits
d9606378
Commit
d9606378
authored
May 01, 2020
by
Tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Vending Machine Resit
parent
96e2943e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
5 deletions
+50
-5
VendingMachineClass.java
src/VendingMachineClass.java
+50
-5
No files found.
src/VendingMachineClass.java
View file @
d9606378
import
javax.*
;
import
javax.swing.JFrame
;
import
javax.swing.JLabel
;
import
javax.swing.JPanel
;
public
class
VendingMachineClass
extends
javax
.
swing
.
JFrame
{
import
java.awt.*
;
import
java.awt.event.*
;
public
class
VendingMachineClass
extends
javax
.
swing
.
JFrame
implements
ActionListener
{
public
VendingMachineClass
()
{
public
VendingMachineClass
()
{
...
@@ -8,6 +15,12 @@ public class VendingMachineClass extends javax.swing.JFrame {
...
@@ -8,6 +15,12 @@ public class VendingMachineClass extends javax.swing.JFrame {
}
}
private
void
initComponents
()
{
private
void
initComponents
()
{
//setting up a bunch of string variables, these are all for the items.
//setting up a bunch of string variables, these are all for the items.
...
@@ -28,6 +41,13 @@ public class VendingMachineClass extends javax.swing.JFrame {
...
@@ -28,6 +41,13 @@ public class VendingMachineClass extends javax.swing.JFrame {
jButton2
=
new
javax
.
swing
.
JButton
();
jButton2
=
new
javax
.
swing
.
JButton
();
jButton3
=
new
javax
.
swing
.
JButton
();
jButton3
=
new
javax
.
swing
.
JButton
();
//Here I am adding action listeners for each button, this allows me to add functionality to them.
jButton3
.
addActionListener
(
this
);
jButton2
.
addActionListener
(
this
);
setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
jComboBox1
.
setModel
(
new
javax
.
swing
.
DefaultComboBoxModel
<>(
new
String
[]
{
chocolate
,
water
,
hot_drink
,
snack
,
sweet
}));
jComboBox1
.
setModel
(
new
javax
.
swing
.
DefaultComboBoxModel
<>(
new
String
[]
{
chocolate
,
water
,
hot_drink
,
snack
,
sweet
}));
...
@@ -38,12 +58,14 @@ public class VendingMachineClass extends javax.swing.JFrame {
...
@@ -38,12 +58,14 @@ public class VendingMachineClass extends javax.swing.JFrame {
jLabel1
.
setText
(
"Selected Item"
);
jLabel1
.
setText
(
"Selected Item"
);
jButton1
.
setText
(
"
Money Ou
t"
);
jButton1
.
setText
(
"
Cos
t"
);
jButton2
.
setText
(
"
Money In
"
);
jButton2
.
setText
(
"
Purchase
"
);
jButton3
.
setText
(
"Add"
);
jButton3
.
setText
(
"Add"
);
javax
.
swing
.
GroupLayout
layout
=
new
javax
.
swing
.
GroupLayout
(
getContentPane
());
javax
.
swing
.
GroupLayout
layout
=
new
javax
.
swing
.
GroupLayout
(
getContentPane
());
getContentPane
().
setLayout
(
layout
);
getContentPane
().
setLayout
(
layout
);
layout
.
setHorizontalGroup
(
layout
.
setHorizontalGroup
(
...
@@ -96,6 +118,26 @@ public class VendingMachineClass extends javax.swing.JFrame {
...
@@ -96,6 +118,26 @@ public class VendingMachineClass extends javax.swing.JFrame {
pack
();
pack
();
}
}
//Here I create some variables
int
cost
=
0
;
int
stock
=
20
;
public
void
actionPerformed
(
ActionEvent
e
)
{
//Checks which button has been clicked
if
(
e
.
getActionCommand
().
equals
(
"Add"
))
{
//If the add button is clicked the item will be displayed in the following text areas.
jTextField1
.
setText
(
jComboBox1
.
getSelectedItem
().
toString
());
jTextArea1
.
setText
(
jComboBox1
.
getSelectedItem
().
toString
());
}
if
(
e
.
getActionCommand
().
equals
(
"Cost"
))
{
System
.
out
.
print
(
"Test"
);
}
}
public
static
void
main
(
String
args
[])
{
public
static
void
main
(
String
args
[])
{
...
@@ -121,11 +163,13 @@ public class VendingMachineClass extends javax.swing.JFrame {
...
@@ -121,11 +163,13 @@ public class VendingMachineClass extends javax.swing.JFrame {
java
.
awt
.
EventQueue
.
invokeLater
(
new
Runnable
()
{
java
.
awt
.
EventQueue
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
public
void
run
()
{
new
VendingMachineClass
().
setVisible
(
true
);
new
VendingMachineClass
().
setVisible
(
true
);
}
}
});
});
}
}
private
javax
.
swing
.
JButton
jButton1
;
private
javax
.
swing
.
JButton
jButton1
;
private
javax
.
swing
.
JButton
jButton2
;
private
javax
.
swing
.
JButton
jButton2
;
private
javax
.
swing
.
JButton
jButton3
;
private
javax
.
swing
.
JButton
jButton3
;
...
@@ -138,3 +182,4 @@ public class VendingMachineClass extends javax.swing.JFrame {
...
@@ -138,3 +182,4 @@ public class VendingMachineClass extends javax.swing.JFrame {
private
javax
.
swing
.
JTextField
jTextField3
;
private
javax
.
swing
.
JTextField
jTextField3
;
}
}
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