8 Replies - 4911 Views - Last Post: 13 July 2011 - 07:33 AM Rate Topic: -----

#1 MBT7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 08-April 11

question-client_server by XML

Posted 11 July 2011 - 01:04 PM

Hi,
I wrote a game(Tank game) and now I need to change it to client server mode to play on network.
how can I write a client_server program bye XML?
I attached the GameWindow class.
please help me whatever you can!
tnx.
import java.awt.Graphics;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Stack;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JInternalFrame;


public class GameWindow extends JInternalFrame implements Serializable {
	private static final long serialVersionUID = 1L;
	public int rows;
	private int columns;
	Stack history=new Stack();
	MainWindow mainWindow=null;
	JButton[][] blocks=null;
	public GameWindow(MainWindow mainWindow, int rows,int columns) {
		this.setTitle("Game Window");
		this.mainWindow=mainWindow;
		this.rows=rows;
		this.columns=columns;
		this.mainwindow.setSize(this.columns*60+20, this.rows*60+60);
		setVisible(true);
		setLayout(null);
		setBounds(0, 0, this.columns*60+10,this.rows*60+33);
		blocks=new JButton[this.rows][this.columns];
		for(int i=0;i<this.rows;i++){
			for(int j=0;j<this.columns;j++){
				blocks[i][j]=new JButton(new ImageIcon("Blocks/Ground.png"));
//				blocks[i][j]=new JButton();
//				paint(blocks[i][j].getGraphics());
				blocks[i][j].setBounds(j*60, i*60, 60, 60);
				blocks[i][j].setFocusable(false);
				blocks[i][j].addActionListener(new GameWindowButtonListener(this,blocks[i][j]));
				blocks[i][j].setBorderPainted(false);
				add(blocks[i][j]);
			}
		}
		this.mainwindow.map = new Map(this.columns,this.rows);///mapo ba column va row new kon na ba row va column
	}
//	public void paint(Graphics g){
//		try {
//			System.out.println(g);
//			g.drawImage(ImageIO.read(new File("Blocks/Ground.png")), 0, 0, this);
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//	}
	public void changing(JButton button){
		JButton b=new JButton();
		b.setFocusable(false);
		b.setIcon(button.getIcon());
		b.setBounds(button.getX(), button.getY(),button.getWidth(),button.getHeight());
		history.push(B)/>;
		}
		public void undo(){
		if(history.size()<=0)
		return;
		JButton b=(JButton) history.pop();
		this.remove(blocks[b.getY()/60][b.getX()/60]);
		blocks[b.getY()/60][b.getX()/60]=b;
		this.add(B)/>;
		repaint();
		}
}


*Edited Code tags added. Please :code:

This post has been edited by pbl: 11 July 2011 - 05:12 PM


Is This A Good Question/Topic? 0
  • +

Replies To: question-client_server by XML

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: question-client_server by XML

Posted 11 July 2011 - 05:14 PM

Why do you need XML ?
If both your Client and Server are written in Java, if both of them share the same code just readObject()/writeObject() to the sockets.
Was This Post Helpful? 0
  • +
  • -

#3 MBT7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 08-April 11

Re: question-client_server by XML

Posted 11 July 2011 - 08:35 PM

yes, I know this way a little.
but I'm interested in working with XML. Otherwise send me a tutorial or sample code that completely learns socket programming if you can.
tnx.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10565
  • View blog
  • Posts: 39,104
  • Joined: 27-December 08

Re: question-client_server by XML

Posted 12 July 2011 - 06:02 AM

Technologies have purposes. It isn't a good idea to use a technology simply for the sake of using it if it has no real purpose in your program. Personally, I see no need for XML here, unless maybe as a way of saving the data. Though for a client-server application, perhaps a SQL database would be better.

For a tutorial on Client/Server applications in Java, check out this link.
Was This Post Helpful? 2
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: question-client_server by XML

Posted 12 July 2011 - 10:07 PM

If you want to get XML expertise good for you. I survided 35 years in the IT business without it. It is like the new fashion about: "regular expression". It seems that any piece of software not using them shouldn't put into production. I don't know why everybody trip on them, I always manage to get a confortable yearly income without knowing nothing about them. I still parse by hand :) And it works :^:
Anyhow, if you need help with socket.writeObject() and socket.readObject() I'll be glad to help :)
May be, surely, I am a dynosaur and after 35 years of programming I wonder how many lines of code I wrote are still used everyday... surely a few hundred thousand :)
Was This Post Helpful? 2
  • +
  • -

#6 MBT7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 08-April 11

Re: question-client_server by XML

Posted 12 July 2011 - 11:09 PM

Yes, you are right! and I gave up XML and started socket programming! :D
I write the beginning of the server and client. and I need to know about frequently problems maybe I encounter with.
My Tank game has a map(the map of the game that contains some kind of blocks) and gameWindow(the graphic mode of the map) and gameKeyListener that handle pressed key and .. .
I started from server. I want to send map and gameWindow to client. I should handle key pressing between server and client.
I need your Help! :D ;)
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: question-client_server by XML

Posted 13 July 2011 - 04:01 AM

Depends if you play on a LAN or over the internet ?
Was This Post Helpful? 0
  • +
  • -

#8 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,444
  • Joined: 20-September 08

Re: question-client_server by XML

Posted 13 July 2011 - 05:34 AM

Don't be too quick to dismiss xml. For instance, it's the basis for an important messaging framework - XMPP, for which Skype are adding support in their latest software.

If you were to look into this, you could

a. leverage existing protocols for use in your game
b. develop experience with XMPP that could benefit you elsewhere (as opposed to developing your own protocol that, while hopefully useful and effective, will likely be a dead end)
Was This Post Helpful? 2
  • +
  • -

#9 MBT7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 08-April 11

Re: question-client_server by XML

Posted 13 July 2011 - 07:33 AM

to plb: I will play over the internet.
to gOOse: yes, generally I like new technologies in programming! but this is my first experience in making game and I'm so hurried to see a result in my work! :D
so I think first I should learn xml in a good way. please help me to learn xml. (specially its application in java).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1