Skip to content

Commit d66712e

Browse files
committed
finaleira tem que ver a situação do arquivo
1 parent 0145a26 commit d66712e

1 file changed

Lines changed: 88 additions & 29 deletions

File tree

src/br/feevale/TelaChat.java

Lines changed: 88 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void keyPressed(KeyEvent e) {
120120
@Override
121121
public void actionPerformed(ActionEvent e) {
122122
// TODO Auto-generated method stub
123-
enviaArquivo();
123+
perguntaEnviarArquivo();
124124
}
125125
});
126126

@@ -199,8 +199,8 @@ protected void enviaMensagem() {
199199
}
200200
}
201201

202-
private void enviaArquivo() {
203-
202+
private void perguntaEnviarArquivo() {
203+
// TODO Auto-generated method stub
204204
fc = new JFileChooser();
205205
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
206206
int returnVal = fc.showOpenDialog(TelaChat.this);
@@ -209,37 +209,25 @@ private void enviaArquivo() {
209209

210210
File file = fc.getSelectedFile();
211211

212-
mensagem.setText(file.getName());
213-
214-
int confirma = JOptionPane.showConfirmDialog(null,
215-
"Deseja enviar o arquivo:" + file.getName(), "Atenção",
216-
JOptionPane.YES_NO_OPTION);
217-
218-
if (confirma == JOptionPane.YES_OPTION) {
219-
220-
System.out.println(file);
221-
222-
try {
223-
JSONObject obj = new JSONObject();
224-
obj.put("tpTransacao", 3);
225-
obj.put("arquivo", file);
226-
227-
enviaTransacao(obj);
228-
229-
escreveNoLog(meuNome + ": " + file.getName());
230-
231-
} catch (Exception e) {
232-
e.printStackTrace();
233-
}
212+
try {
213+
JSONObject obj = new JSONObject();
214+
obj.put("tpTransacao", 3);
215+
obj.put("arquivo", file.getName());
216+
obj.put("tamanho", file.length());
234217

235-
} else {
218+
enviaTransacao(obj);
236219

237-
mensagem.setText(null);
238-
mensagem.requestFocus();
220+
} catch (Exception e) {
221+
e.printStackTrace();
239222
}
240223
}
241224
}
242225

226+
private void respondeEnviarArquivo() {
227+
// TODO Auto-generated method stub
228+
229+
}
230+
243231
private class LeitorDeSocket extends Thread {
244232

245233
@Override
@@ -266,13 +254,26 @@ public void run() {
266254
trataMensagem(obj);
267255
break;
268256
case 3:
269-
trataArquivo(obj);
257+
chamaAtencao();
258+
break;
259+
case 4:
260+
perguntaEnviarArquivo();
261+
break;
262+
case 5:
263+
respondeEnviarArquivo();
264+
break;
265+
270266
}
267+
268+
trataArquivo(obj);
269+
break;
270+
271271
}
272272
} catch (Exception e) {
273273
e.printStackTrace();
274274
}
275275
}
276+
276277
}
277278

278279
private void escreveNoLog(String msg) {
@@ -340,5 +341,63 @@ public void chamaAtencao() {
340341
} catch (LineUnavailableException e) {
341342
e.printStackTrace();
342343
}
344+
345+
346+
347+
private void trataPerguntaEnviarArquivo(JSONObject obj) {
348+
// TODO Auto-generated method stub
349+
350+
String arquivo = obj.getString("arquivo");
351+
String tamanho = obj.getString("tamanho");
352+
353+
respostaEnviarArquivo();
354+
355+
String mensagem = obj.getString("msg");
356+
357+
escreveNoLog(outroNome + ": " + mensagem);
358+
}
359+
360+
361+
private void respostaEnviarArquivo() {
362+
// TODO Auto-generated method stub
363+
int confirma = JOptionPane.showConfirmDialog(null,
364+
"Deseja receber o arquivo/n" + arquivo + "/n " + tamanho , "Atenção",
365+
JOptionPane.YES_NO_OPTION);
366+
367+
if (confirma == JOptionPane.YES_OPTION) {
368+
try {
369+
JSONObject obj = new JSONObject();
370+
obj.put("tpTransacao", 6);
371+
obj.put("resposta", true);
372+
obj.put("porta", 6666)
373+
374+
enviaTransacao(obj);
375+
376+
} catch (Exception e) {
377+
e.printStackTrace();
378+
}
379+
}else{
380+
try {
381+
JSONObject obj = new JSONObject();
382+
obj.put("tpTransacao", 6);
383+
obj.put("resposta", false);
384+
385+
enviaTransacao(obj);
386+
387+
} catch (Exception e) {
388+
e.printStackTrace();
389+
}
390+
}
391+
}
392+
393+
private void trataRespostaEnviarArquivo(JSONObject obj) {
394+
// TODO Auto-generated method stub
395+
boolean resposta = obj.get("resposta");
396+
if(resposta = true){
397+
int porta = obj.getInt("porta");
398+
399+
}
400+
}
401+
343402
}
344403
}

0 commit comments

Comments
 (0)