Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jonathan Sudibya
IF3230-Tugas-Besar-Sister-2015
Commits
addd6759
Commit
addd6759
authored
Apr 26, 2015
by
Jonathan Sudibya
Browse files
milestone server #1
parent
0e83946a
Changes
44
Expand all
Hide whitespace changes
Inline
Side-by-side
src/client/TCPClient/nbproject/project.properties
View file @
addd6759
...
...
@@ -69,7 +69,7 @@ jnlp.signed=false
jnlp.signing
=
jnlp.signing.alias
=
jnlp.signing.keystore
=
main.class
=
TCPC
lient
main.class
=
c
lient
.Login
# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed
manifest.custom.codebase
=
# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions)
...
...
src/client/TCPClient/src/ClientHandler.java
0 → 100644
View file @
addd6759
/*
* 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
client
;
/**
*
* @author Fauzan Hilmi
*/
public
class
ClientHandler
{
public
static
void
Login
(
String
username
,
String
password
)
{
}
}
src/client/TCPClient/src/Connection/Listener.java
deleted
100644 → 0
View file @
0e83946a
/*
* 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
Connection
;
import
java.io.BufferedReader
;
import
java.io.DataInputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.Socket
;
import
java.util.Vector
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
org.json.simple.JSONObject
;
import
org.json.simple.parser.JSONParser
;
import
org.json.simple.parser.ParseException
;
/**
*
* @author Jonathan
*/
public
class
Listener
implements
Runnable
{
private
Socket
connection
;
private
Vector
<
JSONObject
>
data
;
private
Thread
t
;
private
boolean
active
;
public
Listener
(
Socket
_connection
)
{
connection
=
_connection
;
data
=
new
Vector
<>();
active
=
true
;
}
@Override
public
void
run
()
{
JSONParser
parser
=
new
JSONParser
();
while
(
active
){
try
{
BufferedReader
inFromServer
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
()));
data
.
add
((
JSONObject
)
parser
.
parse
(
inFromServer
.
readLine
()));
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
Listener
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
ParseException
ex
)
{
Logger
.
getLogger
(
Listener
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
}
public
void
start
(){
if
(
t
!=
null
){
t
=
new
Thread
(
this
,
"Client Listener"
);
t
.
start
();
}
}
public
void
setActive
(
boolean
_active
)
{
active
=
_active
;
}
public
boolean
isDataEmpty
()
{
return
data
.
isEmpty
();
}
public
JSONObject
getFirstData
()
{
return
data
.
remove
(
0
);
}
}
src/client/TCPClient/src/Connection/Sender.java
deleted
100644 → 0
View file @
0e83946a
/*
* 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
Connection
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.net.Socket
;
import
java.nio.charset.Charset
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
org.json.simple.JSONObject
;
/**
*
* @author Jonathan
*/
public
class
Sender
implements
Runnable
{
private
JSONObject
data
;
private
Socket
connectionSocket
;
private
boolean
active
;
private
Thread
t
;
public
Sender
(
Socket
_connection
)
{
connectionSocket
=
_connection
;
active
=
true
;
}
@Override
public
void
run
()
{
while
(
active
)
{
if
(!
data
.
isEmpty
()){
try
{
DataOutputStream
outToServer
=
new
DataOutputStream
(
connectionSocket
.
getOutputStream
());
outToServer
.
write
(
data
.
toJSONString
().
getBytes
(
Charset
.
forName
(
"UTF-8"
)));
data
.
clear
();
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
Sender
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
}
}
public
void
setActive
(
boolean
a
)
{
active
=
a
;
}
public
void
setData
(
JSONObject
_data
)
{
data
=
_data
;
}
public
boolean
isDataEmpty
()
{
return
data
.
isEmpty
();
}
public
void
start
()
{
if
(
t
!=
null
)
{
t
=
new
Thread
(
this
,
"Client Sender"
);
t
.
start
();
}
}
}
src/client/TCPClient/src/Field.form
0 → 100644
View file @
addd6759
<?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"
/>
</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=
"Background"
alignment=
"0"
max=
"32767"
attributes=
"0"
/>
</Group>
</DimensionLayout>
<DimensionLayout
dim=
"1"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"Background"
alignment=
"0"
max=
"32767"
attributes=
"0"
/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container
class=
"javax.swing.JPanel"
name=
"Background"
>
<Properties>
<Property
name=
"background"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"99"
green=
"ff"
red=
"99"
type=
"rgb"
/>
</Property>
</Properties>
<Layout>
<DimensionLayout
dim=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"103"
alignment=
"0"
groupAlignment=
"0"
max=
"-2"
attributes=
"0"
>
<Component
id=
"NamaField"
pref=
"253"
max=
"32767"
attributes=
"0"
/>
<Component
id=
"TimeCurrent"
max=
"32767"
attributes=
"0"
/>
</Group>
<Component
id=
"Time"
alignment=
"0"
min=
"-2"
pref=
"235"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"CharPosition"
alignment=
"0"
min=
"-2"
pref=
"94"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"1"
attributes=
"0"
>
<Group
type=
"102"
attributes=
"0"
>
<Component
id=
"Inventory"
min=
"-2"
pref=
"51"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"unrelated"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Mix"
min=
"-2"
pref=
"51"
max=
"-2"
attributes=
"0"
/>
</Group>
<Component
id=
"Field"
min=
"-2"
pref=
"55"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
type=
"unrelated"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Tradebox"
min=
"-2"
pref=
"51"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"unrelated"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Offer"
min=
"-2"
pref=
"51"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Find"
min=
"-2"
pref=
"51"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<Component
id=
"Logout"
min=
"-2"
pref=
"51"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"34"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Char"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"32767"
attributes=
"0"
/>
</Group>
<Group
type=
"102"
alignment=
"1"
attributes=
"0"
>
<Component
id=
"Move"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"separate"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"xfield"
min=
"-2"
pref=
"21"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"unrelated"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"yfield"
min=
"-2"
pref=
"21"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"34"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
</Group>
<Group
type=
"102"
attributes=
"0"
>
<EmptySpace
min=
"-2"
pref=
"42"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Canvas"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"0"
pref=
"0"
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=
"0"
max=
"-2"
attributes=
"0"
>
<Group
type=
"102"
attributes=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
max=
"-2"
attributes=
"0"
>
<Group
type=
"102"
attributes=
"0"
>
<Component
id=
"NamaField"
min=
"-2"
pref=
"30"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"32767"
attributes=
"0"
/>
<Component
id=
"CharPosition"
min=
"-2"
pref=
"30"
max=
"-2"
attributes=
"0"
/>
</Group>
<Component
id=
"Char"
alignment=
"1"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"102"
alignment=
"1"
attributes=
"0"
>
<Component
id=
"Logout"
min=
"-2"
pref=
"47"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"13"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<EmptySpace
min=
"-2"
pref=
"11"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
groupAlignment=
"3"
attributes=
"0"
>
<Component
id=
"xfield"
alignment=
"3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"yfield"
alignment=
"3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Move"
alignment=
"3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
<Group
type=
"102"
alignment=
"0"
attributes=
"0"
>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"TimeCurrent"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
type=
"unrelated"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Time"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
</Group>
<Group
type=
"102"
attributes=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"Inventory"
alignment=
"1"
min=
"-2"
pref=
"47"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Mix"
alignment=
"1"
min=
"-2"
pref=
"47"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Tradebox"
alignment=
"1"
min=
"-2"
pref=
"47"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Offer"
alignment=
"1"
min=
"-2"
pref=
"47"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Find"
alignment=
"1"
min=
"-2"
pref=
"47"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
max=
"32767"
attributes=
"0"
/>
<Component
id=
"Field"
min=
"-2"
pref=
"47"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
<EmptySpace
type=
"separate"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"Canvas"
max=
"32767"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"58"
max=
"-2"
attributes=
"0"
/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component
class=
"javax.swing.JLabel"
name=
"NamaField"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Kalinga"
size=
"18"
style=
"1"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"66"
green=
"66"
red=
"66"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Nama Field"
/>
<Property
name=
"toolTipText"
type=
"java.lang.String"
value=
""
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"Char"
>
<Properties>
<Property
name=
"icon"
type=
"javax.swing.Icon"
editor=
"org.netbeans.modules.form.editors2.IconEditor"
>
<Image
iconType=
"3"
name=
"/client/image/charsteadygif.gif"
/>
</Property>
</Properties>
</Component>
<Component
class=
"javax.swing.JButton"
name=
"Move"
>
<Properties>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Move To"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"MoveActionPerformed"
/>
</Events>
</Component>
<Component
class=
"javax.swing.JButton"
name=
"Field"
>
<Properties>
<Property
name=
"icon"
type=
"javax.swing.Icon"
editor=
"org.netbeans.modules.form.editors2.IconEditor"
>
<Image
iconType=
"3"
name=
"/client/image/field.png"
/>
</Property>
<Property
name=
"toolTipText"
type=
"java.lang.String"
value=
"field"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"FieldActionPerformed"
/>
</Events>
</Component>
<Component
class=
"javax.swing.JButton"
name=
"Inventory"
>
<Properties>
<Property
name=
"icon"
type=
"javax.swing.Icon"
editor=
"org.netbeans.modules.form.editors2.IconEditor"
>
<Image
iconType=
"3"
name=
"/client/image/inventory.gif"
/>
</Property>
<Property
name=
"toolTipText"
type=
"java.lang.String"
value=
"inventory"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"InventoryActionPerformed"
/>
</Events>
</Component>
<Component
class=
"javax.swing.JButton"
name=
"Mix"
>
<Properties>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Mix"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"MixActionPerformed"
/>
</Events>
</Component>
<Component
class=
"javax.swing.JButton"
name=
"Tradebox"
>
<Properties>
<Property
name=
"icon"
type=
"javax.swing.Icon"
editor=
"org.netbeans.modules.form.editors2.IconEditor"
>
<Image
iconType=
"3"
name=
"/client/image/trade.png"
/>
</Property>
<Property
name=
"toolTipText"
type=
"java.lang.String"
value=
"trade"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"TradeboxActionPerformed"
/>
</Events>
</Component>
<Component
class=
"javax.swing.JButton"
name=
"Find"
>
<Properties>
<Property
name=
"icon"
type=
"javax.swing.Icon"
editor=
"org.netbeans.modules.form.editors2.IconEditor"
>
<Image
iconType=
"3"
name=
"/client/image/zoom.png"
/>
</Property>
<Property
name=
"toolTipText"
type=
"java.lang.String"
value=
"find"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"FindActionPerformed"
/>
</Events>
</Component>
<Component
class=
"javax.swing.JButton"
name=
"Offer"
>
<Properties>
<Property
name=
"icon"
type=
"javax.swing.Icon"
editor=
"org.netbeans.modules.form.editors2.IconEditor"
>
<Image
iconType=
"3"
name=
"/client/image/offer.png"
/>
</Property>
<Property
name=
"toolTipText"
type=
"java.lang.String"
value=
"offer"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"OfferActionPerformed"
/>
</Events>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"Time"
>
<Properties>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Time"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"TimeCurrent"
>
<Properties>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Time Current"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"CharPosition"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Kalinga"
size=
"18"
style=
"1"
/>
</Property>
<Property
name=
"foreground"
type=
"java.awt.Color"
editor=
"org.netbeans.beaninfo.editors.ColorEditor"
>
<Color
blue=
"66"
green=
"66"
red=
"66"
type=
"rgb"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Position"
/>
<Property
name=
"toolTipText"
type=
"java.lang.String"
value=
""
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JTextField"
name=
"xfield"
>
<Properties>
<Property
name=
"text"
type=
"java.lang.String"
value=
"0"
/>
<Property
name=
"toolTipText"
type=
"java.lang.String"
value=
"posisi x"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JTextField"
name=
"yfield"
>
<Properties>
<Property
name=
"text"
type=
"java.lang.String"
value=
"0"
/>
<Property
name=
"toolTipText"
type=
"java.lang.String"
value=
"posisi y"
/>
</Properties>
</Component>
<Container
class=
"javax.swing.JPanel"
name=
"Canvas"
>
<Layout>
<DimensionLayout
dim=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<EmptySpace
min=
"0"
pref=
"655"
max=
"32767"
attributes=
"0"
/>
</Group>
</DimensionLayout>
<DimensionLayout
dim=
"1"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<EmptySpace
min=
"0"
pref=
"513"
max=
"32767"
attributes=
"0"
/>
</Group>
</DimensionLayout>
</Layout>
</Container>
<Component
class=
"javax.swing.JButton"
name=
"Logout"
>
<Properties>
<Property
name=
"icon"
type=
"javax.swing.Icon"
editor=
"org.netbeans.modules.form.editors2.IconEditor"
>
<Image
iconType=
"3"
name=
"/client/image/logout.png"
/>
</Property>
<Property
name=
"toolTipText"
type=
"java.lang.String"
value=
"Logout"
/>
</Properties>
<Events>
<EventHandler
event=
"actionPerformed"
listener=
"java.awt.event.ActionListener"
parameters=
"java.awt.event.ActionEvent"
handler=
"LogoutActionPerformed"
/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>
src/client/TCPClient/src/Field.java
0 → 100644
View file @
addd6759
This diff is collapsed.
Click to expand it.
src/client/TCPClient/src/Invent.java
0 → 100644
View file @
addd6759
/*
* 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
client
;
import
javax.swing.*
;
import
org.json.simple.JSONArray
;
import
org.json.simple.JSONObject
;
/**
*
* @author Muhammad Husain
*/
public
final
class
Invent
extends
JPanel
{
private
Item
[]
items
;
private
JSONObject
invenJSON
;
public
Invent
(){
this
.
setSize
(
655
,
519
);
initComponent
();
}
public
void
setJSON
(
JSONObject
in
){
invenJSON
=
in
;
getmatrixofitem
();
Repaint
();
}
private
void
getmatrixofitem
(){
JSONArray
itemitem
=
(
JSONArray
)
invenJSON
.
get
(
"inventory"
);
for
(
int
i
=
0
;
i
<
10
;
i
++){
items
[
i
]
=
new
Item
();
items
[
i
].
setID
(
i
);
}
for
(
int
i
=
0
;
i
<
10
;
i
++){
items
[
i
].
setIcon
();
items
[
i
].
setJumlah
(
Integer
.
parseInt
(
itemitem
.
get
(
i
).
toString
()));
}
}
public
void
addInvent
(
int
code
,
int
value
){
value
=
value
+
items
[
code
].
getJumlah
();
items
[
code
].
setJumlah
(
value
);
repaint
(
code
);
System
.
out
.
println
(
"jumlah item sekarang : "
+
items
[
code
].
ShowJumlah
());
}
public
void
initComponent
(){
invenJSON
=
new
JSONObject
();
items
=
new
Item
[
10
];
Back
=
new
javax
.
swing
.
JButton
();
Honey
=
new
JLabel
();
Herbs
=
new
JLabel
();
Mineral
=
new
JLabel
();
Clay
=
new
JLabel
();
Potion
=
new
JLabel
();
Incense
=
new
JLabel
();
Gem
=
new
JLabel
();
LifeElixir
=
new
JLabel
();
Crystal
=
new
JLabel
();
PhilosopherStone
=
new
JLabel
();
Level1
=
new
javax
.
swing
.
JPanel
();
Level2
=
new
javax
.
swing
.
JPanel
();
Level4
=
new
javax
.
swing
.
JPanel
();
Level5
=
new
javax
.
swing
.
JPanel
();
Back
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
CENTER
);
Back
.
setText
(
"Back"
);
Back
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
BackActionPerformed
(
evt
);
}
});
Level1
.
setBackground
(
new
java
.
awt
.
Color
(
153
,
255
,
51
));
javax
.
swing
.
GroupLayout
Level1Layout
=
new
javax
.
swing
.
GroupLayout
(
Level1
);
Level1
.
setLayout
(
Level1Layout
);
Level1Layout
.
setHorizontalGroup
(
Level1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
Level1Layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
Level1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
,
false
)
.
addComponent
(
Mineral
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
)
.
addComponent
(
Honey
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
)
.
addComponent
(
Herbs
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
)
.
addComponent
(
Clay
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
))
.
addContainerGap
(
64
,
Short
.
MAX_VALUE
))
);
Level1Layout
.
setVerticalGroup
(
Level1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
Level1Layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addComponent
(
Honey
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
42
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
Mineral
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
41
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
Herbs
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
Clay
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
45
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)