Creating new instances of objects from external classes

Hello!
I have a number of classes, in particular a 'room' class and a 'player' class. I've just made them as simple classes with a couple of fields and a few accessor and mutator methods.
I have a 'start' class, and at the moment it has the heading:
public class start extends room {  This is working fine, as I have been able to create an array of rooms and use the room object's roomName method for each room to name it. But now I also want to create a new player:
player player1 = new player;But I don't know how to do that. I'm fairly new to Java and have been working from web tutorials and textbooks, but am still not quite used to the very 'universal' format of the code (i.e it just uses generic terms instead of actual examples of real-life situations).
If someone can help me with a simple way of having both the room and player class available for new object creation I'd be most grateful. My compiler cannot seem to create the new player as there is no direct link to that class.
Cheers.
Hussein.
"Simplicity is appreciated."

You keep posting these basic questions and asking for simple answers. Well, learning Java is not a simple task. You need to start at the beginning of a long road and take many steps, one at a time. May I suggest one or more of the following:
Sun's basic Java tutorial
Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
Bruce Eckel's Thinking in Java (Available online.)
Joshua Bloch's Effective Java
Bert Bates and Kathy Sierra's Head First Java.
James Gosling's The Java Programming Language. Gosling is
the creator of Java. It doesn't get much more authoratative than this.

Similar Messages

  • Creating an arrays of objects from a class

    I was wondering does any one know how to create an array of objects from a class?
    I am trying to create an array of objects of a class.
    class name ---> Class objectArray[100] = new Class;
    I cant seem to make a single class but i need to figure out how to create an array of objects.
    I can make a normal class with Class object = new Class

    There are four lines of code in your for-loop that actually do something:
    for(index = 0; index < rooms.length; index++) {
    /*1*/  assignWidth.setWidth(Double.parseDouble(in.readLine()));
    /*2*/  rooms[index] = assignWidth;
    /*3*/  assignLength.setWidth(Double.parseDouble(in.readLine());
    /*4*/  rooms[index] = assignLength;
    }1.) Sets the width of an object, that has been instantiated outside the loop.
    2.) assigns that object to the current position in the array
    3.) Sets the width of a second object that has been instantiated outside the loop
    4.) assigns that other object to the current position in the array
    btw.: I bet you meant "assignLength.setLength(Double.parseDouble(in.readLine());" in line 3 ;)
    Since each position in an array can only hold one value, the first assignment (line 2) is overwritten by the second assignment (line 4)
    When I said "construct a new room-object and assign it to rooms[index]" I meant something like this:
    for(index = 0; index < rooms.length; index++) {
        Room aNewRoom = new Room();
        aNewRoom.setWidth(Double.parseDouble(in.readLine()));
        aNewRoom.setLength(Double.parseDouble(in.readLine());
        rooms[index] = aNewRoom;
    }1.) Constructs a new Object in every iteration of the for-loop. (btw: I don't know what kind of objects you're using, so this needs most likely modification!!)
    2.) set the width of the newly created object
    3.) set the length of the newly created object
    4.) assign the newly created object to the current position in the array
    -T-
    btw. this would do the same:
    for(index = 0; index < rooms.length; index++) {
        rooms[index] = new Room();
        rooms[index].setWidth(Double.parseDouble(in.readLine()));
        rooms[index].setLength(Double.parseDouble(in.readLine());
    }but be sure you understand it. Your teacher most likely wants you to explain it ;)

  • Why can't I create new object from a class that is in my big class?

    I mean:
    class A
    B x = new B;
    class B
    and how can I solve it if I still want to create an object from B class.
    Thank you very much :)

    public class ItWorksNow  {
      public ItWorksNow() {
      public static void main ( String[] argv )  throws Exception {
        ItWorksNow.DaInnaClass id = new ItWorksNow().new DaInnaClass();
      public class DaInnaClass {
    }

  • Accessing the same object from multiple classes.

    For the life of me I can't workout how I can access things from classes that haven't created them.
    I don't want to have to use "new" multiple times in seperate classes as that would erase manipulated values.
    I want to be able to access and manipulate an array of objects from multiple classes without resetting the array object values. How do I create a new object then be able to use it from all classes rather than re-creating it?
    Also I need my GUI to recognize the changes my buttons are making to data and reload itself so they show up.
    All help is good help!
    regards,
    Luke Grainger

    As long as you have a headquarters it shouldn't be to painfull. You simply keep a refrence to your ShipDataBase and Arsenal and all your irrellevant stuff in Headquarters. So the start of your Headquarters class would look something like:
    public class Headquarters{
      public Arsenal arsenal;
      public ShipDatabase db;
    //constructor
      public Headquarters(){
        arsenal = new Arsenal(this, ....);
        db = new ShipDatabase(...);
    //The Arsenal class:
    public class Arsenal{
      public Headquarter hq;
      public Arsenal(Headquarter hq, ....){
        this.hq = hq;
        .Then in your ShipDatabase you should, as good programing goes, keep the arraylist as a private class variable, and then make simple public methods to access it. Methods like getShipList(), addToShipList(Ship ship)....
    So when you want to add a ship from arsenal you write:
    hq.db.addToShipList(ship);
    .Or you could of course use a more direct refrence:
    ShipDatabase db = hq.db;
    or even
    ShipList = hq.db.getShipList();
    but this requires that the shiplist in the DB is kept public....
    Hope it was comprehensive enough, and that I answered what you where wondering.
    Sjur
    PS: Initialise the array is what you do right here:
    //constructor
    shipList = new Ship[6];
    shipList[0] = new Ship("Sentry", 15, 10, "Scout");
    " " " "etc
    shipList[5] = new Ship("Sentry", 15, 10, "Scout");PPS: To make code snippets etc. more readable please read this article:
    http://forum.java.sun.com/faq.jsp#messageformat

  • Can't create mcafee plug-in object: TypeError: Components.classes[cid] is undefined

    I updated to Firefox 4.0 and ever since then, I get this message when I try to open Firefox:
    can't create mcafee plug-in object: TypeError: Components.classes[cid] is undefined
    I have a Mac and have McAfee protection for Mac. This problem did not happen before I updated Firefox. Once I click on "OK" Firefox opens.

    This issue is most likely caused by a McAfee extension that isn't working properly and you will have to disable the extension that causes it.
    You can also check if there is an update available from McAfee that fixes this problem.

  • How to repaint an array of JCheckbox witou creating new instance?

    Can you help me on how I will repaint the array of check box, without creating new instance. When I pressed the refresh Button It will repaint the check box. Anybody who can help me..
    Here's my code. The Comment is the one I need to put the action.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class subok extends javax.swing.JFrame {
        JCheckBox c[] = new JCheckBox[10];
        public subok() {
            initComponents();
            setSize(300,500);
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            check();
            refresh = new javax.swing.JButton();
            getContentPane().setLayout(null);
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jPanel1.setLayout(null);
            refresh.setText("Refresh");
            refresh.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    repaintCheckbox(evt);
            jPanel1.add(refresh);
            refresh.setBounds(160, 260, 160, 23);
            getContentPane().add(jPanel1);
            jPanel1.setBounds(0, 0, 400, 300);
            pack();
        }// </editor-fold>                       
        private void repaintCheckbox(java.awt.event.ActionEvent evt) {                              
                // what will I put here???????
                // ANy Help will do....
                // I just want to refresh the checkbox when I pressed this button..
        public void check() {
            boolean s = false;
            int x = 10;
            for(int i = 0; i < 10; i++) {
                c[i] = new JCheckBox();
                c.setText("");
    c[i].setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    c[i].setMargin(new java.awt.Insets(0, 0, 0, 0));
    jPanel1.add(c[i]);
    c[i].setBounds(20, x, 73, 15);
    x += 30;
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new subok().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton refresh;
    // End of variables declaration

    what do you mean by repaint the checkboxes?
    do you mean setting them all to 'unchecked'?
    if so, just loop through your checkbox array c[x].setSelected(false);

  • ORA - 01034 : ORACLE NOT AVAILABLE  Error while creating new instance.

    I was trying to create new instance in unix environment. I have configured all my shell scripts to run and install but while performing the install I get the
    following error message and fails.
    ORA-01034: ORACLE not available
    I have previously installed an instance using same scripts but fails this time when I copy the scripts and modify them in new folder. Pointed out the path in the scripts correctly.
    I am a junior DBA and I would appriciate your help.

    Paste here scripts, your .profile (or environment variables according to Oracle) and your init.ora

  • How & where to use Java script to create new button in object detail page

    Hi All,
    I want to create "New/Add button" in object detail page. If i am not wrong i need to use java script for that but could you please let me know how & where to use Java script to create new button in object detail page in CRMOD.
    Thanks in advance.
    Regards,
    Manish

    Any related object on the detail page should have an "Add" or "New" or both buttons by default - This is vanilla functionality and will do the required action.
    If you want to modify this behaviour and do something tricky you will potentially have to go for javascript. You should add the javascript on a custom web tab on that Object.
    Admin --> Application Customization --> Contact -->Contact Web Applet
    Now, add your javascript in the code area, after you select the type = HTML for this web applet, expose this web applet on the Contact detail layout and your javascript will be invoked whenever this page is loaded.
    Check this online document to see how javascript can be embedded in CRM on Demand http://helponmyproject.com/TTOCOD/
    Cheers!
    Royston

  • Able to create new instances in Platform Edition 9.0?

    According to the Platform Edition 9.0 docs http://docs.sun.com/app/docs/doc/819-3662/6n5s9hmtq?a=view , it is possible to create new instances using create-instance command.
    However, I encountered an invalid command error in asadmin when trying to invoke create-instance:
    bash$ ./asadmin
    Use "exit" to exit and "help" for online help.
    asadmin> create-instance
    CLI147 Invalid command, create-instance
    asadmin>I am using Application Server Platform Edition 9.0_01 (build b14)
    SO, are we really able to create new instances in PE 9.0? Thanks in advance for any advice.

    Hi there !
    I don't belive of can perform these tasks on PE.
    The concepts of nodeagents , clusters and other are no present on the Platform edition.
    I also see no way of managing these new instances on the administration console, so ... my guess is it can be done
    Rp

  • After downloading 4.0 I get this message: JavaScript application can't create mcafee plug-in object: TypeError: components.classes[cid] is undefined

    I finished downloading Firefox 4.o to my Mac OS.X.
    When I try to open a website I get the message:
    [JavaScript Application] can't create mcafee plug-in object: TypeError: Components.classes[cid] is undefined
    If I click the OK button, the site opens, but without the McAfee alert at the bottom of the window.
    I had just downloaded 3.6.16, and got box suggesting download version 4.0 for better security, but that seems to be where the problem is!

    That indicates that an add-on you are using is not compatible, considering the other errors it is possibly the McAfee add-on. To confirm what add-on is causing this use the procedure in this link - https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • The following error message came when I tried to open Firefox and install Firefox Home. "can't create mcafee plug-in object: TypeError: Components.classes[cid] is undefined"

    The following error message came when I tried to open Firefox and install Firefox Home.
    "can't create mcafee plug-in object: TypeError: Components.classes[cid] is undefined"

    This issue can be caused by an extension or plugin that isn't working properly.
    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]

  • Create development instance by cloning from Production instance

    Hi,
    There is a requirement for us in Oracle E-Business Suite.
    Our client wants to create development instance by cloning from Production instance, at the same time they donot want live data. Can anyone suggest in this regard.
    i.e After cloning Dev Instance from Production, no live data to be available in dev.
    Thanks

    Hi,
    Hi,
    There is a requirement for us in Oracle E-Business Suite.
    Our client wants to create development instance by cloning from Production instance, at the same time they donot want live data. Can anyone suggest in this >regard.
    i.e After cloning Dev Instance from Production, no live data to be available in dev.
    ThanksRefer very good post by Hussain and Helios on same topic:
    Scarmble data after clone
    Regards,
    X A H E E R

  • With PS 7  create new  Place two objects on the new file  then you may cut copy and paste Cs2  create new  place two object on the new file Cut is not available how does one cut and paste in new file

    With PS 7
    create new
    Place two objects on the new file
    then you may cut copy and paste
    Cs2
    create new
    place two object on the new file
    Cut is not available how does one cut and paste in new file

    If your using File>Place then photoshop cs2 creates what's known as Smart Objects, which photoshop 7 didn't have.
    In photoshop cs2 you can rasterize the smart objects and that should make the Cut function available.
    Select both placed layers, right click on the area to the right of the tumbnail and select Rasterize Layers.
    If in photoshop cs2 you to Help>Photoshop Help and look under Layers>Smart Objects, that should give you a good overview of what smart objects are.

  • How to create new instance of the process from external web apps?

    Hi Everyone,
    How to create a new instance of the process which deploy to the weblogic server from the external web app?
    Thank you.

    Assuming the process includes a message start event, the simplest way is to use Web Service call. Once you've deployed the process you can use Enterprise Manager to get the URL of the WSDL. There's and icon at the top of the composite summary page for getting the WSDL, or you can get it from the test page. Use that WSDL URL to construct the client to use from the web app. If it's an ADF client you can generate either an ADF Data Control or a client proxy.

  • ADF viewScope is creating new instance without navigating away from view

    Hello,
    I'm using JDeveloper version 11.1.1.6.0.
    In a Portal application, I'm using view scoped Managed Beans. When I navigate to a page, as expected one instance of the Bean is created. I have dependent selectOneChoice objects inside this page, therefore a partial page refresh is generated when the user chooses a value, a value change listener is called, I read bean variables and do my thing. But here's the catch, a new instance of the Managed Bean is created before the value change listener is called. I have no idea why. According to documentation the viewScope bean should persist until the viewId changes. The end result is I'm screwed trying to read variables that should persist from page load inside this value change listener.
    But wait, that's not all. The issue here is the very first partial page refresh (or whatever it should be called). Only the first partial page refresh will cause the creation of a new managed bean instance. Any subsequent ones will not.
    So it goes like this:
    Page load -> @PostConstruct runs once -> Partial page refresh -> @PostConstruct runs again -> Partial page refresh -> @PostConstruct doesn't run -> Partial page refresh -> @PostConstruct doesn't run...
    I'm really at a loss of options here, the @PostConstruct running twice inside the very same view in a viewScope Bean is news to me. But then again, I'm new to ADF so what do I know. I noticed this happens with every viewScope bean in my application, not just this particular one. It just so happens that only in this case this became a problem.
    I'm in an all out war against this thing for more than a day now. The internet is my last resort before I make some dumb workaround that will consume me in my sleep. Any help is greatly appreciated.
    Edited by: 934172 on Sep 6, 2012 12:35 PM
    Edited by: 934172 on Sep 6, 2012 12:36 PM

    I'm determined to fix this thing no matter what the hell it takes.
    I found out exactly what is happening, even though I'm not sure why it happens. But the important question here is how to fix it.
    Here is the first request, the one that happens when I navigate to the page:
    http://localhost:7101/teste-Portal-context-root/faces/pages_test?_adf.ctrl-state=18hjxv8lyw_4Here are all the subsequent ones, the ones that happen when I select a choice:
    http://localhost:7101/teste-Portal-context-root/faces/oracle/webcenter/portalapp/pages/test.jspx?_adf.ctrl-state=18hjxv8lyw_4It's no wonder the server is confused and creates a new bean instance. Now what the hell? Why are they different? But more importantly, can I fix the first one? Can I force the bean created by the first one to answer for the second one?
    I still don't know. But hopefully I'll find out.

Maybe you are looking for

  • Reinstalling owned copy of Mt Lion

    Boought a new iMac.  Apple store cleaned old MacBook Pro of everything, back to original settings of OS X 10.7.5  Genius told me to go home and reinstall Mt Lion wich I had purchased.  Can't find anywhere that shows that I have a copy of Mt Lion that

  • Master/Slave settings for HD and SuperDrive

    i recently updated the hard drive to a 17" usb2 iMac flat panel, I upgraded the standard 80GB HD with a new maxtor 250GB disk, the problem is that the transfer rate from dvd/firewire/hd to hd are superslow. what i don't know is the jumper settings fo

  • Strange behavoir of JSF in JDeveloper

    Hi all. I'm having a problem with a JSF project thats running in a jdeveloper 9.03 ide. When i send to run a page, the browser shows that page not found. looking in the oc4j-app.log it shows javax.servlet.ServletException: Error initializing servlet

  • Unmeasured Billing Analysis

    Hi.. What is the different between Volumetric Amount and Fixed Amount? How to find the Premise volumetric and fixed amount with respect to Posting date,Rate Category and Cal. Year/Quarter  Could you please proved is there any table or any transaction

  • Missing oracle-ant.jar in ORACLE_HOME/ant/lib

    Hi I have version 10.1.3.3 of the Oracle Application Server Running. As I understand it, you are provided with Apache Ant via the default installation and you are supposed to have the file ORACLE_HOME/ant/lib/oracle-ant.jar in order use the oracle an