Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8524249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:38:07+00:00 2026-06-11T07:38:07+00:00

I’ve asked this already but I need further knowledge. I’m trying to link two

  • 0

I’ve asked this already but I need further knowledge. I’m trying to link two class together using button command. I followed the last answer here but when I separate classes, it doesn’t work. I used b2Command to trigger the event. Here’s my code:

MainMidlet.java

  /*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
  */

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Display;

/**
* @author bon
*/
public class MainMidlet extends MIDlet implements CommandListener, 
ItemCommandListener, ItemStateListener{
private Display display;
private Form form;
private Command okCommand, backCommand, exitCommand, b1Command, b2Command, exCommand,    boutCommand;
private StringItem b1stringItem, b2stringItem, boutstringItem, exstringItem;

public AddCalendarEvent addcalendarevent;

public MainMidlet(){
    okCommand = new Command ( "OK", Command.OK, 1); 
    exitCommand = new Command ( "EXIT", Command.EXIT, 1);
    backCommand = new Command ( "BACK", Command.BACK, 1);
    b1Command = new Command ( "BUTTON", Command.ITEM, 2);
    b2Command = new Command ( "BUTTON", Command.ITEM, 2);
    exCommand = new Command ( "BUTTON", Command.ITEM, 2);
    boutCommand = new Command ( "BUTTON", Command.ITEM, 2);

    form = new Form ( "CyberMe");

    b1stringItem = new StringItem (null, "Make Todo", Item.BUTTON); 
    b1stringItem.setItemCommandListener (this); 
    b1stringItem.setDefaultCommand (b1Command);

    b2stringItem = new StringItem (null, "Set Alarm", Item.BUTTON); 
    b2stringItem.setItemCommandListener (this); 
    b2stringItem.setDefaultCommand (b2Command);

    boutstringItem = new StringItem (null, "About", Item.BUTTON); 
    boutstringItem.setItemCommandListener (this); 
    boutstringItem.setDefaultCommand (boutCommand);

    exstringItem = new StringItem (null, "Exit", Item.BUTTON); 
    exstringItem.setItemCommandListener (this); 
    exstringItem.setDefaultCommand (exCommand);

    form.append ( "Any Appointment?"); 
    form.append (b1stringItem);
    form.append (b2stringItem);
    form.append (boutstringItem);
    form.append (exstringItem);

    form.addCommand (okCommand); 
    form.addCommand (exitCommand); 
    form.setCommandListener (this);
}

public void startApp() {
    display = Display.getDisplay(this);
    display.setCurrent(form);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command c, Displayable d) {
    throw new UnsupportedOperationException("Not supported yet.");
}

public void commandAction(Command c, Item item) {

if (c == b1Command) { 
//display.setCurrent (); 
}
else if (c == b2Command){
    addcalendarevent = new AddCalendarEvent(this);
    display.setCurrent(addcalendarevent);
}
else if (c == exCommand){
destroyApp(false); 
notifyDestroyed ();
}
//else if (c == boutCommand)
//display.setCurrent ();
}

public void itemStateChanged(Item item) {
    throw new UnsupportedOperationException("Not supported yet.");
}
}

And here’s what I’m trying to link:
AddCalendarEvent.java

        /*
        * To change this template, choose Tools | Templates
        * and open the template in the editor.
        */
        import javax.microedition.midlet.MIDlet;
        import javax.microedition.lcdui.Displayable;
        import javax.microedition.lcdui.Display;
        import javax.microedition.lcdui.Form;
        import javax.microedition.lcdui.CommandListener;
        import javax.microedition.lcdui.TextField;
        import javax.microedition.lcdui.DateField;
        import javax.microedition.lcdui.Command;
        import javax.microedition.lcdui.Alert;

        import javax.microedition.pim.PIM;
        import javax.microedition.pim.PIMItem;
        import javax.microedition.pim.EventList;
        import javax.microedition.pim.Event;
        import javax.microedition.pim.PIMException;

        import java.util.Date;
        /**
        *
        * @author bon
        */
        public class AddCalendarEvent extends MainMidlet{
            private Display display;
            // Form where user can enter data of new event.
            private Form addEventForm;

            // Command for adding event to list of events. Placed on addEventForm.
            private Command cmdAddEvent;
            // Command for exiting from application. Placed on addEventForm.
            private Command cmdExit;

            // Text field for summary of event.
            private TextField summaryField;
            // Date field for start data of event.
            private DateField startDateField;
            // Date field for end data of event.
            private DateField endDateField;
            // Text field for note of event.
            private TextField noteField;
            // Text field for location of event.
            private TextField locationField;

            /**
            * Constructor.
            */    
            public AddCalendarEvent() {
                if(checkPIMSupport() == false) {
                    exitMIDlet();
                }

                initializeComponents();
            }

            /**
            * Initializes components of midlet.
            */      
            public void initializeComponents() {
                display = Display.getDisplay(this);

                // Create form for adding event.
                addEventForm = new Form("Add event");

                // Add commands to form and set listener for it.
                cmdAddEvent = new Command("Add event", Command.SCREEN, 0);
                addEventForm.addCommand(cmdAddEvent);

                cmdExit = new Command("Exit", Command.EXIT, 0);
                addEventForm.addCommand(cmdExit);

                addEventForm.setCommandListener(this);        

                try {
                    // Get list of events.
                    EventList eventList = (EventList)PIM.getInstance().openPIMList(
                            PIM.EVENT_LIST, PIM.READ_WRITE);

                    // Create controls based on supported fields for event.
                    if(eventList.isSupportedField(Event.SUMMARY) == true) {
                        summaryField = new TextField("Summary", null, 20, 
                                                    TextField.ANY);
                        addEventForm.append(summaryField);
                    } else {
                        // At least "summary" field must be supported. 
                        // If not, throw exception.
                        eventList.close();
                        throw new Exception("Summary field is not supported");
                    }

                    if(eventList.isSupportedField(Event.START) == true) {
                        startDateField = new DateField("Start date", 
                                                    DateField.DATE_TIME);
                        startDateField.setDate(new Date());
                        addEventForm.append(startDateField);
                    }

                    if(eventList.isSupportedField(Event.END) == true) {
                        endDateField = new DateField("End date", DateField.DATE_TIME);
                        endDateField.setDate(new Date());
                        addEventForm.append(endDateField);
                    }

                    if(eventList.isSupportedField(Event.NOTE) == true) {
                        noteField = new TextField("Note", null, 20, TextField.ANY);
                        addEventForm.append(noteField);
                    }

                    if(eventList.isSupportedField(Event.LOCATION) == true) {
                        locationField = new TextField("Location", null, 20, 
                                                    TextField.ANY);
                        addEventForm.append(locationField);
                    }            

                    // Close list of events.
                    eventList.close();

                } catch(PIMException pimExc) {
                    // TODO: Handle error on working with PIM.
                }
                catch(SecurityException secExc) {
                    // TODO: Handle error on access to PIM.
                }
                catch(Exception exc) {
                    // If unknown error was catched, exit from application.
                    exitMIDlet();
                }
            }

            /**
            * Checks PIM support.
            * @return - true if PIM is supported, false otherwise.
            */    
            private boolean checkPIMSupport() {
                String propValue = System.getProperty("microedition.pim.version");
                if(propValue != null) {
                    return true;
                } else {
                    return false;
                }
            }

            /**
            * Adds event to list of events. 
            * Gets data for event from addEventForm controls.
            */
            private void addEvent() {
                try {
                    // Get list of events.
                    EventList eventList = (EventList)PIM.getInstance().openPIMList(
                            PIM.EVENT_LIST, PIM.READ_WRITE);            

                    // Create new event.
                    Event event = eventList.createEvent();

                    // Get data from controls
                    if(eventList.isSupportedField(Event.SUMMARY) == true) {
                        String summary = summaryField.getString();
                        event.addString(Event.SUMMARY, PIMItem.ATTR_NONE, summary);
                    } else {
                        // At least summary must be supported.
                        eventList.close();
                        throw new Exception("Summary field for event is not supported");
                    }

                    if(eventList.isSupportedField(Event.START) == true) {
                        long startDate = startDateField.getDate().getTime();
                        event.addDate(Event.START, PIMItem.ATTR_NONE, startDate);
                    }

                    if(eventList.isSupportedField(Event.END) == true) {
                        long endDate = endDateField.getDate().getTime();
                        event.addDate(Event.END, PIMItem.ATTR_NONE, endDate);
                    }

                    if(eventList.isSupportedField(Event.NOTE) == true) {
                        String note = noteField.getString();
                        event.addString(Event.NOTE, PIMItem.ATTR_NONE, note);
                    }

                    if(eventList.isSupportedField(Event.LOCATION) == true) {
                        String location = locationField.getString();
                        event.addString(Event.LOCATION, PIMItem.ATTR_NONE, location);
                    }      

                    // Commit event.
                    event.commit();
                    // Close list of events.
                    eventList.close();

                    // Notify user that event was added
                    showAlert("Info", "Event was successfully added.");

                } catch(PIMException pimExc) {
                    // TODO: Handle error on working with PIM.
                    showAlert("PIMException", pimExc.getMessage());
                }
                catch(SecurityException secExc) {
                    // TODO: Handle error on access to PIM.
                    showAlert("SecurityException", secExc.getMessage());
                }
                catch(Exception exc) {
                    // TODO: Handle all other errors.
                    showAlert("Exception", exc.getMessage());
                }   
            }

            /**
            * Shows alert with specified title and text.
            * @param title - Title of alert.
            * @param message - text of alert.
            */
            private void showAlert(String title, String message) {
                Alert alert = new Alert(title);
                alert.setString(message);
                alert.setTimeout(Alert.FOREVER);
                display.setCurrent(alert);
            }

            private void exitMIDlet() {
                notifyDestroyed();
            }

            public void commandAction(Command command, Displayable displayable) {
                if(command == cmdAddEvent) {
                    addEvent();
                }

                if(command == cmdExit) {
                    exitMIDlet();
                }
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:38:09+00:00Added an answer on June 11, 2026 at 7:38 am

    try this out,

    // Define a public static method in your MainMidlet class

    private static Display display;  // declare static Display variable.
    
    public static Display getDisplay () 
    {
        return display;
    }
    

    Now access this method from AddCalendarEvent class as follows,

    private void showAlert(String title, String message) 
    {
        Alert alert = new Alert(title);
        alert.setString(message);
        alert.setTimeout(Alert.FOREVER);
        MainMidlet.getDisplay().setCurrent(alert);  // this line has been changed
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.