instance

A field to count the amount instances of a class [duplicate]

时光怂恿深爱的人放手 提交于 2019-12-25 04:55:16
问题 This question already has answers here : post increment operator java (3 answers) Closed 6 years ago . I need to create a field to count the number of instances made by a class public class Circle { private int diameter; private int xPosition; private int yPosition; private String color; private boolean isVisible; private static int count = 0; /** * Create a new circle at default position with default color. */ public Circle() { diameter = 30; xPosition = 20; yPosition = 60; color = "blue";

How to check whether a variable is an instance of a module's subclass using rspec?

不羁岁月 提交于 2019-12-25 04:22:39
问题 I have a class structure that looks like this: module MyModule class MyOuterClass class MyInnerClass end end end I'm trying to make sure that a variable was correctly instantiated as a MyInnerClass using Rspec. printing the type of the class, it was MyModule::MyOuterClass::MyInnerClass. However, if I try to run the line expect{@instance_of_MyInnerClass}.to be_an_instance_of(MyModule::MyOuterClass::MyInnerClass) I get the error "You must pass an argument rather than a block to use the provided

Accessing GUI JTextField objects that are dynamically generated

旧时模样 提交于 2019-12-25 03:32:42
问题 I am writing a program that contains a JButton . Every time the button is clicked, a new JTextField is added to a JPanel . My problem is that, after the user has created all the JTextFields and filled them with information, I need to get the text of each field. How can I get access to the JTextFields when they are dynamically generated, as they don't have instance names? Is there a better way to get the text of each one, without knowing their instance name. Here is the code of the

objective-c (iphone sdk) access instance method from separate class

吃可爱长大的小学妹 提交于 2019-12-25 03:26:09
问题 I know this is a pretty well posted thing to do, but I still can't work it out. I have an instance method saveAllDataJobs in Jobs.m. - (void) saveAllDataJobs { ... } I am in DetailViewController.m and I want to run the method saveAllDataJobs, which is in Jobs.m. What precisely do I need in order for this code to run. Sorry for the repeat question, but I can't work it out. Regards 回答1: Read about "delegation" in documents. Here is the basics: When you create DetailViewController, you give it

accessing an instance in main from a form

狂风中的少年 提交于 2019-12-25 01:01:17
问题 /* Hi i am trying to make my first c# application on visual studio. I have created a class and an instance of that class in main and i am simply trying to query a member of that instance inside a click event on a form but its telling me the instance name does not exist in the current context. Any help would be appreciated here's my code. */ using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace WindowsFormsApplication10 { public class

C# Error 'Object Reference Not Set To An Instance Of An Object'

こ雲淡風輕ζ 提交于 2019-12-24 22:18:07
问题 I've read other questions about this but don't see where or why my code is throwing this error. The code I have is below, if anyone can see where i'm going wrong. private void btnSignIn_Click(object sender, EventArgs e) { sqlConnectionNW.ConnectionString = "Data Source=" + server + ";Initial Catalog=Northwind;Integrated Security=True"; try { sqlConnectionNW.Open(); String enteredDate = cmbDay.SelectedItem.ToString() + "/" + cmbMonth.SelectedItem.ToString() + "/" + cmbYear.SelectedItem

how to create in best way an instance from the class object

余生颓废 提交于 2019-12-24 21:04:46
问题 There is a way to avoid the slow reflection to create an instance from a class, obviously within another method ? For example: Foo foo = new Foo(); foo.create(Dog.class, "rocky"); class Foo { Object create(Class object, String dogName) { //create an instance of the class 'object' here passing the argument to constructor //e.g. Object obj = new object(dogName); <-- this is wrong return obj; } } class Dog extends Animal { Dog(String dogName) { this.name = dogName; } } class Animal { String name

jQuery ColorBox real multiple instances

99封情书 提交于 2019-12-24 19:25:09
问题 This question was asked before in a Google Group, but never really answered, and the group closed by the ColorBox developer Jack Moore (amazing plugin btw, thanks!). I want to create REAL multiple instances of a ColorBox lightbox. This in order to be able to open a lightbox instance and then when closing it, only hiding instead of removing it from the dom. I developed a Moodle Activity Module that supports a lightbox option. And in my course page I have multiple instances of the ColorBox

Set variable as type of class

孤人 提交于 2019-12-24 19:24:45
问题 I am trying to figure out how I can pass a variable as the declaration type (object) for a class in Python 3. Example: #class defintion class TestClass(Document): test = IntField() me = MongoEngine(app) testInstance = TestClass(me.Document) # How do i pass the Document variable I tried passing an instance of the MongoEngine variable as a variable to the TestClass but this isn't working properly? 回答1: I think you need to structure your class slightly different. Don't put Document in the class

Call non-static variable from a static function

风格不统一 提交于 2019-12-24 15:26:40
问题 I've recently started working with C++ and I have stumbled across a problem that I cannot seem to understand. class MyClass { bool eventActive = false; static bool JoinCommand() { if (eventActive == true) // eventActive error: "a nonstatic member reference must be relative to a specific object" { // do something here... } else { } }; I need JoinCommand to be static but I also need to use eventActive which is required to be non-static and is used/modified by other functions in the same class.