Results 1 to 2 of 2
  1. #1
    elenora is offline Member
    Join Date
    Apr 2011
    Posts
    30
    Rep Power
    0

    Unhappy How to use abstract class?

    Hi, I implemented some code that has an alert class which is type of Canvas, that is like JFrame in Java and it has a keyPress method which must work different for each class that using alert class. For example the keyPress method has 2 buttons that the function of each button is different for each class! Could anyone tell me How can I implement that ?
    below is part of my code:

    public class myAlert extends Canvas implements CommandListener{
    public myAlert(int width,int height,String str,String left_str,String right_str){
    }
    protected void paint(Graphics g) {
    g.setColor(0, 0,0);
    g.drawRoundRect(5, 180, width-10, height, 8, 8);
    g.drawRoundRect(15, 185, width-15, height-5, 7, 7);
    g.setColor(0xbfd4f6);
    g.fillRoundRect(0, 180, width, height, 8, 8);
    ///////////////
    }
    protected void keyPressed(int keyCode)
    {
    switch(keyCode){
    case -6: // select button
    //here is about my question!
    break;
    case -7: //close button
    //here is about my question!

    break;
    }
    }
    }
    Public class M(){
    protected void keyPressed(int keyCode) {

    switch (state) {
    case STATE_INPUT_LEFT:
    // do work for focus on the left
    if (keyCode >= KEY_NUM0 && keyCode <= KEY_NUM9 && digitsEntered < 10) {
    digits_left[digitsEntered] = (char) ('0' + (keyCode - KEY_NUM0));
    digitsEntered++;
    repaint();
    if(digitsEntered>=8){
    state=STATE_INPUT_RIGHT;
    m= new myAlertw, 150,"Ok " ,"exit",”system”);
    //I want that if user click on Ok button the main page must be shown to user
    Display.getDisplay(midlet).setCurrent( m); // Midlet is a like Main class in Java
    break;
    }
    }
    }
    Public class N(){
    public void commandAction(Command c, Displayable d) {
    String label = c.getLabel();
    if(label.equals("Exit")){
    midlet.exit();
    }
    else if(label.equals("Enter")){
    m= new myAlert(w, 150,”yes”,”No”,”Print” );
    // I want here that if user clicks on yes another message be shown to user
    Display.getDisplay(midlet).setCurrent( m);

    }
    }
    here is part of my code! as you see in M class and N class left button's function of Alert class is diffrent from each other! Now Could any body help me?
    :(

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Can you please use code tags?
    Unformatted code is hard to follow.

    Also, I'm not entirely clear on your question. Are you asking how to write two subclasses of myAlert, each with different keyPressed() methods?

Similar Threads

  1. Abstract class
    By DeepakZenTech in forum New To Java
    Replies: 8
    Last Post: 03-22-2011, 06:07 AM
  2. How can I call abstract class methods from another class
    By srinivas2828 in forum New To Java
    Replies: 13
    Last Post: 03-12-2010, 02:33 PM
  3. Can this be done using abstract class??
    By romina in forum New To Java
    Replies: 6
    Last Post: 03-02-2009, 12:46 PM
  4. Replies: 6
    Last Post: 02-11-2009, 10:51 AM
  5. Replies: 0
    Last Post: 04-02-2008, 07:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •