Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: NEED HELP! Beginner JApplet Problems

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default NEED HELP! Beginner JApplet Problems

    This is my code for a Client to a Server that asks for IP address and Port

    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class EchoClientJDK121 extends JFrame {
    private JTextField enter;
    private JTextArea display;
    ObjectOutputStream write;
    ObjectInputStream read;
    String message = "";
    String IP;
    String Port;
    private JTextField Input;
    private JTextField PORT;

    public EchoClientJDK121( ) {
    super( "Client" );

    Container c = getContentPane( );

    Input = new JTextField();
    Input.setEnabled(false);
    Input.addActionListener(
    new ActionListener(){
    public void actionPerformed(ActionEvent i){
    GetIP(i.getActionCommand());
    Input.setText("ipAddress: ");
    }
    });

    enter = new JTextField( );
    enter.setEnabled( false );
    enter.addActionListener(
    new ActionListener( ) {
    public void actionPerformed( ActionEvent e )
    {

    sendData( e.getActionCommand( ) );
    enter.setText("");
    }
    }
    );
    GetPort(PORT);

    c.add(PORT, BorderLayout.SOUTH);
    c.add( enter, BorderLayout.NORTH );
    c.add(Input, BorderLayout.SOUTH);

    display = new JTextArea( );
    c.add( new JScrollPane( display ),
    BorderLayout.CENTER );

    setSize( 300, 150 );
    show( );
    }
    public void GetIP(String ip){
    try{
    IP = ip;

    display.append( "\nIP>>>" + ip );
    }
    catch ( IOException cnfex ) {
    display.append( "\nError writing object" );
    }

    }
    public void GetPort(JTextField Port){

    Port = new JTextField();
    Input.setEnabled(false);
    Input.addActionListener(
    new ActionListener(){
    public void actionPerformed(ActionEvent p){
    sendPort( e.getActionCommand( ) );
    enter.setText("Port: ");

    }
    });

    }
    public void SendPort(String Port){
    try{
    String PORT = Port;
    write.writeObject( "CLIENT>>> " + Port ); write.flush( );
    display.append( "\nCLIENT>>>" + Port );
    }
    catch ( IOException cnfex) {
    display.append( "\nError writing object" );
    }
    }





    public void runEchoClientJDK121() {
    Socket client;

    try {
    Integer.parseInt(IP);
    Integer.parseInt(Port);

    // Step 1: Create a Socket to make connection.
    display.setText( "Attempting connection\n" );
    client = new Socket( InetAddress.getByName( IP ), Port );

    display.append( "Connected to: " +
    client.getInetAddress( ).getHostName( ) );

    // Step 2: Get the input and output streams.
    write = new ObjectOutputStream( client.getOutputStream( ) );
    write.flush( );

    read = new ObjectInputStream( client.getInputStream( ) );
    display.append( "\nGot I/O streams\n" );

    // Step 3: Process connection.
    enter.setEnabled( true );

    do { //Print message as they are recieved.
    try {
    message = (String) read.readObject( ); //Blocking read.
    display.append( "\n" + message );
    display.setCaretPosition( display.getText( ).length( ) );
    }
    catch ( ClassNotFoundException cnfex ) {
    display.append( "\nUnknown object type received" );
    }
    } while ( !message.equals( "SERVER>>> TERMINATE" ) );

    // Step 4: Close connection.
    display.append( "Closing connection.\n" );
    write.close( ); read.close( ); client.close( );
    }
    catch ( EOFException eof ) {
    System.out.println( "Server terminated connection" );
    }
    catch ( IOException e ) {
    e.printStackTrace( );
    }
    }

    private void sendData( String s ) {
    try {
    message = s;
    write.writeObject( "CLIENT>>> " + s ); write.flush( );
    display.append( "\nCLIENT>>>" + s );
    }
    catch ( IOException cnfex ) {
    display.append( "\nError writing object" );
    }
    }

    public static void main( String args[ ] ) {
    EchoClientJDK121 app = new EchoClientJDK121( );

    app.addWindowListener(
    new WindowAdapter( ) {
    public void windowClosing( WindowEvent e )
    { System.exit( 0 ); }
    }
    );
    app.runEchoClientJDK121( );
    }
    }


    I am getting the error:
    Java 76: error: cannot find symbol
    sendPort( e.getActionCommand( ) );

    error: no suitable constructor found for Socket( InetAddress, String)
    client = new Socket( InetAddress.getByName( IP), Port);


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: NEED HELP! Beginner JApplet Problems

    Integer.parseInt(String) returns an int which you would usually assign to an int variable, unless you were just testing the String out of interest.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED HELP! Beginner JApplet Problems

    Quote Originally Posted by Sean4u View Post
    Integer.parseInt(String) returns an int which you would usually assign to an int variable, unless you were just testing the String out of interest.
    Oh wow, im dumb, i fixed that but the first error is still popping up, the cannot find symbol one

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: NEED HELP! Beginner JApplet Problems

    What is sendPort()? Is it within the scope of the call?

  5. #5
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: NEED HELP! Beginner JApplet Problems

    Quote Originally Posted by bam0792 View Post
    Oh wow, im dumb, i fixed that but the first error is still popping up, the cannot find symbol one
    public void SendPort(String Port){
    ...
    Java 76: error: cannot find symbol
                sendPort( e.getActionCommand( ) );

Similar Threads

  1. Animation in JApplet
    By Aurin in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 14th, 2012, 10:18 AM
  2. Components I add to JApplet won't appear!
    By austin.rose94 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 6th, 2012, 11:47 AM
  3. Sockets in JApplet
    By shrey.haria in forum Java Networking
    Replies: 4
    Last Post: September 5th, 2011, 10:45 AM
  4. JApplet Not Running In Firefox
    By aussiemcgr in forum Java Theory & Questions
    Replies: 13
    Last Post: August 13th, 2011, 09:40 AM
  5. Cannot update Jlabel in JApplet
    By rin in forum Java Applets
    Replies: 2
    Last Post: April 17th, 2010, 09:21 AM