Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
to tentando fazer um esquema doido aqui mais nao funfa de jeito nenhum... java é confuso, ou eu sou confuso, sei la =[[ helpa ai ?
import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.IOException;import java.io.PrintStream;import java.net.Socket;class criaFrame01 { public static void main(String[] args) { Frame f = new Frame(); f.setVisible(true); }}class Frame01 extends JFrame implements ActionListener{ JTextField texto = new JTextField(32); JButton submit = new JButton("Enviar"); Component textarea = new TextArea(); String text; public Frame01() // Construtor { this.setTitle("Socket Teste"); this.setSize(470, 250); this.setResizable(false); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); getContentPane().setLayout(new FlowLayout()); getContentPane().add(textarea); getContentPane().add(texto); submit.addActionListener(this); getContentPane().add(submit); }}class connCliente extends Frame01{ public static void main(ActionEvent e){ if(e.getSource() == "submit"){ ConnCliente con = new ConnCliente(); t.cliente(texto.getText()); } } public char cliente(String args[]) { Socket sock = null; PrintStream stream = null; try{ sock = new Socket("127.0.0.1",7000); stream = new PrintStream(sock.getOutputStream()); stream.println(text); }catch(IOException e){ System.out.println("Error 401: Não foi possivel conectar ao servidor."); }finally{ try{ sock.close(); }catch(IOException e){} } }}ta, pode estar estranho, mais é o melhor jeito que eu to achando para fazer :P
> --------------------Configuration: <Default>--------------------C:\Documents and Settings\Luiz Fernando\Meus documentos\Java\aprendendoSockets\frameCliente.java:16: Frame01 is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListenerclass Frame01 extends JFrame implements ActionListener{^C:\Documents and Settings\Luiz Fernando\Meus documentos\Java\aprendendoSockets\frameCliente.java:48: cannot resolve symbolsymbol : class ConnClientelocation: class connClienteConnCliente con = new ConnCliente();^C:\Documents and Settings\Luiz Fernando\Meus documentos\Java\aprendendoSockets\frameCliente.java:48: cannot resolve symbolsymbol : class ConnClientelocation: class connClienteConnCliente con = new ConnCliente();^C:\Documents and Settings\Luiz Fernando\Meus documentos\Java\aprendendoSockets\frameCliente.java:49: non-static variable texto cannot be referenced from a static contextt.cliente(texto.getText());^C:\Documents and Settings\Luiz Fernando\Meus documentos\Java\aprendendoSockets\frameCliente.java:49: cannot resolve symbolsymbol : variable tlocation: class connClientet.cliente(texto.getText());^5 errorsProcess completed.
abracos
Carregando comentários...