Como fazer busca string no cliente/servidor?

6 respostas
R

Ola, eu não sei como fazer as busca de uma string num cliente servidor para que ele liste todas strings iguais encontradas nos ucuarios e jogar na tela do usuario que pediu a busca para que ele possa escolher e pega-la…alguem pode me dar uma luz??
:?: Valew!!

6 Respostas

R

Cara,

tu quer procurar uma String onde??? no computador dos seus clientes??? ou no teu servidor??? a aplicação agente viu que é cliente/servidor, mas a busca ficou confusa…

tenta dar uma reestruturada na tua pergunta, q a moçada vai te ajudar com certeza…

:wink:

[]'s

F

:razz:
O ferra tranquilo!!!
Espere até amanhã que irei lhe enviar o codigo fonte para pegar no servidor o arquivo ou a String, ai vc muda oque quer buscar, mas fique tranquilo antes das 12:00 lhe envio

Att.

Fritsjava(allan)

R

Bom é o seguinte eu fiz um codigo de um cliente/servidor aqui e tá funcionando blz os usuarios podem se comunicar atraves de mensagens, agora eu queria que o usuario1 pudesse fazer busca atraves do servidor[tipo o emule, kazaa, só que mais simples] ele iria digitar o nome de um arquivo e iria mandar para o servidor, o servidor iria fazer a busca perguntando para cada usuario se ele teria este arquivo, e devolveria todos os resultados [todos arquivos de msm nome que o usuario1 digitou], e depois de todos os arquivos listado na tela do usuario1 ele poderia escolher qual ele acharia melhor e baixar!!
Deu pra entender agora…é que eu não sou muito bom em expressar as coisas qualquer coisa posso tenta explicar melhor.
“fritzjava” se puderes me mandar msm bah vai se uma mão na roda"
Valew!

F

[code]
import java.awt.*;
import java.awt.image.*;
import java.awt.image.ImageObserver;
import java.net.*;
import java.applet.*;
import java.lang.Math;
import java.io.*;
import java.util.*;
import mmmUtil.ReadParam;
import mmmUtil.HelpWindow;

public class ImgView extends Applet {

static String HOMEPAGE="http://www.obs-us.com/people/mihai/";
static String VERSION="Image View 3.6b";
static String AUTHOR="Mihai Munteanu";
static String COPYRIGHT="(c) 1998, 1999";
Image photo; //The curent image
int width, heigth; //the width and th heigth of the curent image
Applet applet; //This applet
boolean sizeknown; //True when the size of the image is known
boolean errored, err;
boolean tooBig, tooSmall, fitOn, oneto1On, appletToSmall; //some flags
char layoutStyle; //the layout type

//Graphical interface
Button btnNext, btnPrev, btnFit, btn1to1, btnZoomIn, btnZoomOut, btnInfo;
Panel pBtn, pSouth, pZoom, pControl, pTitle, p1Title, pEast;
List photoList;
Scrollbar vertScroll =new Scrollbar(Scrollbar.VERTICAL);
Scrollbar horizScroll=new Scrollbar(Scrollbar.HORIZONTAL);
Label labTitle;
Color backCol, prevNextBtnCol, btnCol, labCol, listCol;
Font fBig;
Font fSmall;
Font fSmallB;
HelpWindow helpWindow = new HelpWindow();

String[] fileName; //array that contains the filenames of the images
String[] comments; //array that oontains the comment (caption) for each image
boolean[] notFound; //true if an image was not found

float pwFit, phFit, pw1to1, ph1to1, phZoom, pwZoom;
int px, py, ph, pw, pxFit, pyFit, px1to1, py1to1, pxZoom, pyZoom, maxZoom;

int noOfPhotos = 0; // is incremented for every file name found in ImgView.toc
int pointPhoto = 0; //curent image index
int numberOfPhotos = 1024; // this is used to allocate memory for the fileName and comments arrays.
// default for 1024 photos

int picW, picH; //curent image dysplay size
String about;//the about text

public void init() {

//set the flags
sizeknown=false;
tooBig=false;
tooSmall=false;
oneto1On=false;
fitOn=true;
appletToSmall=false;
layoutStyle='l';

//set the about text
about=setAboutText();

//and the about window
helpWindow.setTitle(VERSION+" - Help");
helpWindow.setText(about);
helpWindow.pack();
helpWindow.resize(500,380);
helpWindow.setResizable(false);

//set the fonts
fBig = new Font("Helvetica", Font.BOLD, 14);
fSmall=new Font("Helvetica", Font.PLAIN, 12);
fSmallB=new Font("Helvetica", Font.BOLD, 12);

//set the colors
backCol=ReadParam.readColor(getParameter("backColor") ,Color.black);
btnCol=ReadParam.readColor(getParameter("buttonsColor") ,Color.lightGray);
labCol=ReadParam.readColor(getParameter("titlesColor") ,Color.yellow);
listCol=ReadParam.readColor(getParameter("listBackColor") ,Color.white);
prevNextBtnCol=ReadParam.readColor(getParameter("buttonsPrevNextColor") ,Color.white);

if(size().width<240 || size().height<180){//checks the size of th eapplet
appletToSmall=true;
}

//check the layout type
String layoutType = "";
layoutType = layoutType + getParameter("layouttype");
if(layoutType.length()>0){
if(layoutType.charAt(0)=='c' || layoutType.charAt(0)=='C'){
layoutStyle='c';
}
if(layoutType.charAt(0)=='r' || layoutType.charAt(0)=='R'){
layoutStyle='r';
}
}

//set the images arrays
numberOfPhotos=ReadParam.readPositiveInt(getParameter("numberOfPhotos"), 1024); //default number of photos is 1024
maxZoom=ReadParam.readPositiveInt(getParameter("maxZoomIn"), 3); //default maximum zoom is 3
photoList =new List(4, false);
photoList.setBackground(listCol);

fileName = new String[numberOfPhotos];
comments = new String[numberOfPhotos];
notFound = new boolean[numberOfPhotos];

try{//this block will read and scan the ImgView.toc file
URL tocfile = new URL(getCodeBase(), "ImgView.toc");
DataInputStream dis= new DataInputStream(tocfile.openStream());
String inputLine;
boolean comment, file;

while((inputLine = dis.readLine()) != null){

StringBuffer f = new StringBuffer();
StringBuffer c = new StringBuffer();

if(inputLine.length()>1){
if(inputLine.charAt(0)=='*'){
comment=false;
file=true;
StringBuffer buff = new StringBuffer();
for(int i=1; i<inputLine.length(); i++){

fileName[noOfPhotos]="";
comments[noOfPhotos]="";

if((inputLine.charAt(i)=='*' || inputLine.charAt(i)=='>' || inputLine.charAt(i)==' ' || inputLine.charAt(i)=='\t') && file==true){
file=false;
}

if(inputLine.charAt(i)=='>' && comment==false){
comment=true;
file=false;
}

if(file){
f.append(inputLine.charAt(i));
}

if(comment){
c.append(inputLine.charAt(i));
}
}

fileName[noOfPhotos]=f.toString();
notFound[noOfPhotos]=false;

if (comment){
String cc = c.toString();

for(int i=1; i<cc.length(); i++){
buff.append(cc.charAt(i));
}
}
else{
String ff = f.toString();
if((ff.lastIndexOf('/')>0)||(ff.lastIndexOf('/'))>0){
for(int i=1+Math.max(ff.lastIndexOf('/'),ff.lastIndexOf('\\')); i<ff.length(); i++){
buff.append(ff.charAt(i));
}
}
else{
for(int i=1+ff.lastIndexOf('*'); i<ff.length(); i++){
buff.append(ff.charAt(i));
}
}
}
comments[noOfPhotos]=buff.toString();
photoList.addItem(buff.toString());
noOfPhotos++;
}
}
}

dis.close();
}catch(MalformedURLException e){
System.out.println(e);
}catch(IOException e){
System.out.println(e);
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("\nThe numberOfPhotos parameter in the <APPLET> tag is smaller\nthan the number of photos in the configuration file!\n\n"+e);
}

labTitle = new Label(" Contacting host...");

if(!appletToSmall){
photo = getImage(getCodeBase(), fileName[pointPhoto]);

pSouth = new Panel();
pBtn = new Panel();
pControl = new Panel();
pZoom = new Panel();
p1Title = new Panel();
pTitle = new Panel();
pEast = new Panel();
btnNext = new Button("Next");
btnNext.setBackground(prevNextBtnCol);
btnPrev = new Button("Previous");
btnPrev.setBackground(prevNextBtnCol);
btnFit = new Button("Fit");
btnFit.setBackground(btnCol);
btn1to1 = new Button("1 : 1");
btn1to1.setBackground(btnCol);
btnZoomIn = new Button("Zoom In");
btnZoomIn.setBackground(btnCol);
btnZoomOut = new Button("Zoom Out");
btnZoomOut.setBackground(btnCol);
btnInfo = new Button("Help");
btnInfo.setBackground(btnCol);

setLayout(new BorderLayout());
pSouth.setLayout(new BorderLayout());
pZoom.setLayout(new GridLayout(1,4));
pTitle.setLayout(new BorderLayout());
p1Title.setLayout(new BorderLayout());

pTitle.add("North", horizScroll);

photoList.select(0);
p1Title.setBackground(labCol);
p1Title.add("Center", labTitle);
pTitle.add("Center", p1Title);

pZoom.add(btnFit);
pZoom.add(btn1to1);
pZoom.add(btnZoomIn);
pZoom.add(btnZoomOut);
pBtn.setLayout(new GridLayout(2,1));

if(layoutStyle=='c'){
pControl.setLayout(new GridLayout(1,2));
pControl.add(btnPrev);
pControl.add(btnNext);
}
else{

pControl.setLayout(new BorderLayout());
pControl.add("West", pBtn);
pControl.add("Center", photoList);
pBtn.add(btnPrev);
btnPrev.disable();
pBtn.add(btnNext);
}

p1Title.add("East", btnInfo);

pSouth.add("Center", pControl);
pSouth.add("South", pZoom);
pSouth.add("North", pTitle);

add("South", pSouth);
add("East", vertScroll);
vertScroll.disable();
horizScroll.disable();
btnFit.disable();
btn1to1.disable();
btnZoomIn.disable();
btnZoomOut.disable();

validate();

picW=size().width-vertScroll.size().width;
picH=vertScroll.size().height;
getsize();
}
else{
labTitle.setText("Applet too small!");
add("Center", labTitle);
validate();
}

}

public boolean imageUpdate(Image theimg, int infoflags, int x, int y, int w, int h){

if((infoflags & (ERROR))!=0){
errored=true;
}

if(sizeknown == false){
if ((infoflags & (WIDTH | HEIGHT)) !=0) {
getsize();
}
}

boolean done = ((infoflags & (ERROR | FRAMEBITS | ALLBITS)) != 0);
repaint(done ? 0 : 200); //repaint every 200miliseconds
return !done;
}

public synchronized void getsize(){

if(errored){
photo = getImage(getCodeBase(), "error.jpg");
repaint();
errored=false;
String tmp = photoList.getItem(pointPhoto);
if(notFound[pointPhoto]!=true){
photoList.replaceItem("Not found: "+tmp, pointPhoto);
comments[pointPhoto]="Not found: "+tmp;
notFound[pointPhoto]=true;
}
photoList.select(pointPhoto);
}

if(sizeknown==false){ //here is the brain of th eapplet
//this block calculates the size of the image

pw1to1 = photo.getWidth(this);
ph1to1 = photo.getHeight(this);
pwFit=pw1to1;
phFit=ph1to1;

if( phFit<0 || pwFit<0){
return;
}
sizeknown=true;
if((phFit>(picH-4))||(pwFit>(picW-4))){ //the image is larger than the applet, must resize the image
if( (phFit/pwFit) < (((float)picH-4)/((float)picW-4))){
phFit=phFit/pwFit;
pwFit=picW-4;
phFit=phFit*pwFit;
pxFit=2;
pyFit=((picH-4)-Math.round(phFit))/2;
}
else{
pwFit=pwFit/phFit;
phFit=picH-4;
pwFit=phFit*pwFit;
pyFit=2;
pxFit=((picW-4)-Math.round(pwFit))/2;
}
}
else{ //the image is smaller than the applet
pyFit=(picH-Math.round(phFit))/2;
pxFit=(picW-Math.round(pwFit))/2;
}
px=pxFit;
py=pyFit;
pw=Math.round(pwFit);
ph=Math.round(phFit);
py1to1=(picH-Math.round(ph1to1))/2;
px1to1=(picW-Math.round(pw1to1))/2;
}
}

public synchronized void paint(Graphics g){
btnFit.disable();
btn1to1.disable();
btnZoomIn.disable();
btnZoomOut.disable();
g.setColor(backCol);
g.fillRect(0,0,picW,picH);
update(g);
}

public synchronized void update(Graphics g) {
getsize();
if(pw<pwFit && ph<phFit){
tooSmall=true;
}
else{
tooSmall=false;
}
if( pw>pw1to1*maxZoom && ph>ph1to1*maxZoom ){
tooBig=true;
}
else{
tooBig=false;
}
if(sizeknown){
if(!fitOn) btnFit.enable();
if(!oneto1On) btn1to1.enable();
if(!tooSmall) {btnZoomOut.enable();}
if(!tooBig) {btnZoomIn.enable();}
labTitle.setText(" "+comments[pointPhoto]);
g.drawImage(photo, px, py, pw, ph, this);
}
}

public boolean action(Event e, Object arg){
Object target = e.target;

if((target == this.btnNext)&&(pointPhoto<(noOfPhotos-1))){
pointPhoto++;
photo = getImage(getCodeBase(), fileName[pointPhoto]);
photoList.select(pointPhoto);
checkPoint();
return true;
}

if((target == this.btnPrev)&&(pointPhoto>0)){
pointPhoto--;
photo = getImage(getCodeBase(), fileName[pointPhoto]);
photoList.select(pointPhoto);
checkPoint();
return true;
}

if(e.target == photoList){
pointPhoto=photoList.getSelectedIndex();
photo = getImage(getCodeBase(), fileName[pointPhoto]);
checkPoint();
return true;
}

if(e.target == this.btnInfo){
helpWindow.show();
return true;
}

if(target == this.btn1to1){
oneto1On=true;
fitOn=false;
px=px1to1;
py=py1to1;
pw=Math.round(pw1to1);
ph=Math.round(ph1to1);
setScroll(px, py, pw, ph, picW, picH);
paint(getGraphics());
return true;
}

if(target == this.btnFit){
oneto1On=false;
fitOn=true;
px=pxFit;
py=pyFit;
pw=Math.round(pwFit);
ph=Math.round(phFit);
setScroll(px, py, pw, ph, picW, picH);
paint(getGraphics());
return true;
}

if(target == this.btnZoomIn && !tooBig){
btnZoomIn.disable();
px=(int)(1.5*px-picW/4);
py=(int)(1.5*py-picH/4);
pw=(int)(pw*1.5);
ph=(int)(ph*1.5);
setScroll(px, py, pw, ph, picW, picH);
oneto1On=false;
fitOn=false;
paint(getGraphics());
return true;
}

if(target == this.btnZoomOut && !tooSmall){
btnZoomOut.disable();
px=(int)(px/1.5+picW/6);
py=(int)(py/1.5+picH/6);
pw=(int)(pw/1.5);
ph=(int)(ph/1.5);

if(px>0){
if(pw<picW){
px=(picW-pw)/2;
}
else{
px=0;
}
}
if(px+pw<picW){
if(pw>picW){
px=picW-pw;
}
else{
px=(picW-pw)/2;
}
}
if(py>0){
if(ph<picH){
py=(picH-ph)/2;
}
else{
py=0;
}
}
if(py+ph<picH){
if(ph>picH){
py=picH-ph;
}
else{
py=(picH-ph)/2;
}
}

setScroll(px, py, pw, ph, picW, picH);
oneto1On=false;
fitOn=false;
paint(getGraphics());
return true;
}
return false;
}

public boolean handleEvent(Event evt){

switch(evt.id){
case Event.SCROLL_LINE_UP:
case Event.SCROLL_LINE_DOWN:
case Event.SCROLL_PAGE_UP:
case Event.SCROLL_PAGE_DOWN:
case Event.SCROLL_ABSOLUTE:
if(evt.target == horizScroll){
px=-((Integer)evt.arg).intValue();
if(px>=0){
px=0;
}
if(px<=picW-pw){
px=picW-pw;
}
repaint(0,0,picW,picH);
}
if(evt.target == vertScroll){
py=-((Integer)evt.arg).intValue();
if(py>=0){
py=0;
}
if(py<=picH-ph){
py=picH-ph;
}
repaint(0,0,picW,picH);
}
}
return super.handleEvent(evt);
}

private void setScroll(int x, int y, int w, int h, int pW, int pH){

horizScroll.disable();
vertScroll.disable();

if( (x<0) || ((x+w)>picW)){
horizScroll.setValues(-x, 1, 0, w-pW);
horizScroll.setPageIncrement(16);
horizScroll.setLineIncrement(4);
horizScroll.enable();
}

if( (y<0) || ((y+h)>picH)){
vertScroll.setValues(-y, 1, 0, h-pH);
vertScroll.setPageIncrement(16);
vertScroll.setLineIncrement(4);
vertScroll.enable();
}
}

private void checkPoint(){ //Check what buttons should be enabled or desabled
labTitle.setText(" Contacting host...");
if(pointPhoto<=(noOfPhotos-2)){
btnNext.enable();
}
else{
btnNext.disable();
}
if(pointPhoto>=1){
btnPrev.enable();
}
else{
btnPrev.disable();
}

sizeknown=false;

btnFit.disable();
btn1to1.disable();
btnZoomIn.disable();
btnZoomOut.disable();

horizScroll.disable();
vertScroll.disable();
tooBig=false;
tooSmall=false;
oneto1On=false;
fitOn=true;
paint(getGraphics());
}

private String setAboutText(){
String copyright=VERSION+" - image browser applet\n"+COPYRIGHT+" "+AUTHOR+"\n\nThis program is free software; you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation; either version 2 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software\nFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\nYou can contact me at:\n\n* http://www.obs-us.com/people/mihai\n* e-mail: [email removido] or ";
String help=VERSION+" - Help\n\nBrowsing Controls:\n\n* Previous - Loads and displays the previous picture\n* Next - Loads and displays the next picture\n* Picture List - Double click on the chosen title to load and display the picture\n\nNOTE:\nThe picture list is not displayed in the compact version of the layout\n\nZoom Controls:\n\n* Fit - Fits the picture in the display area\n* 1 : 1 - Displays the picture at its original size\n* Zoom In - Magnifies the picture size 1.5 times\n* Zoom In - Reduces the picture size 1.5 times\n\nNOTES:\n* If the image is smaller than the display area '1 : 1' and 'Fit' produce the same result.\n* The number of zooming steps is limited.\n\n\n";
return help+copyright;
}

public String getAppletInfo() {
return VERSION+" "+COPYRIGHT+" "+AUTHOR+" - ";
}
}

[code]

Att.
Fritsjava
[/b][/code]

F

Bom Dia!!!

rafaelscb

Bom guri não gosto de ficar so na conversa; o trecho acima que lhe envie pega o arquivo do servidor, ele realmente funciona, já está sendo usado!!

Ele é original da Romenia cidade de Brasov sendo que seu autor principal é:
Mihai Munteanu
em 1999 aonde o java era baby ainda.

Este trecho é registrado e publicado por favor não tente vender!!

Mas é aberto

Se quiser posso lhe enviar ele por e-mail é so disponibilizar ele!!

Att.
Fritsjava - Xanxerê

R

“FritsJava”:
Bom Dia!!!

rafaelscb

Bom guri não gosto de ficar so na conversa; o trecho acima que lhe envie pega o arquivo do servidor, ele realmente funciona, já está sendo usado!!

Ele é original da Romenia cidade de Brasov sendo que seu autor principal é:
Mihai Munteanu
em 1999 aonde o java era baby ainda.

Este trecho é registrado e publicado por favor não tente vender!!

Mas é aberto

Se quiser posso lhe enviar ele por e-mail é so disponibilizar ele!!

Att.
Fritsjava - Xanxerê

Cara valeu, achu que com isso vai da pra faze o que eu queria…pode cre!! :grin:

Criado 14 de abril de 2005
Ultima resposta 15 de abr. de 2005
Respostas 6
Participantes 3