• Post Reply Bookmark Topic Watch Topic
  • New Topic

Beginner to Java  RSS feed

 
Chris Cordner
Greenhorn
Posts: 5
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I'm aiming to learn Java with a view to developing mobile apps. I'm using Netbeans IDE with the Codenameone plugin, which I'm particularly attracted to because both simulating and building the apps are very easy.

I've worked through the CodeCademy Java tutorial which was very helpful, so what I'm now trying to do is to work upwards from a basic 'Hello World' to get it something approaching functional.

In the main code class, I have the following:



This works fine and displays the labels as I would like them to. I have created another class, with the intention of building a separate form:



What I'm trying to do, is create a button on the first form ("Hi") that navigates to the second form ("newPage"). As a very new beginner, what I would like to know is:

1) Am I doing the right thing by setting the form up as a new class
2) How do I create a button to open it - what code do I attach to the button to call it? Am I right in saying I'm trying to call the main method of the subMenu class?
3) If I was to create a third button to close the app (the "stop" method of the "HUMPS" class?) how do I do this?

Afraid I'm just trying to get to grips with the Object Oriented business. Starting to understand it, but struggling.

Thanks
Chris

 
Knute Snortum
Sheriff
Posts: 4081
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since no one has responded in a while, I'll try helping you, but the problem will be that I know nothing about the Codenameone product. From what I can tell from their website, you are expected to be a proficient Java coder first. It may be good to do some Java programming that is not Codenameone first to build up your Java proficiency. It looks like questions specific to Codenameone should be posted to Stackoverflow with the tag "codenameone", but I would not post questions about basic Java there. This is a much better place for that. Going through the Oracle Java Tutorials might be a better place to start.

All that said, let's see if I can help you.

1) Am I doing the right thing by setting the form up as a new class

Probably, but putting code in a main() method is almost certainly wrong. I would try putting the code in a constructor or a non-main method. Also, by convention class names start with an uppercase letter.

2) How do I create a button to open it - what code do I attach to the button to call it? Am I right in saying I'm trying to call the main method of the subMenu class?

You never call a main method from an object. To create the object, use the new keyword.
  SubMenu sub = new Submenu();
Then, if the method name was called "startMe", you would invoke the method on the object.
  sub.startMe();

3) If I was to create a third button to close the app (the "stop" method of the "HUMPS" class?) how do I do this?

This would be specific to Codenameone. I don't know.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!