Hello DaniwWeb Members :)

I'm a fairly new programmer and I'm kinda embarressed to ask this question considering that the answer is probably blatently obvious.

So forgive my ignorance :)

But here goes,

I have a String called "Ctype", It is relevant to my combobox which I created. My combobox works perfectly fine, and I can get it to work without using a "JButton" but I would like to use one.

If I selected one of my options in the Combobox, it will instantly follow the instruction instead of waiting until I pressed "Next".

I changed the code around abit and tried to get it to work, but unfortunatly I am unable to use the String I defined in the private "Ctype" combobox class in the button's private class.

Is there anyway I can use the String from one private class in another?
Or is there a way to refactor Netbean's generated code to change it from it's default "private void ....." to a public one? :)

Here is the code <3 :)

    private void transportNextActionPerformed(java.awt.event.ActionEvent evt) {

        JComboBox CargoType = (JComboBox) evt.getSource();
        String Ctype = (String) CargoType.getSelectedItem();


    }

    private void priceNextActionPerformed(java.awt.event.ActionEvent evt) {


        if (Ctype.contentEquals(Kids)) {
            Prices.setVisible(false);
            HowManyChildren.setVisible(true);
            HowFar.setVisible(false);
            Transport.setVisible(false);
        } else {
            Prices.setVisible(false);
            HowManyChildren.setVisible(false);
            HowFar.setVisible(false);
            Transport.setVisible(false);
        }

    }

As you can see, I can't use the String :/

Btw,

I defined "Kids" at the top of the code

String 
       Kids = "Children",
      Items = "Goods";

String TypeC;

Please help me,
Will Greatly Be Appreciated.

Brian

if you want to get to get a value from an Object, from one class to another, use getters.

Be careful with your terminology. Those are two private methods, not classes. You didn't post all the code, but my guess is that they're both in the same class. That means they can share any variables that are defined in the class but outside any one method. Move the declaration of String cType outside that one method, and all the methods will be able to use it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.