stuck with code

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

38 Replies - 1560 Views - Last Post: 04 June 2008 - 10:37 PM Rate Topic: -----

#31 pbl  Icon User is offline

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

Reputation: 8032
  • View blog
  • Posts: 31,202
  • Joined: 06-March 08

Re: stuck with code

Posted 04 June 2008 - 09:16 PM

View Postpbl, on 4 Jun, 2008 - 09:02 PM, said:



OK see the stuff... I passed the 3 first level
Seem simple to me.... when you say "you loose" you should stop the listener

in ALL your mix class

boolean loose = false;

whenever the player looses instead of just System.out.println("You loose") add
loose = true;

			  if(a[i]>=101 && a[i]<=731 && b[i]>=150 && b[i]<=155){
					  System.out.println("you lose");
					  score--;
					  System.out.println(score);
					  loose = true;
			  }



and in your mouseMotionListener don't react if the user has loose

		 public void mouseMoved(MouseEvent e) {
			  if(loose)
				return;



That should do it

P.S. your if(... && ... && ... && are really ugly there are better ways to code that
Was This Post Helpful? 0
  • +
  • -

#32 killer_beast  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 31-May 08

Re: stuck with code

Posted 04 June 2008 - 09:34 PM

View Postpbl, on 4 Jun, 2008 - 09:16 PM, said:

View Postpbl, on 4 Jun, 2008 - 09:02 PM, said:



OK see the stuff... I passed the 3 first level
Seem simple to me.... when you say "you loose" you should stop the listener

in ALL your mix class

boolean loose = false;

whenever the player looses instead of just System.out.println("You loose") add
loose = true;

			  if(a[i]>=101 && a[i]<=731 && b[i]>=150 && b[i]<=155){
					  System.out.println("you lose");
					  score--;
					  System.out.println(score);
					  loose = true;
			  }



and in your mouseMotionListener don't react if the user has loose

		 public void mouseMoved(MouseEvent e) {
			  if(loose)
				return;



That should do it

P.S. your if(... && ... && ... && are really ugly there are better ways to code that



okey i want to know is the program working , i am not talking about the code right now , just that is it working fine and till now i havnt received a single comment on client server program , that is my main concern right now , really i am quite worried about whether it works or not , if that clientserver program doesnt work the whole work means nothing
the purpose of the projects was to establish a client server program
Was This Post Helpful? 0
  • +
  • -

#33 pbl  Icon User is offline

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

Reputation: 8032
  • View blog
  • Posts: 31,202
  • Joined: 06-March 08

Re: stuck with code

Posted 04 June 2008 - 09:47 PM

View Postkiller_beast, on 4 Jun, 2008 - 09:34 PM, said:

okey i want to know is the program working , i am not talking about the code right now , just that is it working fine and till now i havnt received a single comment on client server program , that is my main concern right now , really i am quite worried about whether it works or not , if that clientserver program doesnt work the whole work means nothing
the purpose of the projects was to establish a client server program

Your program is working....
And actually had fun testing it...
I am impressed by the way you draw your rectangles (even if I don't like the way you had to create 5 different classes for the 5 different levels of complexity)
but... sorry to disappoint you ... this is not a Client/Server program at all at least not in the usual Client/Server terminology
What do you think is the Srver ? what do you thinl is the Client ?
You just have on a computer a JFrame with buttons that launches on the same computer a new JFrame into which a MouseListenr checks if you are going to exceed the limits of a corridor... no Client/Server technology involved at all in the code you write
Was This Post Helpful? 0
  • +
  • -

#34 killer_beast  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 31-May 08

Re: stuck with code

Posted 04 June 2008 - 10:00 PM

View Postpbl, on 4 Jun, 2008 - 09:47 PM, said:

View Postkiller_beast, on 4 Jun, 2008 - 09:34 PM, said:

okey i want to know is the program working , i am not talking about the code right now , just that is it working fine and till now i havnt received a single comment on client server program , that is my main concern right now , really i am quite worried about whether it works or not , if that clientserver program doesnt work the whole work means nothing
the purpose of the projects was to establish a client server program

Your program is working....
And actually had fun testing it...
I am impressed by the way you draw your rectangles (even if I don't like the way you had to create 5 different classes for the 5 different levels of complexity)
but... sorry to disappoint you ... this is not a Client/Server program at all at least not in the usual Client/Server terminology
What do you think is the Srver ? what do you thinl is the Client ?
You just have on a computer a JFrame with buttons that launches on the same computer a new JFrame into which a MouseListenr checks if you are going to exceed the limits of a corridor... no Client/Server technology involved at all in the code you write



well here it is
import javax.swing.*;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;

class pla extends JFrame implements ActionListener
{
private JPanel x=new JPanel();
private JButton b1=new JButton("1");
private JButton b2=new JButton("2");
private JButton b3=new JButton("3");
private JButton b4=new JButton("4");
private JButton b5=new JButton("5");
private JTextField t=new JTextField(1);
private  BufferedWriter OBW = null;
private  BufferedReader IBR = null;
private Socket soc = null;
Socket Csoc;
ServerSocket Ssoc;
int terrain=-1;
// int r;
//final_class fc = new final_class();
public pla(String text,int a){
	//if a=0->cliente		   a=1 -> server
	super(text);
	getContentPane().add(x);
	setSize(300,300);
	setVisible(true);

	{   if(a==0)
	{String server = new String("");
	try 
	{
	 // etablissement de la connexion cote client sur le port 20000
	 System.out.print("Etablissement connexion avec le serveur ...");
	 soc = new Socket(server,20000);
	 System.out.println(" Le serveur " + server + " nous a reconnu");

	 // phase de communication avec le serveur :
	 // creation des objets de type InputStream et OutputStream
	 // correspondant a l'etablissement d'un flux de donnees
	 // permettant d'echanger des informations avec le serveur
	 InputStream IS = soc.getInputStream();
	 OutputStream OS = soc.getOutputStream();

	// Afin de pouvoir utiliser des entrees/sorties formatees,
	// mise en place de tampons de donnees
	 IBR = new BufferedReader(new InputStreamReader(IS));
	 OBW = new BufferedWriter(new OutputStreamWriter(OS));
	}
	catch(IOException e)
	  { System.out.println("I/O exception error "); }
   
	}
	else if(a==1)
	{

		String reponse;
		int nbrcar,figure;
		 try 
			{ 
			 // etablissement du service cote serveur sur le port 20000
			 // creation du socket serveur que l'on attache au port 20000
			 System.out.print("generating the server at port 20000 ...");
			 Ssoc = new ServerSocket(20000, 180);
			 System.out.println(" OK");
			// phase d'attente d'une connexion avec un client
			System.out.print("waiting for connection with cliente ...");
			Csoc = Ssoc.accept();   // lors de la connexion, on cree le
				 // socket client qui va servir a etablir la communication
			System.out.println("connection with cliente acheived");

			InputStream IS = Csoc.getInputStream();
			OutputStream OS = Csoc.getOutputStream();

			 IBR = new BufferedReader(new InputStreamReader(IS));
			 OBW = new BufferedWriter(new OutputStreamWriter(OS));
			 
			 reponse = new String(IBR.readLine()); // lecture chaine de caracteres
			 System.out.println("the client replied that: " + reponse);
			 
			}
		 catch(UnknownHostException e) { }
		 catch(IOException e)
			  { System.out.println("Erreur entree/sortie pendant la connexion"); }
	}
	}
	x.add(b1);	b1.addActionListener((ActionListener) this);
	x.add(b2);	b2.addActionListener((ActionListener) this);
	x.add(b3);	b3.addActionListener((ActionListener) this);
	x.add(b4);	b4.addActionListener((ActionListener) this);
	x.add(b5);	b5.addActionListener((ActionListener) this);
	x.add(t);
	b1.setVisible(true);b2.setVisible(true);b3.setVisible(true);b4.setVisible(true);b5.setVisible(true);t.setVisible(true);
	
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
}
public void actionPerformed(ActionEvent ev){
	if(ev.getSource()==b1){t.setText("1");terrain=1;}
	if(ev.getSource()==b2){t.setText("2");terrain=2;}
	if(ev.getSource()==b3){t.setText("3");terrain=3;}
	if(ev.getSource()==b4){t.setText("4");terrain=4;}
	if(ev.getSource()==b5){t.setText("5");terrain=5;}
	//fc.passVart(terrain);
	switch(terrain){
	case 1: x.remove(b1);b1.setVisible(false);break;
	case 2: x.remove(b2);b2.setVisible(false);break;
	case 3:x.remove(b3);b3.setVisible(false);break;
	case 4: x.remove(b4);b4.setVisible(false);break;
	case 5: x.remove(b5);b5.setVisible(false);break;
	
	default: break;}
	}

public void closeserver(){
	System.out.print("Enfin, on ferme la communication avec le client ...");
   try{ Csoc.close();}catch(IOException ea){};
	System.out.println(" C'est fait, au revoir le client ...\n");
	System.out.print("\nPuis on arrete le service sur le port 20000 ...");
	try{Ssoc.close();}
   catch(Exception ea){ System.out.println("Erreur d'entree/sortie"); }
}
public void closeclient()
{
	System.out.print("Enfin, on ferme la communication ...");
try{	soc.close();}	
catch(UnknownHostException eaa)
  { System.out.println("le nom du serveur est inconnu"); }
catch(IOException eaa)
  { System.out.println("Erreur entree/sortie pendant la connexion"); }
System.out.println(" OK");

}
}



did you use the same pla class defination as above , if yes , how did you make it work , i couldnt do it with eclipse

This post has been edited by killer_beast: 04 June 2008 - 10:08 PM

Was This Post Helpful? 0
  • +
  • -

#35 pbl  Icon User is offline

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

Reputation: 8032
  • View blog
  • Posts: 31,202
  • Joined: 06-March 08

Re: stuck with code

Posted 04 June 2008 - 10:18 PM

oupalai toute une differente paire de manches...
puis la version Client ou est-elle ?
ne me dites pas que je vais avoir a cut&paste 50 differentes classes pour tester to ca ?
Le code original ne montrait pas tou ca...
La facon la plus facile est d'envoyer sur le OutputStream (si le client ne l'a pas) le JFrame a montrer en tant qu'objet Java et de le montrer chez le client.
"killer_beast" ce n'est pas tres francais :)

P.S.
sorry it is gainst this forum policy to use another language than Bill Gates mother tong but after seing the comments in French the temptation was too hard

This post has been edited by pbl: 04 June 2008 - 10:25 PM

Was This Post Helpful? 0
  • +
  • -

#36 killer_beast  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 31-May 08

Re: stuck with code

Posted 04 June 2008 - 10:19 PM

yeah i understand what you mean for th client server program , here i am creating a sever and a client on the same machine as i dont have 2 computers now . but in our collage lab i will test it on two machines
Was This Post Helpful? 0
  • +
  • -

#37 pbl  Icon User is offline

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

Reputation: 8032
  • View blog
  • Posts: 31,202
  • Joined: 06-March 08

Re: stuck with code

Posted 04 June 2008 - 10:28 PM

View Postkiller_beast, on 4 Jun, 2008 - 10:19 PM, said:

yeah i understand what you mean for th client server program , here i am creating a sever and a client on the same machine as i dont have 2 computers now . but in our collage lab i will test it on two machines

good luck

Start a new thread/post with your client/server problem... 4 pages of replies start to be annoying
Was This Post Helpful? 0
  • +
  • -

#38 killer_beast  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 31-May 08

Re: stuck with code

Posted 04 June 2008 - 10:29 PM

View Postpbl, on 4 Jun, 2008 - 10:18 PM, said:

oupalai toute une differente paire de manches...
puis la version Client ou est-elle ?
ne me dites pas que je vais avoir a cut&paste 50 differentes classes pour tester to ca ?
Le code original ne montrait pas tou ca...
La facon la plus facile est d'envoyer sur le OutputStream (si le client ne l'a pas) le JFrame a montrer en tant qu'objet Java et de le montrer chez le client.
"killer_beast" ce n'est pas tres francais :)

P.S.
sorry it is gainst this forum policy to use another language than English but after seing the comments in French the temptation was too hard


yeah it is not french because i am not french , i am studying in france , actually i am from india :),
so in the pla class when i say that the value of a==0 it is the program for the client and when it is equal to 1 it creates the server
now i told you in the beginning of this conversation that i am really not sure about this part of the program , do you think that it will work on 2 different machines ( actually at collage we have unix ), i think we will do it by altering the ports or something like that .

This post has been edited by killer_beast: 04 June 2008 - 10:31 PM

Was This Post Helpful? 0
  • +
  • -

#39 pbl  Icon User is offline

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

Reputation: 8032
  • View blog
  • Posts: 31,202
  • Joined: 06-March 08

Re: stuck with code

Posted 04 June 2008 - 10:37 PM

View Postkiller_beast, on 4 Jun, 2008 - 10:29 PM, said:

View Postpbl, on 4 Jun, 2008 - 10:18 PM, said:

oupalai toute une differente paire de manches...
puis la version Client ou est-elle ?
ne me dites pas que je vais avoir a cut&paste 50 differentes classes pour tester to ca ?
Le code original ne montrait pas tou ca...
La facon la plus facile est d'envoyer sur le OutputStream (si le client ne l'a pas) le JFrame a montrer en tant qu'objet Java et de le montrer chez le client.
"killer_beast" ce n'est pas tres francais :)

P.S.
sorry it is gainst this forum policy to use another language than English but after seing the comments in French the temptation was too hard


yeah it is not french because i am not french , i am studying in france , actually i am from india :),
so in the pla class when i say that the value of a==0 it is the program for the client and when it is equal to 1 it creates the server
now i told you in the beginning of this conversation that i am really not sure about this part of the program , do you think that it will work on 2 different machines ( actually at collage we have unix ), i think we will do it by altering the ports or something like that .


A JFrame is a Java Object if the receiving socket knows anything about Java it should be able to understand it and display it accordingly
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3