Results 1 to 3 of 3
  1. #1
    ops2048 is offline Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Question problem, calling a method

    Apologies for the amount of code in this question as I am not too sure as to what may or may not be relevant. I have included two (edited) classes, FleetOps, the main application class and CreateNewPlayer, which is called by the FleetView class, not included, which provides the applications gui.

    My problem lies in line 35 of the CreateNewPlayer class "if (!fleetOpsSession.checkforduplicateplayer(getUsern ame(), getPassword())) {".

    Eclipse insists that "fleetOpsSession cannot be resolved" yet I distinctly believe that I have instantiated an instance of FleetOps in the static main method. I feel that this indicates that I have some simple fundamental misconception. Can anybody point out where I am going wrong?

    Java Code:
    package FleetOpsControl;
    
    import java.util.*;
    
    import javax.swing.*;
    import javax.swing.UIManager.*;
    import javax.swing.SwingUtilities;
    
    import FleetOpsModel.*;
    import FleetOpsView.*;
    
    public class FleetOps {
        
        protected String    playerName,
                                  passWord,
        
        protected Player    player;
        protected Game     game;
        
        protected List<Player>    players;
        protected List<Game>     games;
    
        protected Boolean duplicate;
        
        public FleetOps()    {
            
            players = new ArrayList<Player>();
            games = new ArrayList<Game>();
        }
        
        public boolean checkforduplicateplayer(String username, String password) {
            
            return duplicate;
        }
    
        public static void main(String[] args)    {
            
            FleetOps fleetOpsSession = new FleetOps();
            FleetView fleetOpsViewSession = new FleetView();
        }
    }
    Java Code:
    package FleetOpsView;
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    
    import FleetOpsControl.*;
    import FleetOpsModel.*;
    
    public class CreateNewPlayer    {
        
        JFrame frame;
        
        public CreateNewPlayer()    {
            
            frame = new JFrame();
            CreatePlayerDialog createPlayer = new CreatePlayerDialog(frame);
            createPlayer.setVisible(true);
        }
            
        public class CreatePlayerDialog extends JDialog {
             
            private JButton btnCreate;
         
            public CreatePlayerDialog(Frame parent) {
                super(parent, "Create new player", true);
                
                btnCreate = new JButton("Create");
         
                btnCreate.addActionListener(new ActionListener() {
         
                    public void actionPerformed(ActionEvent e) {
                        
                        if (!fleetOpsSession.checkforduplicateplayer(getUsername(), getPassword())) {
    
                        } else {
    
                        }
                    }
                });
    
                JPanel bp = new JPanel();
                bp.add(btnCreate);
    
                getContentPane().add(bp, BorderLayout.PAGE_END);
         
                pack();
                setResizable(false);
                setLocationRelativeTo(parent);
            }
         
            public String getUsername() {
                 return "";
            }
         
            public String getPassword() {
                 return "";
            }
        }
    }

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: problem, calling a method

    fleetOpsSession is only locally known in FleetOps.main . If you need the instance in other classes, you have to pass it to them.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

Similar Threads

  1. FileWriter/Method Calling Problem
    By javaNewblet in forum New To Java
    Replies: 8
    Last Post: 11-11-2011, 07:35 AM
  2. Calling method problem
    By jmoutia in forum New To Java
    Replies: 7
    Last Post: 10-24-2010, 10:06 AM
  3. Thread problem, calling method in run method
    By majk in forum Threads and Synchronization
    Replies: 4
    Last Post: 09-27-2010, 12:40 PM
  4. Problem calling a method
    By ToeJam in forum New To Java
    Replies: 5
    Last Post: 12-12-2009, 02:45 AM
  5. Replies: 29
    Last Post: 09-25-2008, 08:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •