voh's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
9 (0.01 per day)
Joined:
18-February 13
Profile Views:
559
Last Active:
User is offline Apr 19 2013 08:45 AM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Linux
Favorite Browser:
Mozilla
Favorite Processor:
AMD
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0
Icon   voh has not set their status

Posts I've Made

  1. In Topic: (x,y) coordinates using 2D array and for loop

    Posted 17 Mar 2013

    Thank you so much :D
  2. In Topic: ActionListener button actionPerformed method

    Posted 23 Feb 2013

    Guys just to update where I have gotten so far and the original problem I was ultimately trying to solve ....

    I have a few classes, but 2 that I shall refer to here

    one called:

    public class GameBoard 
    
    


    another:

    public class FrameActionListener implements ActionListener
    
    


    the purpose of the latter is to "send commands to controller" while the former :
    public class GameBoard "sets the environment of the board":

    the public method below takes an array of 9 and sest the tiles on a 3*3 puzzle board:

    public GameBoard(int[] state) {
            this.state = new int[state.length];
            System.arraycopy(state, 0, this.state, 0, state.length);
    
        }
    
    
    


    while in the FrameActionListener class, an if statement then checks the button pressed/ Object source is = the "initialState" button ... if so the "board" referencing the "public GameBoard" board is assigned accordingly:

    public class FrameActionListener implements ActionListener {
            public void actionPerformed(ActionEvent voh) {
                try {
                	
                    
                        Object vource = voh.getSource();
                        
                          if (vource == initialState) {
                        	  
                        	  int[] variable2 = new int[9];
                          	String input = JOptionPane.showInputDialog("Tiles?", "0 "+ "8 " +"7 " +"6 " +"5 "+ "4 " +"3 " +"2 " +"1");
                          	
                          	String[] inputs = input.split(" ");
                            	for (int j = 0; j< 9; j++) 
                            	{   
                					variable2[j] = 
                            	            Integer.parseInt(inputs[j]);
                					
                		/*error here->*/	board = new EightPuzzleBoard( variable2 ); 
                            	}
    
                          } }
    
    


    note:
    > public class FrameActionListener is within another class called PuzzleFrame which extends JFrame
    > public class GameBoard is imported in class PuzzleFrame


    Thanks
  3. In Topic: ActionListener button actionPerformed method

    Posted 22 Feb 2013

    Thanks guys I now get it. I solves it....

    but I (wrongly) presumed that my post could solve my real problem I thought they would work the same way for...

    
    int[] variable = new int[9];
                	 
                	public void actionPerformed(ActionEvent e) {
                		
                    	String input = JOptionPane.showInputDialog("Tiles?", "0 "+ "8 " +"7 " +"6 " +"5 "+ "4 " +"3 " +"2 " +"1");
                    	String[] inputs = input.split(" ");
                      	for (int j = 0; j< 9 ; j++) 
                      	{   
          					variable[j] = 
                      	            Integer.parseInt(inputs[j]);
          					//System.out.println(variable);
                      	}
                     
                	}            	
                });
                toolbar.add(initialState);
               System.out.println(variable);
    
    


    where variable outside the method in

    System.out.println(variable);
    
    


    will be recognised.. is there a way?

    Thanks again
  4. In Topic: ActionListener button actionPerformed method

    Posted 22 Feb 2013

    Mr pbl:

    when I do that :

    int variable=1;
                System.out.println(variable);
                initialState = new JButton("Initial state");
                initialState.setToolTipText("Initial state");
               // initialState.addActionListener(actionListener);
                initialState.addActionListener(new ActionListener(){
                	
                	public void actionPerformed(ActionEvent e) {
                		JOptionPane.showMessageDialog(null, "ActionListener is working-- VOH");
                		variable = 100;
                	}            	
                });
                toolbar.add(initialState);
    
    


    it doesn't compile with error and my IDE (eclipse) telling me to "change modifier to final

    so it (variable) becomes:
    final int variable=1;

    which still doesn't compile with error "The final local variable variable cannot be assigned, since it is defined in an enclosing type"

    Thanks
  5. In Topic: ActionListener button actionPerformed method

    Posted 22 Feb 2013

    Ok Ryano:

    int variable=1;
                System.out.println(variable);
                initialState = new JButton("Initial state");
                initialState.setToolTipText("Initial state");
               // initialState.addActionListener(actionListener);
                initialState.addActionListener(new ActionListener(){
                	
                	public void actionPerformed(ActionEvent e) {
                		JOptionPane.showMessageDialog(null, "ActionListener is working-- VOH");
                		int variable = 100;
                	}            	
                });
                toolbar.add(initialState);
    
    
    


    but my problem was/is what when I click the initialState button (I wanted the variable becomes 100 instead of 1) although right now it just doesnt "make variable value = 100" it remains 1.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

Comments

voh has no profile comments yet. Why not say hello?