Java ME class access from another class - java-me

Java ME main class runs very well. It has a Form with CustomItem (Button like shape). When it is clicked keyPressed() is called in the CustomItem class. But I need to get information from the main class in the CustomItem class. As the main class is already run hence I can't create new object of the main class in the CustomItem's keyPressed() method. How to get access to the main class's element in the keyPressed() method?

You can do one thing, just pass the object of main class with your next class constructor when you calling that class. You can use your main class object for any purpose. Just pass it with your next class constructor. If you dont understand post code here i will tell you.
Thanks

Related

Can a GDScript class not extend anything?/Is there a class that every class must extend?

I'm making a GDScript class that shouldn't need to extend Node2D. It doesn't have an associated scene, and exists so that other classes in my project can interface with it, but will never be displayed directly by the engine. Can I simply not have the extends keyword at the top of the file?
You can extend Object or any of its descendants, not just Node.
I believe you can omit the extends statement and it will default to inheriting Reference, but you should be explicit and write extends Reference.
Read the docs on Object then Reference then Resource and see which one will work best for you.
You can then instance your new script like:
const MyScript = preload(‘path/to/my_script.gd’)
var my_script := MyScript.new()
Or if you have given your script a class_name you can omit the preload into constant step.

How to access external class within a class in groovy

I'm new to groovy...
I've made a class. Within this class, I'd like to call an external method : LOG.error, but somehow, groovy is complaining about the method not being part of the class... how should I call that external method ?
class GAPI{
private myvar
public getResult(){
this.myvar="blabla"
LOG.error("test")
}
}
Groovy provides #Slf4j annotation that can add log field to your class, e.g.
#Slf4j
class GAPI{
private myvar
public getResult(){
this.myvar="blabla"
log.error("test")
}
}
Alternatively you can use #Log annotation that adds log field that uses java.util.logging.Logger instead of one provided with Slf4j. However in this case you have to be aware that java.util.logging.Logger uses different API, so there is no log.error() method.
In your example Groovy throws MissingPropertyException, because LOG is not defined in your class. If there is a class LOG with static method error you will have to import this class. But most probably you should just create LOG field (with annotation or manually) and call it to be most explicit (otherwise your code gets unreadable).

Object can be used as class name even though a predefined Object class exists

i have created a class X in com.x package, since X class is there it didn't allowed me to create a class with name 'X' again.
now, i created a package java.lang and created a Object class with main method
its created, how it is allowing to create a class with same name and same package which is already exists.
when i try to execute it has thrown the below error
Error: Main method not found in class java.lang.Object, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
why is it happening? i know its pointing to predefined Object class and it didn't find main method.
thanks.

How should I represent the main method (java) using UML?

I have three classes: Bridge, Main and Car.
I have no idea about how to include the main method in my UML representation.
Should I list all the attributes...as well as the main method?
The main method does:
- a bit of calculation
- instantiate the other two classes
I would draw the Main, this way:
---------------------------
Main
---------------------------
---------------------------
+ main(String[] args): void
---------------------------
Is that correct?
Thanks
Your drawing is good, you just need to underline the main method to show that it is static. I think that you should model it since it shows that this class is one entry point to the system (there may be more).
you don't need to include main method in your UML and also as I remember, you should put all the members and methods that are present in your class except the main method. Since the main method is somewhat a given already
The main method should be drawn like this:
+ main(args: String[]): void
____________________________
Main class has, by definition, no instance; Relationship like association, agregation and so on are used between objets, so the main class in a diagram is not very usefull.

Using of Base Class and Derived Class and Inheritance

I has a 2 Methods in Base Class(say Method1 and Method2) and having a two derived class (say Derived Class1 and Derived Class2) which are inheriting from Base Class
Now the Derived Class1 will get the two methods of Base Class(Method1 and Method2) But Derived Class2 should get only one method of Base Class(say Method1).
so, can any one suggest how can i proceed in this scenario(i am using C# as a Programming Language)
Thank in Advance!
Declare the two method as virtual in the base class
virtual void Method1()
virtual void Method2()
You could implement Method1 as an extension method and only have it referenced by DerivedClass1.

Resources