This will probably look like a really stupid piece of code.. but it works
My question is, how can I write the last part so there is only one extended Canvas class that can recieve a parameter for the image number
Thanks -
-
import java.io.IOException;
-
import javax.microedition.lcdui.Canvas;
-
import javax.microedition.lcdui.Command;
-
import javax.microedition.lcdui.CommandListener;
-
import javax.microedition.lcdui.Display;
-
import javax.microedition.lcdui.Displayable;
-
import javax.microedition.lcdui.Font;
-
import javax.microedition.lcdui.Graphics;
-
import javax.microedition.lcdui.Image;
-
import javax.microedition.lcdui.List;
-
import javax.microedition.midlet.MIDlet;
-
-
public class MyImages extends MIDlet implements CommandListener {
-
-
// The MIDlet's Display object
-
private Display mydisplay;
-
-
// Flag indicating first call of startApp
-
protected boolean started;
-
-
// Exit command
-
private Command exitCommand;
-
-
// Back to examples list command
-
private Command backCommand;
-
-
// The example selection list
-
private List examplesList;
-
-
// The Canvases used to demonstrate different Items
-
private Canvas[] canvases;
-
-
// The example names. Used to populate the list.
-
private String[] examples = {
-
"Image001", "Image002", "Image003", "Image004", "Image005", "Image006"
-
};
-
-
protected void startApp() {
-
if (!started) {
-
started = true;
-
mydisplay = Display.getDisplay(this);
-
-
// Create the common commands
-
exitCommand = new Command("Exit", Command.EXIT, 0);
-
backCommand = new Command("Back", Command.BACK, 1);
-
-
// Create the canvases
-
canvases = new Canvas[examples.length];
-
canvases[0] = createDrawImageCanvas(0);
-
canvases[1] = createDrawImageCanvas(1);
-
canvases[2] = createDrawImageCanvas(2);
-
canvases[3] = createDrawImageCanvas(3);
-
canvases[4] = createDrawImageCanvas(4);
-
canvases[5] = createDrawImageCanvas(5);
-
-
// Create the list of examples
-
examplesList = new List("Select a picture", List.IMPLICIT);
-
for (int i = 0; i < examples.length; i++) {
-
examplesList.append(examples[i], null);
-
}
-
examplesList.setCommandListener(this);
-
-
// Start with the List
-
mydisplay.setCurrent(examplesList);
-
}
-
}
-
-
protected void pauseApp() {
-
}
-
-
protected void destroyApp(boolean unconditional) {
-
}
-
-
public void commandAction(Command c, Displayable d) {
-
if (d == examplesList) {
-
// New example selected
-
int index = examplesList.getSelectedIndex();
-
mydisplay.setCurrent(canvases[index]);
-
} else if (c == exitCommand) {
-
// Exit. No need to call destroyApp
-
// because it is empty.
-
notifyDestroyed();
-
} else if (c == backCommand) {
-
// Go back to main selection list
-
mydisplay.setCurrent(examplesList);
-
}
-
}
-
-
-
// Create the Canvas for the image drawing example
-
private Canvas createDrawImageCanvas(int idx) {
-
-
switch (idx) {
-
case 0 :
-
Canvas canvasx0 = new DrawImageCanvas0();
-
canvasx0.addCommand(exitCommand);
-
canvasx0.addCommand(backCommand);
-
canvasx0.setCommandListener(this);
-
return canvasx0;
-
case 1 :
-
Canvas canvasx1 = new DrawImageCanvas1();
-
canvasx1.addCommand(exitCommand);
-
canvasx1.addCommand(backCommand);
-
canvasx1.setCommandListener(this);
-
return canvasx1;
-
case 2 :
-
Canvas canvasx2 = new DrawImageCanvas2();
-
canvasx2.addCommand(exitCommand);
-
canvasx2.addCommand(backCommand);
-
canvasx2.setCommandListener(this);
-
return canvasx2;
-
case 3 :
-
Canvas canvasx3 = new DrawImageCanvas3();
-
canvasx3.addCommand(exitCommand);
-
canvasx3.addCommand(backCommand);
-
canvasx3.setCommandListener(this);
-
return canvasx3;
-
case 4 :
-
Canvas canvasx4 = new DrawImageCanvas4();
-
canvasx4.addCommand(exitCommand);
-
canvasx4.addCommand(backCommand);
-
canvasx4.setCommandListener(this);
-
return canvasx4;
-
case 5 :
-
Canvas canvasx5 = new DrawImageCanvas5();
-
canvasx5.addCommand(exitCommand);
-
canvasx5.addCommand(backCommand);
-
canvasx5.setCommandListener(this);
-
return canvasx5;
-
}
-
-
Canvas canvasx0 = new DrawImageCanvas0();
-
canvasx0.addCommand(exitCommand);
-
canvasx0.addCommand(backCommand);
-
canvasx0.setCommandListener(this);
-
return canvasx0;
-
-
}
-
-
}
-
-
// A canvas that illustrates image drawing
-
class DrawImageCanvas0 extends Canvas {
-
static Image image;
-
-
public void paint(Graphics g) {
-
int width = getWidth();
-
int height = getHeight();
-
int idx = 1;
-
-
// Fill the background using black
-
g.setColor(0);
-
g.fillRect(0, 0, width, height);
-
-
// Load an image from the MIDlet resources
-
if (image == null) {
-
try {
-
image = Image.createImage("/earth" + 0 + ".png");
-
} catch (IOException ex) {
-
g.setColor(0xffffff);
-
g.drawString("Failed to load image!", 0, 0, Graphics.TOP | Graphics.LEFT);
-
return;
-
}
-
}
-
-
g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
-
-
}
-
}
-
-
-
// A canvas that illustrates image drawing
-
class DrawImageCanvas1 extends Canvas {
-
static Image image;
-
-
public void paint(Graphics g) {
-
int width = getWidth();
-
int height = getHeight();
-
int idx = 1;
-
-
// Fill the background using black
-
g.setColor(0);
-
g.fillRect(0, 0, width, height);
-
-
// Load an image from the MIDlet resources
-
if (image == null) {
-
try {
-
image = Image.createImage("/earth" + 1 + ".png");
-
} catch (IOException ex) {
-
g.setColor(0xffffff);
-
g.drawString("Failed to load image!", 0, 0, Graphics.TOP | Graphics.LEFT);
-
return;
-
}
-
}
-
-
g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
-
-
}
-
}
-
-
// A canvas that illustrates image drawing
-
class DrawImageCanvas2 extends Canvas {
-
static Image image;
-
-
public void paint(Graphics g) {
-
int width = getWidth();
-
int height = getHeight();
-
int idx = 1;
-
-
// Fill the background using black
-
g.setColor(0);
-
g.fillRect(0, 0, width, height);
-
-
// Load an image from the MIDlet resources
-
if (image == null) {
-
try {
-
image = Image.createImage("/earth" + 2 + ".png");
-
} catch (IOException ex) {
-
g.setColor(0xffffff);
-
g.drawString("Failed to load image!", 0, 0, Graphics.TOP | Graphics.LEFT);
-
return;
-
}
-
}
-
-
g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
-
-
}
-
}
-
-
// A canvas that illustrates image drawing
-
class DrawImageCanvas3 extends Canvas {
-
static Image image;
-
-
public void paint(Graphics g) {
-
int width = getWidth();
-
int height = getHeight();
-
int idx = 1;
-
-
// Fill the background using black
-
g.setColor(0);
-
g.fillRect(0, 0, width, height);
-
-
// Load an image from the MIDlet resources
-
if (image == null) {
-
try {
-
image = Image.createImage("/earth" + 3 + ".png");
-
} catch (IOException ex) {
-
g.setColor(0xffffff);
-
g.drawString("Failed to load image!", 0, 0, Graphics.TOP | Graphics.LEFT);
-
return;
-
}
-
}
-
-
g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
-
-
}
-
}
-
-
// A canvas that illustrates image drawing
-
class DrawImageCanvas4 extends Canvas {
-
static Image image;
-
-
public void paint(Graphics g) {
-
int width = getWidth();
-
int height = getHeight();
-
int idx = 1;
-
-
// Fill the background using black
-
g.setColor(0);
-
g.fillRect(0, 0, width, height);
-
-
// Load an image from the MIDlet resources
-
if (image == null) {
-
try {
-
image = Image.createImage("/earth" + 4 + ".png");
-
} catch (IOException ex) {
-
g.setColor(0xffffff);
-
g.drawString("Failed to load image!", 0, 0, Graphics.TOP | Graphics.LEFT);
-
return;
-
}
-
}
-
-
g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
-
-
}
-
}
-
-
// A canvas that illustrates image drawing
-
class DrawImageCanvas5 extends Canvas {
-
static Image image;
-
-
public void paint(Graphics g) {
-
int width = getWidth();
-
int height = getHeight();
-
int idx = 1;
-
-
// Fill the background using black
-
g.setColor(0);
-
g.fillRect(0, 0, width, height);
-
-
// Load an image from the MIDlet resources
-
if (image == null) {
-
try {
-
image = Image.createImage("/earth" + 5 + ".png");
-
} catch (IOException ex) {
-
g.setColor(0xffffff);
-
g.drawString("Failed to load image!", 0, 0, Graphics.TOP | Graphics.LEFT);
-
return;
-
}
-
}
-
-
g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
-
-
}
-
}
-
-
3 2323 hsn 237
New Member
hi
me my self i am learning J2ME
and i have a problem with downloading and installing it.
can you tell me how to do it plzzzzzzzzzzzz.
i really need to know how to do it.
You just need to put the image creation code in a method that takes the image name/path as a variable. You then call that method passing it different values for the name/path.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Oz Mortimer |
last post by:
Hi There,
Is there any way that I can display an XML page within a J2ME application?
Many Thanks
Oz.
|
by: Oz Mortimer |
last post by:
Hi,
Is there any way that I can scroll a canvas - i.e. if there are too many
items on the canvas you can still access by pressing down. I know Form does
this (apparently) but I need to do it using a canvas!. Maybe I can attach my
Canvas to a form?
Ideas?
Oz.
|
by: Todd Christy |
last post by:
I am building a J2ME application for a BlackBerry handheld device.
This application connects to an IIS server via HTTP to execute remote
ASPX-based services that collect and return data. We are working on
our authentication scheme, and trying to figure out the best approach
that will:
* Pass the ID and password via HTTP from the J2ME app to an IIS server
(preferably encrypted)
* Authenticate the ID/password combination against an...
|
by: Dave Rathnow |
last post by:
We are looking at using J2ME in a embedded device that will
be deployed in an industrial application and I've been doing some
research to see how practical J2ME would be for our application.
Most of the devices I've come across that use J2ME are consumer
devices like phones and PDAs. I would be interested in hearing
from anyone who might be using J2ME on devices other than
consumer type devices.
What kind of processor are you using? ...
|
by: Sveta |
last post by:
Hi, all!
I am new with J2ME.
I have application that has form with 2 commands (exit and select).
All UI uses are high level API, and it is very important to leave it
high-level.
This application works fine on some devices. But at Samsung mobile
phone, I have a problem.
In this phone my 2 commands appear under menu command, and then I can
| |
by: Ralph Yozzo |
last post by:
Hi,
Does anyone know of a good place to look for a starting point -- I'm
building an application on J2ME and I want to have a scripting
language to both access my UI and the database RMS. Most phones have
very limited resources so the interpreter should be small and fast.
Does anyone know of a simple scripting language source to handle if (
) { } else {} and while ( ) { } and expressions and function calls
back into Java. I'm using...
|
by: Tomislav |
last post by:
Hi!
I have 3 questions, so here they are:
1.I would like to make an aplicaton wich can run on GSM mobile phones -
SonyErricson k700 for instance. Is the J2ME what I am looking for?
2. Is there a way my Java aplicatio can accest SMS inbox on my GSM mobile
phone and get data from it?
For example lets say I want to make a game. In the game I hava the
|
by: Clay Shirky |
last post by:
Can Jython be used to write applications to run in J2ME environments?
I ask because Python seems an ideal language for teaching students to
write applications for the phone or other mobile devices.
If this is possible, I would be grateful for any pointers to a
Jython/J2ME reference.
-clay
|
by: mayankcdac |
last post by:
Hi i am a new guy in j2me field i am working in j2me gaming but i want to switch from gaming to application. i am facing some problems to build j2me application can any one give me any source code( any application of j2me which is complete) for study my email: <deleted>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |