Referencing another's Class CardLayout to add cards.

Hi, thanks for having a look at my question.
I had some working code where the Frame was created in the main. Trying out MVC pattern with simple password screen.
I used to create the CardLayout in the main and pass both the frame reference and the cardLayout reference (and a view) to another (controller)class where the view was added to the frame and the cardLayout. No complaints sofar.
I then decided to put the frame in it's own class. In this class the layout is also set to cardLayout.
In the main where I now (still) pass the reference for the frame reference I feel no need to pass the cardLayout reference.
I thought I should be able to refer to the cardLayout by knowing the frame reference.
However, the compiler does not appreciate my formulation. (As a newbie I tried a dozen 'combinations' already to no avail)
I would appreciate if you could help me out here. I have the offending code snippets below, the error at the bottom.
KR WimE
The Main:
import java.awt.*;
import java.awt.event.*;
public class Main {
    public static void main(String[] args) {
          Frame frame = new MVCFrame("Frame");
          MVCModelLogin     mvcModelLogin     = new MVCModelLogin();
          MVCView_Login     mvcView_Login     = new MVCView_Login(mvcModelLogin);
          MVCContrLogin     mvcContrLogin     = new MVCContrLogin(frame, mvcModelLogin, mvcView_Login);
          frame.setVisible(true);
          System.out.println("Main - ended");
    }     The Frame:
import java.awt.*;
import java.awt.event.*;
public class MVCFrame extends Frame {
     public CardLayout cardLayout = new CardLayout();
     public MVCFrame (String title) {
          super(title);
          this.setLayout(cardLayout);
          this.setBounds(64,100,1024,768);
     public void pushStackCardLayoutShow(MVCView_Login view,java.lang.String title) {
          this.add(view, title);
          cardLayout.addLayoutComponent(this, title);          
}The Controller:
import java.awt.*;
import java.awt.event.*;
public class MVCContrLogin {
     private Frame frame;
     private MVCModelLogin model;
     private MVCView_Login  view;
     public MVCContrLogin(Frame frame, MVCModelLogin model, MVCView_Login view)
          System.out.println("Constructor - Controller - Login");
          this.model     = model;
          this.view     = view;
          frame.pushStackCardLayoutShow(view, "mvcView_Login");
//     the offending line:
//   _MVCContrLogin.java:29: cannot find symbol : method pushStackCardLayoutShow(MVCView_Login,java.lang.String)_

You are referencing the MVCFrame as a Frame in MVCContrLogin. A Frame does not have the method pushStackCardLayoutShow. Change the reference type to MVCFrame.
Kaj

Similar Messages

  • Referencing between custom classes

    Hi,
    I need some help with the theory of referencing between custom class files.
    I have not worked much with custom classes before, but want to learn more.
    Is it possible to call for a function in one custom class file from another custom class file?
    The files are in the same package (folder).
    The first custom class is the one stat starts all the main activities on the movie clip when it is added to the stage.
    One of the activities it should start, is starting to add some movie clips to the stage.
    I would like to initiate that activity in the first custom class file, but have the detailed code (where, what and when to add) in another custom class file.
    Is that possible? When yes, how should it be referenced?
    Many thanks in advance!

    Hi,
    Thank you all for your replays.
    Got some new terminology – Singelton, Setters and Getters.
    Have not come across before:)
    I do know the inheritance and have used it. And my little experience with it told me as well – it’s something you shouldn’t go crazy or fanatic with. Overusing it makes things complicated.
    Amy, what you descibed is how I normally do use the classes – attach them to the Library symbols.
    In my question I meant one concrete Movie Clip which is one sub-part of the application.
    The Movie Clip is just an animated picture. That Movie Clip (girlSwim) is attached to the base class GirlSwim.
    And that class is at the moment handling the animation for that girl swimming. It would be good to have that code on a sub-level symbol, like the Girl, but as a mask is swimming along as well, it got too complicated for me to code, cross reference the nested symbols. So the code ended up on top level symbol.
    In that Movie Clip are other animating symbols as well and they are all handled with other custom classes.
    When the girlSwim Movie Clip is activated, it’s on screen, dragonflies start to fly in and fishes start to swim in as well. They are not on the original picture, so not on stage.
    And adding them is managed with timers and it continues as long as the Movie Clip is on screen.
    At the moment I have all the stuff related to dragonflies and fishes on the first keyframe.
    And it all functions nicely.
    But as I’m practicing now using class files and keeping my timeline action script free (except some stop and goto staff to handle the timeline animations), I want to get that part of the code into class file as well.
    I could but it all into the class GirlSwim and it would function.
    But as the animation code for the girl is long enough, I though it would be good to have the code for dragonflies and fishes separate.
    But it needs to be initiated by the GirlSwim class.
    So … in my little-simple world I thought the following could work .. but it didn’t:)
    1180: Call to a possibly undefined method timerStartDragonflies.
    package
    public class GirlSwim extends MovieClip
          public function GirlSwim()
               timerStartDragonflies ();
    package
    public class Dragonflies extends MovieClip
    public function Dragonflies ()
                                    //empty
                    internal function timerStartDragonflies():void
                                   //code for starting timer
                    etc.
    Is something like that possible or should I put it all into the GirlSwim class?

  • I HAVE AN OLD 3G IPHONE , HOW DO I USE IT IN ANOTHER COUNTRY WITH A NEW SIM CARD

    I  HAVE AN OLD 3G IPHONE , HOW DO I USE IT IN ANOTHER COUNTRY WITH A NEW SIM CARD ?

    it has to be unlocked by your carrier. give them a call

  • How to call a Java class from another java class ??

    Hi ..... can somebody plz tell me
    How to call a Java Class from another Java Class assuming both in the same Package??
    I want to call the entire Java Class  (not any specific method only........I want all the functionalities of that class)
    Please provide me some slotuions!!
    Waiting for some fast replies!!
    Regards
    Smita Mohanty

    Hi Smita,
    you just need to create an object of that class,thats it. Then you will be able to execute each and every method.
    e.g.
    you have developed A.java and B.java, both are in same package.
    in implementaion of B.java
    class B
                A obj = new A();
                 //to access A's methods
                 A.method();
                // to access A's variable
                //either
               A.variable= value.
               //or
               A.setvariable() or A.getvariable()

  • How to reference a Constants.as actionscript in another actionscript class

    Hi,
    How can I use constant variables from a Constatnst file (.as file) in another actionscript class?
    Thanks.

    What id I don't have the Constants.as not defined as a class.
    Constants.as
    public static const BASE_NAME = "ABC";
    public static const EQUIPMENT_NAME = "777";
    I can't import is file as its not a class file, right?
    So, how can I access BASE_NAME, etc.
    In a mxml file, I use the <mx:Script source="/../Constants.as"/>
    but how about in an actionscript class file.

  • Can an abstract class extend another abstract class?

    Is it possible for an abstract class to extend another abstract class?
    Say
    public abstract class AComponent extends JComponent {
    Thanks.

    Yes

  • Cannot add cards in the passbook

    hello guys,
    I have an IPhone 6 16Gb and I cannot find anything about Apple pay in my phone.
    When I go to the settings the option to active the Apple pay ( in the part where exist the icloud and Apple Store )
    when I access my passbook the only oprion that show is the scan the code ( nothing about add cards as you can see in the image).
    Anyone with this problem or know how to solve it?
    THank you.

    Yes, my iCloud is ok, my fringrpints are in use and the restrictions are turned off.
    i mi have no idea what is happen. For exemple, I cant see it in the general settings for exemple ( like in the picture).

  • Dynamic Calc referencing another Dynamic Calc

    Hi,
    I found a problem today in a Dynamic Calc member formula.
    Member A has in formula: B;
    Member B has in formula: C + D;
    Both members are Dynamic Calc and while member B shows the correct result, member A shows nothing in forms. If I switch the formula of member A to C + D; then it shows results.
    Is there any problem of Dynamic Calc members referencing another Dynamic Calc members?
    Thank you

    or change the position of member A/member B in the outline.^^^Exactly, Essbase is calculating the dimension top to bottom and if A needs B, it needs to be after B or as Andre stated, you need to stick a two-pass on A. I prefer not to use two-pass unless i need to as it can FUBAR my YTD and variance calcs. It's just easier to have it work in the "right" order.
    Regards,
    Cameron Lackpour

  • Add card reader to M82 Tower units

    We have 20 new m82 3202 tower units here and were told by Lenov we could add card readers (of any kind) to them.  However, once the boxes were opened, we realized that the front bezel doesn't look finished with a card reader installed, and the provided card reader bracket doesn't line up with the holes in our generic card readers.
    So far nobody at Lenovo has been able to tell us what the part # is for the finished bezel to make them look appropriate, or the part # of a compatible and correct card reader.
    Now, I think I can work around the mounting, but the finished looking front is a must, and these generic readers just don't fill the space or look correct at all.
    Update1:  Lenovo tech support just called back and says that these systems require the following parts:
    03T8160 card reader, 03t9736 card reader bezel.
    These parts don't seem to come up very often on google and mostly on NON US sites, so I'm afraid he's mistaken or these parts have cross #'s for other more available parts.  So, still stuck.
    Update2:  I can tell that one issue is that shorter or "not as deep" generic card reader units.  A longer generic card reader from rosewill that has 3 holes, 2 closer at the rear and 1 further at the front, on the side, works as far as depth goes, but there still must be a bezel of some kind that needs to go on there.  I hope that it's the bezel part # listed above, but since I can't get a picture of it, and have no idea if it's even available, I'm still stuck on that part.
    Update3:  Parts tells me they only have 6 of these " 03t9736 card reader bezel" available and the others will have to !!!manufactured!!! so there is no telling when they'll be available.  Furthermore they have no picture or any idea of what they are, so I wouldn't know if they were actually what I needed or not.  Lastly, they are $17/each plus outrageous shipping for a simple piece of plastic (presumably).  unbelievable.
    Thanks in advance if you can help.
    JC

    Lenovo tech support gave me mis-information on 2 complex problems. Double check everything, searching Lenovo websites, Google, and Bing.

  • Accesing components of global class in another global class.

    Hi,
    I am not able to access Public TYPES defined on a class in other class.
    Class cl_business_object : has public type tt_records type table of  <ztable> with default key.
    and when i use it in method of cl_gui , get_records returning rt_records type cl_business_object=>tt_records after making the statement of Class definition cl_business_object load / entering the name of the class in properties tab's .. why does it happen ?
    Regards.

    Hi, Its ECC 6.0,
    We did nto have this problem before, Its kind of new, have no idea why it behaves so ..
    And the syntax error is not generated when we are cheking onthe class where it has been used (acessing other class types) , this is activated.
    but another 3rd class where this activated class is used, throw up syntactical error showing error in class 2.
    " saying components of global class are not accesible, class definition missing"..
    but there are statements of class definition load already!!
    Regards
    Edited by: Trivvka on Aug 11, 2009 5:06 PM

  • Calling another java class from a java class

    Hi Friends,
    I have a class tht works in 2 modes,depending upon which mode i am passing (gui or text) on the command line eg:
    java myclass [mode]
    I want to call this command from another java class,and i wrote this code:
    try
             Process theProcess =
                Runtime.getRuntime().exec("java myclass  "+args[0]);
          catch(IOException e)
             System.err.println("Error on exec() method");
             e.printStackTrace();
          }When i pass "gui" it works fine,but when i pass"text", the class completes and nothing shows up on the command prompt window,so can please somebody tell me how to make this work.
    Thanks

    As aniseed just pointed out, you could do something like this:
    import javax.swing.*;
    class Test extends JFrame {
         public Test(String title) {
              this.setTitle(title);
              this.pack();
              this.setSize(300, 300);
              this.setLocationRelativeTo(null);
              this.setDefaultCloseOperation(EXIT_ON_CLOSE);
         public static void main(String[] argv) { new Test(argv[0]).setVisible(true); }
    public class Test2 {
         public static void main(String[] argv) {
              Test.main(argv);
    }Run it by executing this command:
    java Test2 "Title of Frame"See if that's not what you're looking for ...

  • Initialize/set a base class from a another base class instance

    Hi,
    How can I initialize/set a base class from a another base class instance? I do not want to do a copy of it.
    It would look something like:
    class A {...}
    class B extends A
        B(A a)
            // super = a;
        setA(A a)
            // super = a;
    }Thank you.

    erikku wrote:
    Thanks Winton. It is what I did first but A has lots of methods and if methods are later added to A, I will have to edit B again. For those two reasons, I wanted to use inheritance. The part I was not sure with was the way to initialize B's base (A).You pays your money and you takes your choice. One way (this way) you have to provide forwarders; the other way (inheritance) you have to provide constructors (and if A has a lot of em, you may be writing quite a few).
    Ask yourself this question: is every B also an A? No exceptions. Ever.
    If the answer is 'yes', then inheritance is probably the best way to go.
    However, if there is even the remotest chance that an instance of B should not exhibit 100% of the behaviour of A, now or in the future, then the wrapper style is probably what you want.
    Another great advantage of the wrapper style is that methods can be added to A without affecting the API for B (unless you want to).
    Winston
    PS: If your Class A has a constructor or constructors that take a pile of parameters, you might also want to look at the Builder pattern. However, that's not really what we're talking about here, and it should probably be implemented on A anyway.

  • Referencing WMI Manageable class from another WMI Class

    Hi,
    I am trying to have WMI manageable class referring to another WMI manageable class
    Something like
    [ManagementEntity]
    Class A
    [ManagementEntity]
    Class B
            [ManagementReference(Type = "A")]
            [ManagementProbe]
            public A AClass;
    When trying to install the class, I am getting “Type unsupported”
    I tried the Microsoft
    ManagementReference sample,
    http://msdn.microsoft.com/en-us/library/system.management.instrumentation.managementreferenceattribute.aspx
    (working fine but the LetterPhonetic class won’t show on the WMI Object Browser)
    Ideas will be highly appreciated
    My Sample code
    using System;
    using System.Management.Instrumentation;
    using System.Collections.Concurrent;
    using System.Collections;
    [assembly: WmiConfiguration("root\\ConsoleC", HostingModel = ManagementHostingModel.Decoupled)]
    namespace ConsoleDecoupled
        [System.ComponentModel.RunInstaller(true)]
        public class TheInstaller : DefaultManagementInstaller
        public class Program
            public static void Main(string[] args)
                for (int i = 0; i < 10; ++i)
                    TestEnumWmi ms = TestEnumWmi.CreateTestEnumWmi();
                    ms.teststring = i.ToString();
                InstrumentationManager.RegisterType(typeof(TestEnumWmi));
                InstrumentationManager.RegisterType(typeof(RuntimeConfigSettings));
                Console.WriteLine("Press enter to exit");
                Console.ReadLine();
                InstrumentationManager.UnregisterType(typeof(TestEnumWmi));
                InstrumentationManager.UnregisterType(typeof(RuntimeConfigSettings));
        [ManagementEntity(Singleton = true, Name = "ConfigurationSample")]
        [ManagementQualifier("Description", Value = "Configuration Sample Application")]
        public class RuntimeConfigSettings
            [ManagementProbe]
            public string[] ReadMe;
            private int myVar;
            [ManagementConfiguration]
            public int MyProperty
                get { return myVar; }
                set { myVar = value; Console.WriteLine(value); }
            [ManagementReference(Type = "TestEnumWmi")]
            [ManagementProbe]
            public TestEnumWmi MSS;
            [ManagementBind]
            public RuntimeConfigSettings()
                ReadMe = new string[10];
                for (int i = 0; i < 10; ++i)
                    ReadMe[i] = "blah " + i;
        [ManagementEntity(Name = "TestEnumWmi")]
        public class TestEnumWmi
            private TestEnumWmi()
            static internal TestEnumWmi CreateTestEnumWmi()
                TestEnumWmi ms = new TestEnumWmi();
                ms._id = Guid.NewGuid().ToString();
                ms.teststring = "blah";
                ms.TestInt = new Random().NextDouble();
                instantlist.TryAdd(ms._id, ms);
                return ms;
            [ManagementConfiguration()]
            public double TestInt { get; set; }
            [ManagementConfiguration()]
            public string teststring { get; set; }
            [ManagementKey(Name = "ID")]
            public string _id;
            [ManagementBind]
            static public TestEnumWmi GetInstant([ManagementName("ID")] string ID)
                TestEnumWmi ms = null;
                if (instantlist.TryGetValue(ID, out ms))
                    return ms;
                else
                    throw new InstanceNotFoundException();
            [ManagementEnumerator]
            static public IEnumerable EnumerateTestEnumWmis()
                foreach (var i in instantlist)
                    yield return i.Value;
            static internal ConcurrentDictionary<string, TestEnumWmi> instantlist = new ConcurrentDictionary<string, TestEnumWmi>();

    Hi,
    The Microsoft ManagementReference sample you mentioned contains a bug:
    Instead of:
    inst.LetterNumber = "Letter = " + i;
    inst.PhoneticNumber = "Phonetic = " + i;
    The exact text (where spaces in the string are important and must be removed) should be:
    inst.LetterNumber = "NumberLetter.Number=" + i;
    inst.PhoneticNumber = "NumberPhonetic.Number=" + i;
    With this fix, the hierarchy can now be navigated properly.
    c.f. my response to the following blog post:
    http://juggledthoughts.blogspot.co.uk/2008/06/wmi-association-classes.html
    I have also
    logged a bug on MSDN Feedback so please vote on this if you'd like them to fix the sample.

  • Referencing another class with multiple types.

    Here's my code:
    import java.io.*;
    import java.util.Scanner;
    class CH3_13
        public static void main ( String args[] )
            Scanner input = new Scanner( System.in );
         // Invoice MyInvoice = new Invoice();
         /* myInvoice.displayInvoice();*/   }   
    class Invoice
    {   private String partNumber;
        private String partDescription;
        int quantity;
        double pricePerItem;
        public Invoice( String pNumber, String description, int qNumber, double price)
            partNumber = pNumber;
            partDescription = description;
            setQuantity( qNumber );
            setPricePerItem ( price );   }
          public void setPartNumber ( String pNumber )
          {   partNumber = pNumber;   }
          public String getPartNumber ()
          {   return partNumber;   }
          public void setPartDescription ( String description )
          {   partDescription = description;   }
          public String getPartDescription ()
          {   return partDescription;   }
          public void setQuantity ( int qNumber )
          {   quantity = ( qNumber < 0 ) ? 0 : qNumber;   }
          public int getQuantity ()
          {   return quantity;   }
          public void setPricePerItem ( double price )
          {   pricePerItem = ( price < 0.0) ? 0.0 : price;   }
          public double getPricePerItem ()
          {   return pricePerItem;   }
          public double getInvoiceAmount()
          {   return getQuantity() * getPricePerItem();   }
           public void displayInvoice ()
          {   System.out.println("The part number is" + getPartNumber() );
              System.out.println("The part description is" + getPartDescription() );
              System.out.println("The quantity number is" + getQuantity() );
              System.out.println("The price per item is" + getPricePerItem() );
              System.out.println("The invoice amount is" + getInvoiceAmount() );   }          
    }The problem is.. I cannot use the line:
    // Invoice MyInvoice = new Invoice(); (it's commented out for that reason)
    ... because it seems I cannot reference it because the Invoice class has multiple types defined in it. As this is the case, is there anyway, I'd be able to get that line to compile?

    I am not sure of this is what you are looking for but I would definitely suggest some real refactoring here. First of all the part no. name description donot belong to the invoice class so they need to go into a different class named part no. Secondly you need to identify the relationship which I would say would be has a relationship between invoice and part. A many to many relationship. SInce its many to many I would guess it would need to be biderectional associaition.
    However if we have a defined no. of parts in the inventory I would suggest using the reference objects, by predefining them and loading them into memory to ensure that if every time an invoice has a part, a new part object is not created.

  • How to refresh a JTable of a class from another thread class?

    there is an application, in server side ,there are four classes, one is a class called face class that create an JInternalFrame and on it screen a JTable, another is a class the a thread ,which accept socket from client, when it accept the client socket, it deal the data and insert into db,then notify the face class to refresh the JTable,but in the thread class I used JTable's revalidate() and updateUI() method, the JTable does not refresh ,how should i do, pls give me help ,thank you very much
    1,first file is a class that create a JInternalFrame,and on it there is a table
    public class OutFace{
    public JInternalFrame createOutFace(){
    JInternalFrame jf = new JInternalFram();
    TableModel tm = new MyTableModel();
    JTable jt = new JTable(tm);
    JScrollPane jsp = new JScrollPane();
    jsp.add(jt);
    jf.getContentPane().add(jsp);
    return jf;
    2,the second file is the main face ,there is a button,when press the button,screen the JInternalFrame. there is also a thread is beggining started .
    public class MainFace extends JFrame implements ActionListener,Runnable{
    JButton jb = new JButton("create JInternalFrame");
    jb.addActionListener(this);
    JFrame fram = new JFrame();
    public void performance(ActionEvent e){
    JInternalFrame jif = new OutFace().createOutFace(); frame.getContentPane().add(JInternalFrame,BorderLayout.CENTER);
    public static void main(String[] args){
    frame.getContentPane().add(jb,BorderLayout.NORTH);
    frame.pack();
    frame.setVisible(true);
    ServerSokct ss = new ServerSocket(10000);
    Socket skt = ss.accept()'
    new ServerThread(skt).start();
    3.the third file is a thread class, there is a serversoket ,and accept the client side data,and want to refresh the JTable of the JInternalFrame
    public class ServerThread extends Thread{
    private skt;
    public ServerThread(Sokcet skt){
    this.skt = skt;
    public void run(){
    OutputObjectStream oos = null;
    InputObjectStream ios = null;
    try{
    Boolean flag = flag;
    //here i want to refresh the JTable,how to write??
    catch(){}
    4.second is the TableModel
    public class MyTableModel{
    public TableModel createTableModel(){
    String[][] data = getData();
    TableModel tm = AbstractTableModel(
    return tm;
    public String[][] getData(){
    }

    Use the "code" formatting tags when posting code.
    Read this article on [url http://www.physci.org/codes/sscce.jsp]Creating a Simple Demo Program before posting any more code.
    Here is an example that updates a table from another thread:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=435487

Maybe you are looking for