By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,237 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,237 IT Pros & Developers. It's quick & easy.

Variable value not being stored

P: 2
Hello,

I am a newbie at programming and have a question. The variable fnh is not being stored in the fullFNH in the second file, only in fnh in the first file. Can someone suggest me what I could be doing wrong? Thanks in advance.


// AlladinLamp.java

Expand|Select|Wrap|Line Numbers
  1. import statements go here
  2.  
  3. public class AlladinLamp  {
  4.  
  5.    int fnh;
  6.    JComboBox runners;
  7.    other variables go here
  8.  
  9.    actionListener and other methods go here, including
  10.  
  11.    public int getFNH()  { return fnh; }
  12.  
  13.    ActionListener runnersActionListener = new ActionListener()  {
  14.           @Override
  15.           public void actionPerformed( ActionEvent e ) {
  16.              String  runnersNumber = ( String )runners.getSelectedItem();
  17.              fnh = Integer.parseInt( runnersNumber );          
  18.              hNam = new String[ fnh ];
  19.              hNum = new int[ fnh ];
  20.              hVal = new int[ fnh ];
  21.              jtxt = new JTextField[ fnh ];
  22.              reducedFNH = reduce( fnh );                
  23.            }
  24.    };
  25.  
  26.  
  27.  
  28.    public AlladinLamp()  {
  29.  
  30.       gui built here...
  31.  
  32.       String[] numberOfRunners = { "8", "9", "10", "11", "12",
  33.                                 "13", "14", "15", "16", "17",
  34.                                 "18", "19", "20", "21", "22" };
  35.  
  36.       runners = new JComboBox( numberOfRunners );
  37.       runners.setMaximumRowCount(5); 
  38.  
  39.  
  40.       runners.addActionListener( runnersActionListener );
  41.  
  42.       ...
  43. }
  44.  
  45. public static void main( String args[] )  {
  46.  
  47.    SwingUtilities.invokeLater( new Runnable()  {
  48.             @Override
  49.             public void run()  {
  50.                 AlladinLamp lamp = new AlladinLamp();                 
  51.             }
  52.         });
  53.  
  54. }
  55.  
  56.  
  57. // Process.java
  58.  
  59. import statements go here
  60.  
  61. public class Processes  {
  62.  
  63. int fullNH;
  64. AlladinLamp lamp;
  65.  
  66. public Process()  {
  67.  
  68.   lamp = new AlladinLamp();
  69.   fullNH = lamp.getFNH();
  70.  
  71.   ...
  72.  
  73. }
Mar 28 '13 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
Post the actual code that you used. What you posted doesn't even compile.
Mar 28 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.