Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-19-2008, 04:00 AM
Member
 
Join Date: Feb 2008
Posts: 5
stessie is on a distinguished road
show a high score from tetris
hi,i have a problem.my program consist to show high scores from tetris which is played on line and we have to use it and add a method which can help us to show high score . The scores have to be shown in JDialog but i don't know how i can write into the JTable the informations receive by the servlet which has answered to my request.
I have written this one but i don't know how to write informations obtained by the servlet ,it is the part in red

private void BtnScoreActionPerformed(ActionEvent evt) {
//System.out.println("BtnScore.actionPerformed, event=" + evt);
//TODO add your code for BtnScore.actionPerformed
String res,nom;
int numPers,score,niveau;
try{
URL url=new URL("http://localhost:8080/ProjetServlet/affscore");
URLConnection connexion=url.openConnection();
connexion.setDoOutput(true);
ObjectOutputStream fluxsortie = new ObjectOutputStream(connexion.getOutputStream());
fluxsortie.writeObject("");
ObjectInputStream fluxentree = new ObjectInputStream(connexion.getInputStream());
SerializedResultSet donnees = (SerializedResultSet) fluxentree.readObject();
//affichage du résultat
donnees.first();
//JTable jTable1 = new JTable(donnees, ( "Position "," nom "," Niveau", " Score " ));
Vector contenu = new Vector();

ListeResultat.setModel(contenu)
for(int i=0;i<donnees.recordCount();i++){
numPers= donnees.getInt("position");
nom= donnees.getString("nom");
niveau= donnees.getInt("niveau");
score= donnees.getInt("score");
//contenu.addElement(res);
donnees.next();
}
if (donnees.recordCount()==0){
res = "aucun score disponible";
contenu.addElement(res);
}
ListeResultat.

}
catch(Exception sql)
System.out.println("erreur"+ sql);
}
}







and i don't know if the request used in servlet is right.Bestjoueurs is an array of names which represent the players with the five best scores and Attributs is a 2D array which represent the level and the score of those players.This is the Servlet program




package MesServlets;

import java.io.*;
import java.sql.Connection;

import java.sql.*;

import javax.naming.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.sql.*;

import SResultSet.SerializedResultSet;

public class ServerTetris extends HttpServlet {
private DataSource ds;
Connection BD;
String requeteentree;
SerializedResultSet sresultat;

protected void DoPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException{
try{
ObjectInputStream entree = new ObjectInputStream(req.getInputStream());
requeteentree =(String)entree.readObject();
ObjectOutputStream sortie = new ObjectOutputStream(res.getOutputStream());
sresultat = ExecuterRequete(requeteentree);
sresultat.first();
sortie.writeObject(sresultat);
}catch(Exception ex){
ex.printStackTrace();
}
}


public SerializedResultSet ExecuterRequete(String Query){
Query = "select * from BestJoueurs,Attributs";
try{
BD =ds.getConnection();
Statement s= BD.createStatement();
ResultSet r= s.executeQuery(Query);
ResultSetMetaData columnNames= r.getMetaData();
SResultSet.SerializedResultSet sResultSet = new SResultSet.SerializedResultSet();
for(int i=1;i<=columnNames.getColumnCount();i++){
sResultSet.addColumn(columnNames.getColumnName(i), i);
}
while(r.next()){
for(int column = 1; column<=columnNames.getColumnCount();column++){
sResultSet.addColumnData(column,r.getObject(column ));
}
}
r.close();
s.close();
BD.close();
s=null;
r=null;
return sResultSet;
}
catch(SQLException ex){
System.out.println("erreur d'execution de la requete SQL: "+ex);
return null;
}
}

public void init(){
try{
Context initCtx = new InitialContext();
System.out.println("lookup de env");
Context envCtx = (Context) initCtx.lookup("java:comp/env");
System.out.println("lookup de base_test");//es ce la meme base?
ds=(DataSource)envCtx.lookup("base_test");
}catch(Exception er){
System.out.println("erreur de chargement du contexte " + er);
}
}
}



i hope there are some people who can help me,thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
netbeans 6.0 not show commpunent or show blank page fahimaamir NetBeans 1 01-26-2008 07:20 AM
Hot domains for sale with high appraisals Bettypeng Reviews / Advertising 0 01-22-2008 09:44 AM
get the average and maximum score Eric Advanced Java 2 07-01-2007 05:15 AM
Java Tetris 1.0 levent Java Announcements 0 05-26-2007 01:32 PM
Klaverjas Score 0.2 levent Java Announcements 0 05-23-2007 08:40 AM


All times are GMT +3. The time now is 11:38 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org