Commit 58490f01 authored by Susanti Gojali's avatar Susanti Gojali
Browse files

move player added

parent e17fbd95
......@@ -13,4 +13,5 @@ src/client/nbbuild/
src/client/nbdist/
src/client/nbactions.xml
src/client/nb-configuration.xml
.nb-gradle/
\ No newline at end of file
.nb-gradle/
/src/client/dist/
\ No newline at end of file
......@@ -6,5 +6,5 @@ user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.pro
=======
>>>>>>> 2e2ad538abfe623e38cc24be02c48f5ad2ee0768
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
user.properties.file=C:\\Users\\susanti_2\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
>>>>>>> 43e41c8c08f84039568ca701a584f38f9911e548
......@@ -3,12 +3,8 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<<<<<<< HEAD
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/LoginPage.java</file>
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/MainPage.java</file>
=======
<file>file:/E:/semester%206/Sistem%20Paralel%20dan%20Terdistribusi/SISTER/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/MainPage.java</file>
>>>>>>> f49f35941c855b388307f2c54b28647caeb9e5c3
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/TCPClient.java</file>
</group>
</open-files>
</project-private>
......@@ -338,56 +338,68 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace pref="18" max="32767" attributes="0"/>
<Component id="playerPanel" min="-2" pref="513" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="89" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="currenttimeLabel" min="-2" max="-2" attributes="0"/>
<Component id="timeLabel" min="-2" max="-2" attributes="0"/>
<Component id="mapLabel" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="positionLabel" alignment="0" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="37" max="32767" attributes="0"/>
<Component id="playerPanel" min="-2" pref="550" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="52" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="timeLabel" linkSize="8" min="-2" max="-2" attributes="0"/>
<Component id="positionLabel" linkSize="8" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace pref="12" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="moveButton" max="32767" attributes="0"/>
<Component id="xpositionTextField" min="-2" pref="59" max="-2" attributes="0"/>
<Component id="moveButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="43" max="32767" attributes="0"/>
<Component id="fieldButton" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" max="-2" attributes="0">
<Component id="xpositionLabel" alignment="0" max="32767" attributes="0"/>
<Component id="positionXTextField" alignment="0" pref="59" max="32767" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="34" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="43" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="ypositionTextField" max="32767" attributes="0"/>
<Component id="fieldButton" min="-2" max="-2" attributes="0"/>
<Component id="positionYTextField" pref="55" max="32767" attributes="0"/>
<Component id="ypositionLabel" max="32767" attributes="0"/>
</Group>
</Group>
<Component id="mapLabel" linkSize="8" alignment="0" max="32767" attributes="0"/>
<Component id="currenttimeLabel" linkSize="8" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="40" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="52" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="38" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="playerPanel" alignment="1" pref="491" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="38" max="-2" attributes="0"/>
<Component id="mapLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="positionLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="timeLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="28" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="currenttimeLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="29" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="33" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="xpositionTextField" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="ypositionTextField" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="xpositionLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="ypositionLabel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="positionYTextField" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="positionXTextField" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="moveButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="fieldButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="295" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="playerPanel" pref="518" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
......@@ -416,14 +428,17 @@
<Property name="text" type="java.lang.String" value="Current Time"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="xpositionTextField">
<Component class="javax.swing.JTextField" name="positionXTextField">
</Component>
<Component class="javax.swing.JTextField" name="ypositionTextField">
<Component class="javax.swing.JTextField" name="positionYTextField">
</Component>
<Component class="javax.swing.JButton" name="moveButton">
<Properties>
<Property name="text" type="java.lang.String" value="Move"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="fieldButton">
<Properties>
......@@ -441,12 +456,12 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="mapScrollPane" alignment="0" pref="513" max="32767" attributes="0"/>
<Component id="mapScrollPane" alignment="0" pref="550" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="mapScrollPane" alignment="1" max="32767" attributes="0"/>
<Component id="mapScrollPane" alignment="0" pref="518" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
......@@ -482,10 +497,12 @@
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="null"/>
</Property>
<Property name="rowSelectionAllowed" type="boolean" value="false"/>
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="null" type="code"/>
</Property>
<Property name="updateSelectionOnSort" type="boolean" value="false"/>
<Property name="verifyInputWhenFocusTarget" type="boolean" value="false"/>
</Properties>
<AccessibilityProperties>
<Property name="AccessibleContext.accessibleDescription" type="java.lang.String" value=""/>
......@@ -495,6 +512,18 @@
</Container>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="xpositionLabel">
<Properties>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="X"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="ypositionLabel">
<Properties>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="Y"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="inventoryPanel">
......
package tcpclient;
import java.applet.Applet;
import java.awt.CardLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.Timer;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
......@@ -19,6 +28,7 @@ import javax.swing.table.TableModel;
import org.json.JSONArray;
import org.json.JSONObject;
import sun.swing.ImageIconUIResource;
public class MainPage extends javax.swing.JFrame {
......@@ -26,6 +36,9 @@ public class MainPage extends javax.swing.JFrame {
//atribut
private TCPClient client;
private TableModel mapModel;
private Date currentTime;
private Date time;
private Timer timer;
public MainPage() {
......@@ -72,13 +85,15 @@ public class MainPage extends javax.swing.JFrame {
positionLabel = new javax.swing.JLabel();
timeLabel = new javax.swing.JLabel();
currenttimeLabel = new javax.swing.JLabel();
xpositionTextField = new javax.swing.JTextField();
ypositionTextField = new javax.swing.JTextField();
positionXTextField = new javax.swing.JTextField();
positionYTextField = new javax.swing.JTextField();
moveButton = new javax.swing.JButton();
fieldButton = new javax.swing.JButton();
playerPanel = new javax.swing.JPanel();
mapScrollPane = new javax.swing.JScrollPane();
mapTable = new javax.swing.JTable();
xpositionLabel = new javax.swing.JLabel();
ypositionLabel = new javax.swing.JLabel();
inventoryPanel = new javax.swing.JPanel();
Level1Panel = new javax.swing.JPanel();
HoneyIcon = new javax.swing.JLabel();
......@@ -323,6 +338,11 @@ public class MainPage extends javax.swing.JFrame {
currenttimeLabel.setText("Current Time");
moveButton.setText("Move");
moveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
moveButtonActionPerformed(evt);
}
});
fieldButton.setText("Field");
......@@ -338,8 +358,10 @@ public class MainPage extends javax.swing.JFrame {
);
mapTable.setName(""); // NOI18N
mapTable.setPreferredSize(null);
mapTable.setRowSelectionAllowed(false);
mapTable.setTableHeader(null);
mapTable.setUpdateSelectionOnSort(false);
mapTable.setVerifyInputWhenFocusTarget(false);
mapScrollPane.setViewportView(mapTable);
mapTable.getAccessibleContext().setAccessibleDescription("");
......@@ -347,60 +369,78 @@ public class MainPage extends javax.swing.JFrame {
playerPanel.setLayout(playerPanelLayout);
playerPanelLayout.setHorizontalGroup(
playerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mapScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)
.addComponent(mapScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 550, Short.MAX_VALUE)
);
playerPanelLayout.setVerticalGroup(
playerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mapScrollPane, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(mapScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 518, Short.MAX_VALUE)
);
xpositionLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
xpositionLabel.setText("X");
ypositionLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
ypositionLabel.setText("Y");
javax.swing.GroupLayout mapPanelLayout = new javax.swing.GroupLayout(mapPanel);
mapPanel.setLayout(mapPanelLayout);
mapPanelLayout.setHorizontalGroup(
mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mapPanelLayout.createSequentialGroup()
.addContainerGap(18, Short.MAX_VALUE)
.addComponent(playerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 513, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(89, 89, 89)
.addGroup(mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(currenttimeLabel)
.addContainerGap(37, Short.MAX_VALUE)
.addComponent(playerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 550, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(52, 52, 52)
.addGroup(mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(timeLabel)
.addComponent(mapLabel)
.addComponent(positionLabel)
.addGroup(mapPanelLayout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(moveButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(xpositionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(34, 34, 34)
.addComponent(moveButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
.addComponent(fieldButton))
.addGroup(mapPanelLayout.createSequentialGroup()
.addGroup(mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(xpositionLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(positionXTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE))
.addGap(43, 43, 43)
.addGroup(mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(ypositionTextField)
.addComponent(fieldButton))))
.addGap(40, 40, 40))
.addComponent(positionYTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE)
.addComponent(ypositionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(mapLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(currenttimeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(52, 52, 52))
);
mapPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {currenttimeLabel, mapLabel, positionLabel, timeLabel});
mapPanelLayout.setVerticalGroup(
mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mapPanelLayout.createSequentialGroup()
.addGap(38, 38, 38)
.addGroup(mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(playerPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE)
.addGroup(mapPanelLayout.createSequentialGroup()
.addGap(38, 38, 38)
.addComponent(mapLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(positionLabel)
.addGap(18, 18, 18)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(timeLabel)
.addGap(28, 28, 28)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(currenttimeLabel)
.addGap(29, 29, 29)
.addGap(33, 33, 33)
.addGroup(mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(xpositionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ypositionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(xpositionLabel)
.addComponent(ypositionLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(positionYTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(positionXTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(moveButton)
.addComponent(fieldButton))
.addGap(0, 295, Short.MAX_VALUE)))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mapPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(playerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 518, Short.MAX_VALUE)))
.addContainerGap())
);
......@@ -975,23 +1015,32 @@ public class MainPage extends javax.swing.JFrame {
client.y=response.getInt("y");
showMessage("Login success");
Long time = response.getLong("time");
//update map view
positionLabel.setText("Position: ["+client.x+" , "+client.y+"]");
Long timeLong = response.getLong("time");
time = new Date(Long.parseLong(timeLong.toString())*1000);
timeLabel.setText("Time: "+time);
currenttimeLabel.setText("Current Time: "+ new Date());
//Create timer for Current Time
timer=new Timer(1000,new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
currentTime = new Date();
String formateDate=sdf.format(currentTime);
currenttimeLabel.setText("Current Time: "+currentTime.toString());
}
});
timer.start();
generateMap();
LoginAndRegisterPanel.setVisible(false);
NavBarPanel.setVisible(true);
LogoutMenuButton.setVisible(true);
generateMap();
//change to map
CardLayout cl = (CardLayout) MainPanel.getLayout();
cl.show(MainPanel, "MapCard");
} else {
showMessage(response.getString("description"));
}
......@@ -1002,10 +1051,58 @@ public class MainPage extends javax.swing.JFrame {
}
}//GEN-LAST:event_loginButtonActionPerformed
private void moveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveButtonActionPerformed
String positionX=positionXTextField.getText();
String positionY=positionYTextField.getText();
if(time.after(currentTime)){ //player is moving
showMessage("You still moving now..");
}
else if(positionX.isEmpty() || positionY.isEmpty()) {
showMessage(" Position X and Y must be filled");
}else{
try{
int xInt=Integer.parseInt(positionX);
int yInt=Integer.parseInt(positionY);
JSONObject response;
try {
response = client.move(xInt, yInt);
if(response.getString("status").equals("ok")) {
Long timeLong=response.getLong("time");
time= new Date(Long.parseLong(timeLong.toString())*1000);
timeLabel.setText("Time: "+time);
//move character
mapModel.setValueAt(null, client.x, client.y);
client.x=xInt;
client.y=yInt;
ImageIcon playerIcon = new ImageIcon(getClass().getResource("player.png"));
Image img = playerIcon.getImage();
Image newimg = img.getScaledInstance(125, 125, java.awt.Image.SCALE_SMOOTH);
ImageIcon newPlayerIcon = new ImageIcon(newimg);
mapModel.setValueAt(newPlayerIcon, client.x, client.y);
} else if (response.getString("status").equals("fail")){
showMessage(response.getString("description"));
} else {
showMessage(response.getString("status"));
}
} catch (Exception ex) {
showMessage("Server does not respond. Please try again later..");
System.out.println("Login Exception");
Logger.getLogger(LoginPage.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (NumberFormatException ex) {
showMessage("Position X and Y must be filled with number!");
Logger.getLogger(LoginPage.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_moveButtonActionPerformed
//Generate Map
private void generateMap() {
System.out.println("masuk map");
JSONObject response;
try {
response = client.map();
......@@ -1014,19 +1111,22 @@ public class MainPage extends javax.swing.JFrame {
String name = response.getString("name");
mapLabel.setText("Map: "+name);
int dimX=response.getInt("width");;
int dimX=response.getInt("width");
int dimY=response.getInt("height");
mapModel=new MapTableModel(dimX, dimY);
mapModel.setValueAt(null, client.x, client.y);
ImageIcon playerIcon = new ImageIcon(getClass().getResource("player.png"));
Image img = playerIcon.getImage();
Image newimg = img.getScaledInstance(125, 125, java.awt.Image.SCALE_SMOOTH);
ImageIcon newPlayerIcon = new ImageIcon(newimg);
mapModel.setValueAt(newPlayerIcon, client.x, client.y);
mapTable.setModel(mapModel);
mapTable.setRowHeight(100);
mapTable.setRowHeight(125);
for (int i = 0; i < mapTable.getColumnModel().getColumnCount(); i++) {
TableColumn column = mapTable.getColumnModel().getColumn(i);
column.setPreferredWidth(100);
column.setPreferredWidth(125);
}
mapTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
mapTable.setPreferredScrollableViewportSize(mapTable.getPreferredSize());
mapTable.setTableHeader(null);
......@@ -1041,8 +1141,6 @@ public class MainPage extends javax.swing.JFrame {
System.out.println("Map Exception");
Logger.getLogger(LoginPage.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("keluar map");
}
/**
......@@ -1143,6 +1241,8 @@ public class MainPage extends javax.swing.JFrame {
private javax.swing.JLabel portLabel;
private javax.swing.JTextField portTextField;
private javax.swing.JLabel positionLabel;
private javax.swing.JTextField positionXTextField;
private javax.swing.JTextField positionYTextField;
private javax.swing.JButton registerButton;
private javax.swing.JLabel registerLabel;
private javax.swing.JPanel registerPanel;
......@@ -1155,8 +1255,8 @@ public class MainPage extends javax.swing.JFrame {
private javax.swing.JTextField usernameLoginTextField;
private javax.swing.JLabel usernameRegisterLabel;
private javax.swing.JTextField usernameRegisterTextField;
private javax.swing.JTextField xpositionTextField;
private javax.swing.JTextField ypositionTextField;
private javax.swing.JLabel xpositionLabel;
private javax.swing.JLabel ypositionLabel;
// End of variables declaration//GEN-END:variables
......
......@@ -9,15 +9,11 @@ public class MapTableModel extends AbstractTableModel{
private Object[][] data;
private int dimX;
private int dimY;
private ImageIcon playerIcon;
public MapTableModel() {
dimX=0;
dimY=0;
}
public MapTableModel(int x, int y) {
dimX=x;
......@@ -29,10 +25,6 @@ public class MapTableModel extends AbstractTableModel{
data[i][j] = "";
}
}
// ClassLoader cldr = this.getClass().getClassLoader();
// java.net.URL imageURL = cldr.getResource("images/player.png");
// playerIcon = new ImageIcon(imageURL);
}
@Override
......@@ -51,9 +43,14 @@ public class MapTableModel extends AbstractTableModel{
}
public void setValueAt(Object value, int row, int col) {
data[row][col] = "playerIcon";
data[row][col] = value;
fireTableCellUpdated(row, col);
}
@Override
public Class<?> getColumnClass(int column) {
return ImageIcon.class;
}