How to create Array of forms in java me - java-me

I need to create an array of multiple forms, the code below doesn't seem to be working . .
private Form[] myForm3;
myForm3[0] = new Form("Course grade points in each sem " );
Display.getDisplay(this).setCurrent(myForm3[0]);
I am actually trying to create a form which accepts no of courses in each semester, and the grade in each course of each semester, I wanted to take input of grades of course of a semester each in a separate form ( each form would have semester, no. of courses and respective grades), now I got to create those many separate semester forms based on user input . .
The idea I have is to create a function with form array in it, call the same function to display next form with necessary changes accordingly
I tried a lot, struck with array of forms, it does not seem to be working. . I have not used threads either, can this be used in any way?
Any other idea would be helpful with some code provided !

private Form[] myForm3 = new Form[3] ;
You need to initialize the array

Related

how to create a new hash table

I want to implement a new hash table with chaining as an array of lists.
Each object in this inter list will be an implementation of a new class that I created (called " search " ).
Can you please help me?
Thanks.
well I managed to do that by myself so thanks anyway.
after I've learned about hash tables in Java last year i thought it's kinda the same (a special object ) but actually it is just as array of list in python.
if someone else have a different way to do that I'd like to hear about it.

Designing library to generate dynamic MDX query

We are generating MDX query dynamically. We pass list of Columns ([DimesnionName].[Attribute.Name] format), Rows ([DimesnionName].[Attribute.Name] format) and Filter ([DimesnionName].[Attribute.Name].[Member Name] format) along with other inputs like, cube name, page number, measure etc.
This information is passed to a C# library and then we use lot of 'If' and 'Else' conditions to process this input and generate MDX query as a string. It requires lot of string manipulation.
You can say it has a workflow. After going through each condition, system generates some output. I am wondering if there is a smarter way to design this library.
I want to remove if else conditions.
I want to make it more readable.
I want to make it more manageable
My Question is: Is there any design principle I can use? I can think of using Windows WorkFlow. Please provide your suggestions
I'm actually on here to see if someone has done just that so I don't have to. No luck so far. But off the top of my head what you might want to look at is some form of rules engine that will evaluate the state of target string and add your various criteria.
Now I haven't even started to look into the syntax of MDX. I'm not that far along, but if I wanted to create an engine to create sql queries I'd look at the parts ( simplest case first ) you need list of columns, a table and list of where clauses. So you could have three or maybe just two basic engine classes one that takes a list of strings and (or better yet a list of expressions) and concatenates them ( or evaluates and then concats them ). If target string is empty then targetString = "select "+ x else targetString = ", " + x. Then do something similar with the where expression. You can get considerably more fancy for that building classes that implement the different forms of where expressions and so on. Then ultimately you'd pass your engine something like
MySqlEngine(new[] {"FirstName", "LastName", "GirlFriendsAddress"},
new []{EqualsExpression("FirstName","Brown"), EqualsExpression("LastName",Dynamite")},
"People");
and it would return
"SELECT FirstName, LastName, GirlFriendsAddress From People Where FirstName = \"Brown\" AND LastName = \"Dynamite\""
I would highly recommend using Expressions to evaluate properties on a target model that matches your table. Then you could make MySqlEnigine(...) you wouldn't have to provide to table name because your model could be named the same and you'd use no strings except for target value of the where clauses.
I know this is not the engine you want but I don't know MDX yet so you'll have to use this as an analogy.
Final thoughts DO NOT USE Window Workflow. You will want to kill yourself half way through and if you make it all the way through than there will be developers cursing your name for many years in the future.
Good luck
oh and if you build the please open source it and tell me so I don't have to do it.

Breadcrumbs error in Kohana

I am implementing breadcrumbs on my application using Kohana framework using https://github.com/RaymondCrandall/kohana-breadcrumbs
I have a Category section which internally has many other sub categories n so on. One controller called Category.php having two action:
1. index($cat) (called when I click on each category until it reaches the last sub category)
2. category($cat) (called when I click on last sub category i.e. on leaf node )
The way I wrote my code into both action is:
Breadcrumbs::add(Breadcrumb::factory()->set_title("Home")->set_url(url::site()));
Breadcrumbs::add(Breadcrumb::factory()->set_title("Categories")->set_url(url::site('categories')));
if($cat != NUll) {
Breadcrumbs::add(Breadcrumb::factory()->set_title($cat)->set_url(url::site('categories/' .$cat )));
}
$actual = Breadcrumbs::get();
$view->breadcrumbs = $actual;
The problem is it shows me only three levels. How can I extend it to 4th level or more.
Eg. home>category>stationary>dress. How can I save my previous values of $actual?
So when I click on dress, index action is called and replaces my array with
home>category>dress since parameter '$cat= dress'.
I don't think this is much related to the mentioned plugin.
You are just using the category name string, a simple string doesn't even know what is a category, event less what is it's name, and hierarchy.
I see three options:
Get all your parent relations from the DB, or wherever you store them, run a loop that prints breadcrumbs, until it reaches the leaf.
Map your actions so they accept full path, for example "index/stationary/dress", and extract all the values from the path parameters (no need for DB call in this case)
Store an array with previous values in session, and recreate breadcrumb from that array. Also no DB calls here. Note that, in this case you have to be careful when to empty the array. Depends on your logic. You would have to recognize when a leaf has been hit, and empty the array then.

Dynamically adding the same UserControl multiple times

I have a simple UserControl that I've created that simply allows a user to enter the date. For the time being, it has a single Textbox with ID="tbDate". I am trying to dynamically add this control multiple times via (for example) placeholder.Controls.Add(LoadControl()) but am receiving the error "An entry with the same key already exists". I could, perhaps, change the ID of the elements but then it would be difficult to grab the value entered by the user.
Does anyone have an idea on this?
Thanks!
I generate a unique identifier as part of a Component class that I created and then use that value as the Control.ID. You can generate this unique value in any way you'd like but I am storing it as part of a database table. In the end it isn't that important since when the class is instantiated the values are initialized and consistent throughout the run of the application.
The class has a private instance variable:
private Control _control;
When adding the control to the form (and, specifically, the placeholder) I do something similiar to this. Note that c references my created class.
c.Control.ID = c.ComponentName + c.UniqueIdentifier;
phHere.Controls.Add(c.Control);
Then when I need to reference the control at a later point I essentially reverse the steps above:
string component = c.ComponentName + c.UniqueIdentifier;
UserControl uc = (UserControl)ph.FindControl(component);
Hopefully this helps. If you have any questions please feel free to ask. The root of the problem, though, is that the Control.ID must be set in order to avoid the error.
Thanks

Form Class in J2ME Polish

I was just wondering if the Form Class in the J2ME polish api for GUI development maintains a list of references to the Items that are appended to it.
The Form that I am using has a number of text fields appended to it
using the following code.
form.append(new TextField(...)) and then all this goes into a for loop.
How do I refer to these TextFields??
form is a reference to an existing form.
In case anyone is interested ... the answer is yes.
You can use the Form get( int itemNum ) method to retrieve the Item appended at position itemNum.
The size() method will tell you how many items have been appended for the Form.

Resources