Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2012
    Rep Power

    Default Creating an instance variable in one class that connects to another instance variable


    What I'm trying to do is creating an instance variable in one class that connects to another instance variable.
    I'm gonna create an instance variable of the class Model in the class View. That instance variable of Model is gonna connect with instance variable of another class called TegnePanel which is also in class View.

    Here is my how I tried to do it but I get errors on cp.add(model, BorderLayout.CENTER); and tegnepanel.addModel(new model());

    I can't figure out what I did wrong, did I forget something?

    JPanel jpInner = new JPanel();

    Java Code:
    public class View extends JFrame {
    	 JMenu file = new JMenu("File");
    	 JMenu format = new JMenu("Format");
    	 JMenu setup = new JMenu("Setup");
    	    JMenuBar menuBar = new JMenuBar();
            setSize(300, 300);
            setLocation(200, 200);
    	GridLayout gl = new GridLayout(0,2);
    	JPanel jpInner = new JPanel();
    	String TegnePanel;
    	String Model;
    	public View(){
    		Container cp = this.getContentPane();
    		TegnePanel tegnepanel = new TegnePanel();
    		Model model = new Model ();
    	    cp.add(tegnepanel, BorderLayout.CENTER);
    	    cp.add(model, BorderLayout.CENTER);
    	    tegnepanel.addModel(new model());
    		this.setLocation(100, 100);
    	public static void main(String[] args) {
    		View v = new View();

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: Creating an instance variable in one class that connects to another instance vari

    I'm not sure that you've given us enough information to allow us to be able to help you. For instance, when mentioning errors, you should show actual error messages. And when describing and showing code, assume that we have no idea what the rest of your program looks like. Also on a minor note, your class naming is a little confusing since many of us equate "model" with non-GUI logic portion of the program, one that wouldn't get added as a component to the view. Also, what exactly do you mean by having one variable "connect to" another variable. Please provide more information and code, and please provide much more detail in your description.

Similar Threads

  1. Replies: 3
    Last Post: 12-16-2013, 05:35 PM
  2. Updating the Instance Variable of a Class
    By Leo11221 in forum New To Java
    Replies: 19
    Last Post: 12-01-2011, 05:07 PM
  3. Replies: 20
    Last Post: 06-03-2009, 05:33 PM
  4. create new instance of variable class
    By Fedor in forum New To Java
    Replies: 5
    Last Post: 04-12-2009, 08:13 PM
  5. Naming a class instance with a variable
    By pikalex88 in forum New To Java
    Replies: 3
    Last Post: 09-30-2008, 06:27 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