Hello,
I need your help again guys. I am trying to make a pop up form name setIPInterface (when the user click on a button in the form "ClientInterface"), for a user to input an ip address in a textfield and when the user click on the button "Set", the value of the textfield will be send to a method named "setIP()" found in another class named "Client()".

The code of the button "Set":

theClient.setIPAddress(txtIPAddress.getText());

theClient is an instance of the class Client.

but I've got the following error:

java:75: cannot find symbol
symbol : variable theClient
location: class ignisv10.SetIP
theClient.setIPAddress(txtIPAddress.getText());
1 error

Note that the instance "theClient" have already been instantiated in the form "ClientInterface". The user clicks on the button which is found on the ClientInterface form then another form will pop up named "setIPInterface".

Thanks in advance for your help.

You're using netbeans? It doesn't matter what you're using though, Java works the same regardless. If you're in one class, and you make an instance of that class, a different class will not know it exists. In order for this to happen, you would have to have something like the following:

public class whatever{

whatever oneThing= new whatever();
}

public class anything{
whatever wv = null;
public anything(whatever stuff){
wv = stuff;
}
}

I hope you see what I'm trying to get at here.

Sorry, but I am a bit confused. The class has already been initialized, I want to use the instance that have already been initialized but with is found in another class.

The only way to use that instance is to have a variable of that class's type in the other class. So if you have two classes, class one and class two, and you want to use class one from inside class two, class two has to have a variable of type class one.

Can you give me an example please. I am stuck on this part of the program, I am currently developing a chat system and am a bit new to Java. I just want to understand the concept of communicating between classes.

Actually there are 3 classes. Class 2 already have an instance of class 1, I want class 3 to use the same instance of class 2 to be able to use a method found in class 1.

Thanks in advance.

public class First{

First thing = new First();
public static void main(String[] args){
Second second = new Second(thing);
}

}

public class Second{

First whatever = null;

public Second(First param){
whatever = param;
}
}

You basically just pass one Object of the first class's type as a parameter to a method in the other class.

Thanks for the answer. But what should I put in the third class button.

Let said, the third class contain a button named "Set" and on click it should pass the value IP(fetch from a text field in the third class itself) to the class 1?

If you have an object, you can use methods in that Object's class. So if you used the setup I had above, you could access any instance variables of "whatever" from the Second class.

Hello, thanks again for the answer, I've have tried it but its not working. Wait, I am sending you the class 2 and class 3.

The Class 1 contains the the Class Client() and the methods setIP and getIP. I am not sending the class 1 because its an assignment, I have worked hard on it, I don't want another student to put hand on my code. Hope you understand.

Note: The Class 2 contains the main and the interface of the client.

The Class 3 is the pop up form that i want to use in order to set the ip in class 1.

//theClient.setIPAddress(txtIPAddress.getText());

. Check this part in the class 3, its here that I want to pass the value to class 1.

Actually, I don't even know if what I am doing is possible or not in Java. I just want to make my interface easier to use.

I hope that you have understood my objective. Many thanks in advance dude.

Attachments
package ignisv10;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.*;

import javax.swing.JOptionPane;
public class ClientInterface extends javax.swing.JFrame {

    /** Creates new form ClientInterface */
//    public ClientInterface() {
//        initComponents();
//    }

    private static int incrementor= 0;
    private static String clientIdentifier;
    JFileChooser fc = new JFileChooser();


  Client theClient; // Add a variable to the GUI class to hold a reference to the server

   public ClientInterface(Client c) { // add a new constructor that takes a server reference as parameter
        super("");
        theClient = c; // save a ref to the server
        initComponents();
   }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jDialog1 = new javax.swing.JDialog();
        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu4 = new javax.swing.JMenu();
        jMenu5 = new javax.swing.JMenu();
        txtSendMessage = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtChatBox = new javax.swing.JTextArea();
        btnSend = new javax.swing.JButton();
        btnConnect2Server = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        lblStatus = new javax.swing.JLabel();
        btnKnockOut = new javax.swing.JButton();
        txtIPAddress = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        btnBrowse = new javax.swing.JButton();
        btnSendFile = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        jMenu4.setText("File");
        jMenuBar2.add(jMenu4);

        jMenu5.setText("Edit");
        jMenuBar2.add(jMenu5);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("iGnis Client");
        setBackground(new java.awt.Color(204, 255, 204));
        setResizable(false);

        txtSendMessage.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        txtSendMessage.setForeground(new java.awt.Color(153, 153, 255));
        txtSendMessage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSendMessageActionPerformed(evt);
            }
        });

        txtChatBox.setColumns(20);
        txtChatBox.setEditable(false);
        txtChatBox.setRows(5);
        jScrollPane1.setViewportView(txtChatBox);

        btnSend.setText("Send");
        btnSend.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSendActionPerformed(evt);
            }
        });

        btnConnect2Server.setText("Connect 2 Server");
        btnConnect2Server.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConnect2ServerActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel1.setText("Status: ");

        lblStatus.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        lblStatus.setForeground(new java.awt.Color(255, 51, 51));
        lblStatus.setText("Disconnected");

        btnKnockOut.setText("Knock Out");
        btnKnockOut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnKnockOutActionPerformed(evt);
            }
        });

        jButton1.setText("Set IP");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        btnBrowse.setText("Browse ");
        btnBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBrowseActionPerformed(evt);
            }
        });

        btnSendFile.setText("Send File");

        jButton2.setText("Set ");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jMenu1.setText("File");

        jMenuItem1.setText("Connect");
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Exit");
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        jMenu3.setText("Help");

        jMenuItem3.setText("About");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem3);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(107, 107, 107)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnConnect2Server)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnKnockOut, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btnBrowse)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnSendFile)
                                .addGap(29, 29, 29))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel1))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(38, 38, 38)
                                .addComponent(jButton2)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txtIPAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton1))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 80, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 523, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(txtSendMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 437, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(btnSend, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParalle
package ignisv10;

public class SetIP extends javax.swing.JFrame {

    /** Creates new form SetIP */
    public SetIP() {
        initComponents();
    }

    String ipAddress;
    String portNumber;
 

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtIPAddress = new javax.swing.JTextField();
        txtPortNumber = new javax.swing.JTextField();
        btnSet = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("IP Address:");

        jLabel2.setText("Port Number:");

        btnSet.setText("Set");
        btnSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSetActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(70, 70, 70)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(txtIPAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnSet)
                            .addComponent(txtPortNumber))))
                .addContainerGap(137, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(80, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtIPAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtPortNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(49, 49, 49)
                .addComponent(btnSet)
                .addGap(97, 97, 97))
        );

        pack();
    }// </editor-fold>

    private void btnSetActionPerformed(java.awt.event.ActionEvent evt) {
         theClient.setIPAddress(txtIPAddress.getText());
        
}

    

    // Variables declaration - do not modify
    private javax.swing.JButton btnSet;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField txtIPAddress;
    private javax.swing.JTextField txtPortNumber;
    // End of variables declaration


}

It seems like you've done what I suggested. Assuming Class 1 is named Client, and Class 1 has a method called sendData, then you should be fine. But if you want Class 3 to communicate with Class 1 (or Class 2) you will have to share the objects among those classes as well.

Yeah, class 1 have the method sendData(). How to share objects among classes?

Don't forget that class 2 have the instance theClient. I want to set the IP for the instance theClient for the program to work properly else it will not be able to communicate with the server.

Thanks a lot.

You can share Objects among classes through a constructor (or other method) of one class that accepts a parameter of the other class. See the example I already posted.

Can you please modify your example according to my code. I am a bit confuse with the example. Thanks.

I'm not going to write the code for you. You already did what I'm talking about once, with the theClient instance. Just do it again.

Hey, I am not telling you to write the code for me. WTF, I am just asking for help. Its not working thats why I asking you to write your example in the same context. Anyway, don't reply to this thread if you don't want to help.

You are just explaining with complicated words, I've already told you that I am new to Java.

If you don't know something, don't try to act smart, OK !! I am losing my time trying your stupid complicated examples.

You are just a dumb and thanks a lot for your complicated help ... hope someone else will help me and learn to be polite.

Comments
I think you just blew most of your chances for help here.
not cool

Hey, I am not telling you to write the code for me. WTF, I am just asking for help. Its not working thats why I asking you to write your example in the same context. Anyway, don't reply to this thread if you don't want to help.

You are just explaining with complicated words, I've already told you that I am new to Java.

If you don't know something, don't try to act smart, OK !! I am losing my time trying your stupid complicated examples.

You are just a dumb and thanks a lot for your complicated help ... hope someone else will help me and learn to be polite.

It sounded to me like you were asking me to write the code for you. If this wasn't the case, there is no need for you to get upset about it, just clarify what you meant. And obviously, I wanted to help because I responded to this thread. I already know how to do the task you're attempting, and have done the same thing in the past, so it isn't a question of me "not knowing it". And your personal attacks on me are very offensive and uncalled for.

Also, if you don't know what terms such as "parameter" etc mean, you could have asked for clarification or looked them up. If you aren't willing to put in effort to learn, then don't expect your code to work. And if you don't understand the simple terms I used, that is fine, but like I said - try to learn them - don't place blame on me for trying to help you.

"and will probably result in you not getting as much help here in the future." Are you threatening me or what?

I don't like this attitude from you, I am here to have some help and not to fight with you, OK. Please at least show a little respect.

I presume that you work for Dani Web. I do the same job for Tom's guide(in french) but on the "Troubleshooting section". I know how to talk to people on a forum and now you are threatening me. You think that you have the right to do that ?? You stood so low. One thing is sure, you don't know how to help people.


In your 490 posts you have solved only 48 thread which shows how "good" you are. Anyway, I got help from James earlier, check out his explanation, even a baby("I've told you that was new to Java" and "I've worked really hard on this program") will understand his example. Hope you will learn from him.

Note: I just wanted you to write your example in the same context as my program, that's all. I have not told to write the whole stuff for me. Btw, my code is working fine now, I've got the solution from another forum. I will continue to post my questions on Dani Web, there are other peoples over here which will surely help me.

Sincerely,
Bryan Jimmee Hugges

Any help offered here is a completely voluntary effort. As such, your own attitude is going to determine the extent and nature of that help. The attitude demonstrated above is certainly not going to encourage much assistance in the future.

Good luck with your efforts.

(You should also know that most posters never mark their questions as solved. Many don't even trouble themselves to say thanks or come back at all after their issue is resolved. Using that as a metric of "helpfulness" is useless.)

I'm glad you solved whatever issue you were having, and no, I do not work for Daniweb. I'm also not sure how you could interpret my attitude as arrogant or unpleasant, and I'm somewhat confused. But I'll leave this be.

This question has already been answered. Start a new discussion instead.