Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I access the variable within another class's method?

807600Jul 16 2007 — edited Nov 28 2007
Important bits of the Main class:
Genster mechz = new Genster();

//   ...

private class ClickListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == b_generate) {
                if (basic.isSelected() == true); {
                    Genster.BasicG();  // to execute what would be in that method
                    t_generate.setText(/*what to put here?*/);                    
                }
Genster class:
public class Genster {
    
    public static void BasicG() {
        String numbercool = "1337, it worked!";
        
        //return numbercool;
        
        // Without the void, NetBeans complains that I don't have a
        // return type, although I have it here, currently commented. Returning numbercool
       // would seem logical. :/
    }
    
}
So, I'm a bit stumped here. I want to set the text of a text box to what my BasicG method in Genster processes. Right now, it just assigns numbercool to something I specify. I've tried all sorts of things like mechz.numbercool and mechz.BasicG(numbercool) Help please! :D
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 26 2007
Added on Jul 16 2007
7 comments
261 views