Results 1 to 5 of 5
Thread: Static key word issues.
- 01-04-2010, 01:59 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 32
- Rep Power
- 0
Static key word issues.
Static doesn't prevent an array from changing does it?
I'm trying to pass info from my GUI class to my Logic class using a method in my GUI:
the keyword static is required so I can use it from different classes is that right?Java Code:public static String[][] getStringArray(){ String[][] output = new String[9][9] //use a loop to assign values from GUI (Grid[][].getText() to output[][]) return output; }
The values don't seem to be changing though. My GUI consists of a Grid[9][9] of buttons, the buttons are a special extended from JButton button that has a special action mechanism:
it shows a pop up menu of values for you to choose from when you click a button.Java Code:public class SudokuButton extends JButton { SudokuButton(){ addActionListener(new PopupListener()); } class PopupListener implements ActionListener{ JPopupMenu popup = new JPopupMenu(); PopupListener(){ popup.add(new JMenuItem(new ButtonAction(" "))); for (int a = 0; a < 9; a++){ popup.add(new JMenuItem(new ButtonAction(String.valueOf(a+1)))); } } public void actionPerformed(ActionEvent e) { popup.show(getRootPane(),getX() + 45,getY() + 45); } } private class ButtonAction extends AbstractAction{ private String text; public ButtonAction(String text){ super(text); this.text = text; } public void actionPerformed(ActionEvent e){ setText(text); } } }
When I do so, the Grid[][].getText() should also change when I call it right? My method keeps returning the original Grid[][] instead of a new one based on user input. I had some help with this so I'm not to sure on the details. I think setText should've covered it, but I dunno, I think it's not understanding 'static' that's messing me up.
- 01-04-2010, 02:28 AM #2
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
i think i misinterpreted your question .but can you tell me where does the static method lie is it in a different class?
- 01-04-2010, 02:57 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
First of all, to access/calling from different classes you no need to use static. I think you are confusing with the word static. Here is a simple definition from one of my handout.
Is that clear to you?Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), abstract class may contain static data. Any class with an abstract method is automatically abstract itself, and must be declared as such.
A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.
- 01-04-2010, 04:46 AM #4
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
this website can help you clarify the word static if you need help.
Static
- 01-06-2010, 12:28 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Still there is no comment from OP.
Similar Threads
-
Static is a pain in the ass word!
By Addez in forum New To JavaReplies: 4Last Post: 08-18-2009, 01:23 AM -
Non-Static method in static context error
By wizmang in forum New To JavaReplies: 4Last Post: 04-24-2008, 08:51 AM -
Explicit static initialization with the static clause
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 11:07 PM -
Error: Non-static method append(char) cannot be referenced from a static context
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:05 AM -
Error: non-static variable height cannot be referenced from a static context at line
By fernando in forum AWT / SwingReplies: 1Last Post: 08-01-2007, 09:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks