Results 1 to 2 of 2
Thread: How to use abstract class?
- 04-10-2011, 05:32 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 30
- Rep Power
- 0
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?
:(
- 04-11-2011, 10:49 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Abstract class
By DeepakZenTech in forum New To JavaReplies: 8Last Post: 03-22-2011, 06:07 AM -
How can I call abstract class methods from another class
By srinivas2828 in forum New To JavaReplies: 13Last Post: 03-12-2010, 02:33 PM -
Can this be done using abstract class??
By romina in forum New To JavaReplies: 6Last Post: 03-02-2009, 12:46 PM -
Difference between Abstract class having only abstract method and a Interface class
By Santoshbk in forum New To JavaReplies: 6Last Post: 02-11-2009, 10:51 AM -
what is the Priority for execution of Interface class and a Abstract class
By Santoshbk in forum Advanced JavaReplies: 0Last Post: 04-02-2008, 07:04 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks