2 Replies Latest reply on Apr 10, 2012 7:47 AM by 927536

    How to use a variable between interfaces or class?

      Hello All;

      Far by now I can say that the forum is very helpful for me. Thanks for all the people who have the time and generosity to help our problems. Thank you.

      Unfortunately I have a problem <Again :( >

      I want to use a variable in two different *.java files.

      Is it possible?

      The Variable i want to use is; int CiftSayisi

      The variable is declared in the CamCalib.Java under a button's Action Listener.

      Here is the code;
      public void actionPerformed(ActionEvent arg0) {
                          String[] ImPath = list.getItems();                                           //Storing Items in an Array
                          Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();                     //Dimensions of the Screen Storing in an object
                          int ScreenHeight = dim.height;                                           //Definition ScreenHeight
                          int ScreenWidth = dim.width;                                          //Definition ScreenWidth
                          // System.out.println(ScreenHeight);                                                    //Testing of the Dimensions
                          // System.out.println(ScreenWidth);                                                     //Testing of the Dimensions
                          int CiftSayisi = ImPath.length -1 ;
                          if (CiftSayisi == 0){
                               System.out.println("Added Images do not Construct a Pair");
                          else {
      Now i want to use it in another java file which is ImagePair.Java in the loading part of the interface;
                setTitle("Image Pair Selection");
                setBounds(100, 100, 450, 68);
                contentPane = new JPanel();
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                textField = new JTextField();
                textField.setBounds(61, 11, 22, 20);
      I have a text field in here that i need to fill with the value of CiftSayisi

      Any help please?

      ömer kaya

      Edited by: Ömer K. on Apr 10, 2012 12:43 AM
        • 1. Re: How to use a variable between interfaces or class?
          I didn't bother reading the code, since you didn't format it.

          But to answer your question (if I understand it correctly), yes, it is possible to pass variables between different object instances (not from an interface specifically, since interfaces don't have members). The simplest way to pass the variable as an argument to a method or constructor. If these aren't available, you could create a static global variable, though in a multithreaded app you'd have to synchronize access.
          1 person found this helpful
          • 2. Re: How to use a variable between interfaces or class?

            Thanks for the answers;

            Sorry for the code format; i didn't know it, now i know (sorry new to everything here; :| )

            I couldn't understand what you mean by argument to a method? i searched the web but couldn't find any answers regarding that.

            Could you show some code for me?

            I mean not related to my specific problem but how can it be done?

            any web link is helpful too.

            ömer kaya