I've an Html String:
String html="<p><img border=\"1\" align=\"left\" width=\"150\" vspace=\"2\" hspace=\"2\" height=\"159\" src=/"tmdbuserfiles/ntr-vv-vinayak-pics.jpg\" alt=\"Prithvi II, ballistic missile, DRDO, armed forces,Chandipur, Balasore district, Odisha State\" />The Strategic Forces Command of the armed forces successfully flight-tested the surface-to-surface Prithvi II missile from Chandipur in Balasore </P>";
I want to display the text as well as Image on my LWUIT Form Screen,For my Requirement I've used the below code:
public class LwuitMidlet extends MIDlet {
public void startApp() {
Display.init(this);
Form f = new Form("Hello, LWUIT!");
String html="<p><img border=\"1\" align=\"left\" width=\"150\" vspace=\"2\" hspace=\"2\" height=\"159\" src=www.teluguone.com/tmdbuserfiles/ntr-vv-vinayak-pics.jpg\" alt=\"Prithvi II, ballistic missile, DRDO, armed forces,Chandipur, Balasore district, Odisha State\" />The Strategic Forces Command of the armed forces successfully flight-tested the surface-to-surface Prithvi II missile from Chandipur in Balasore </P>";
HTMLComponent com=new HTMLComponent();
com.setPreferredSize(new Dimension(300,300));
com.setHTML(html, null, null, false);
com.setShowImages(true);
//com.setHTML(image, null, null, false);
f.addComponent(com);
f.show();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
If i use the above code,I'm able to display only the text,but i'm not able to display the image,I've tested my app on Nokia SDK 2.O and SDK 3.0.5
can any one help me?
You need to have the full HTML code not just a snippet. The HTML, body etc.
Your src attribute on the img tag is missing the (") character at the beginning. I have not tried but this can be it.
Have you try using
com.setBodyText(html);
instead
com.setHTML(html, null, null, false);
and. I am using HttpRequestHandler implementation from LWUIT example application (you can get the sample apps: LWUITBrowser), instead of DefaultRequestHandler or null.
HttpRequestHandler handler = new HttpRequestHandler();
HTMLComponent com = new HTMLComponent(handler);
Hope it helps.
Related
I've been developing with codenameone for over a year, and I never ran into this problem before, I feel like I'm losing my mind. I just redesigned one part of an app I'm working on, and now the ActionListeners aren't firing. I'm attaching them to a Button and a SpanButton in the code:
ActionListener goToDoc = new ActionListener() {
String mDocId = docId;
#Override
public void actionPerformed(ActionEvent evt) {
mStateMachine.currentExpertId = mDocId;
mStateMachine.showForm("DoctorDetails", null);
}
};
name.addActionListener(goToDoc);
Util.downloadImageToStorage(mStateMachine.URL_PREFIX+"images/doctors/"+(String)value.get("doc_pic"),
"doc_post_pic_"+(String)value.get("doc_id")+".png", new Callback<Image>() {
#Override
public void onSucess(Image img) {
pic.setIcon(img.scaledWidth(mStateMachine.getProportionalWidth(.23)));
StateMachine.applyGreenBorder(pic);
pic.addActionListener(goToDoc);
pic.getParent().revalidate();
}
#Override
public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
System.out.println("Unable to download expert profile picture");
}
});
When I debug the code, the components do show that the ActionListener is attached, but the actionPerformed method is never reached, no matter how many times I click on the buttons. I experience this problem both on the simulator and on an Android device. I have yet to test on an iPhone.
Did you set a parent to be a lead component or focusable?
The reason the click event wasn't firing was because the Components weren't enabled, possibly a bug in the BUI Builder. After checking off the 'Enabled' and 'Focusable' checkboxes in the GUI Builder, and seeing they were unchecked every time I went back to that form, I just used component.setFocusable(true) and component.setEnabled(true) in the code, and it worked fine after that.
I'm building my app using the Nokia SDK 1.0 for the Asha 501
What I want to know, is how to capture events by pressing a TextArea. I'm porting an app from the S40 and using the code below, the TextArea doesn't capture the events
TextArea itemText = new TextArea("Hello I'm a TextArea", 2, 22) {
public void pointerPressed(int x, int y) {
System.out.println("PRESSED");
}
public void pointerReleased(int x, int y) {
System.out.println("HI!");
}
};
itemText.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.out.println("HI");
}
});
itemText.setEditable(false);
itemText.setFocusable(false);
itemText.getStyle().setBorder(null);
itemText.getStyle().setFgColor(Constants.Style.Color.GREY_DATE);
itemText.getStyle().setBgTransparency(Constants.Style.TRANSPARENT);
itemText.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
EDIT
Someone in the Nokia Forum, tells me to delete the itemText.setFocusable(false); line, but it doesn't work.
I've finally found what is the problem, I don't know the reason why but that's it.
Removing this line
itemText.setEditable(false);
the TextArea catches the events.
I don't find the reason that in Nokia SDK 2.0 this code is working and why here is not. Ande there is another fact. I set the TextAreato editable, and it is not editable o_O
I am making an application using LWUIT.
There is a form
There is a list embedded on the form.
The list has 5 elements.
Initially, when I first load the app, if I choose the 1st element, 2nd gets chosen; when I choose the second the 3rd gets chose and and so on (Weird!)
I am not able to click any button on the screen either
next what I do is, shift to a different from using arrow keys (of the keyboard... I am running the app on a simulator btw)
Then I come back to the first form and now everything works as expected(no weird behaviour).
What could be the issue?
I am using Sun Java Micro Edition SDK 3.0 (default touch screen for testing)
My code is:
List dummy = new List();
dummy.addItem("wewerwer");
dummy.addItem("wewerdswer");
dummy.addItem("wewqweerwer");
dummy.addItem("dscxwewerwer");
dummy.addItem("jhgwewerwer");
mainListForm.setLayout(new BorderLayout());
mainListForm.addComponent(BorderLayout.CENTER,dummy);
mainListForm.show();
What could possible be going wrong here?
UPDATE 1
I think there is a bug here. I have attached the complete code below along with the screen shot
import javax.microedition.midlet.*;
import com.sun.lwuit.*;
import com.sun.lwuit.events.*;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
public class Demo extends MIDlet implements ActionListener {
private Form mForm;
List abc;
public void startApp() {
Display.init(this);
try {
Resources r = Resources.open("/Test.res");
UIManager.getInstance().setThemeProps(r.getTheme(
r.getThemeResourceNames()[0])
);
} catch (Exception e){
System.out.println(e.toString());
}
if (mForm == null) {
Button click = new Button("Press me!");
click.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.out.println("I have been pressed");
}
});
abc = new List();
abc.addItem("Str1");
abc.addItem("Str2");
abc.addItem("Str3");
abc.addItem("Str4");
abc.addItem("Str5");
abc.addItem("Str6");
Form f = new Form("Hello, LWUIT!");
abc.addActionListener(this);
f.addComponent(abc);
Command exitCommand = new Command("Exit");
f.addCommand(exitCommand);
f.addCommandListener(this);
f.addComponent(click);
f.show();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void actionPerformed(ActionEvent ae) {
System.out.println(abc.getSelectedIndex());
}
}
So now when I click on 'Str1' of the list Str2 gets selected and so on.
IDE: Netbeans
Emulator: Default Touch screen phone
On the action event set the list to active again after the event by invoking setHandlesInput(true)
OK....so this is how you resolve it.
After the form is displayed remove the list from the form and again add it to the form and then repaint the form.
Earlier Code
1) form.addComponenet(BorderLayout.center,list);
2) form.show();
Word Around for the problem
1)form.addComponenet(BorderLayout.center,list);
2)form.show();
3)form.setScrollable(false);
I know its kind of strange, but this way the list index selection works smooth for touch screen phones.
I am working my way through the NeHe OpenGL examples, using the LWJGL for the OpenGL binding inside an Eclipse RCP application.
My OpenGL graphics are displayed inside the RCP canvas, not in a separate window.
Lesson 07 shows how to use the keyboard. If I try to do a:
Keyboard.create();
I get an error that the (OpenGL) "Display" has not been created.
If I create an OpenGL "Display" with org.lwjgl.opengl.Display.create(), then I get a new Window.
So how do I access the Keyboard without creating a new Window?
You cannot use the Keyboard without a Display, because of how LWJGL works behind the scenes. The best way is to just use AWT events. You can write your own input class, that could go something like this.
public class Input implements KeyListener {
private boolean aDown; //is the A key down?
//Ect, for all needed keys
public void keyPressed(KeyEvent ke) {
switch (ke.getKeyCode()) {
case KeyEvent.VK_A: aDown = true; break;
//and so on for all other needed keys.
}
}
public void keyReleased(KeyEvent ke) {
switch (ke.getKeyCode()) {
case KeyEvent.VK_A: aDown = false; break;
//and so on for all other needed keys.
}
}
public void keyTyped(KeyEvent ke) {} //Do nothing
public void isADown() {return aDown;}
}
I have built a LWUIT UI class which contains the Midlet. I am basically using a theme from this midlet. But I need to jump to another LCDUI form which contains some LCDUI controls and I need to set display that LCDUI form. So is it possible to jump from LWUIT form to LCDUI form and set display the LCDUI form ? If possible how ?
I used following code to show the both LWUIT Form and LCDUI Form. See the sample code.
com.sun.lwuit.Form lwuitForm;
protected void startApp() throws MIDletStateChangeException {
Display.init(this);
lwuitForm = new com.sun.lwuit.Form("LWUIT Form");
lwuitForm.addComponent(new TextField(""));
final MIDlet midlet = this;
final Command abtUsCmd = new Command("Next") {
public void actionPerformed(ActionEvent evt) {
javax.microedition.lcdui.Form frm = new javax.microedition.lcdui.Form("LCDUI Form");
StringItem item = new StringItem("Text", "Sample text");
frm.append(item);
final javax.microedition.lcdui.Command cmd = new javax.microedition.lcdui.Command("Back", javax.microedition.lcdui.Command.BACK, 0);
CommandListener cmdLis = new CommandListener() {
public void commandAction(javax.microedition.lcdui.Command c, Displayable d) {
if(c == cmd) {
Display.init(midlet);
lwuitForm.show(); // Show the LWUIT form again
}
}
};
frm.setCommandListener(cmdLis);
frm.addCommand(cmd);
javax.microedition.lcdui.Display.getDisplay(midlet).setCurrent(frm); // show the LCDUI Form
}
};
lwuitForm.addCommand(abtUsCmd);
lwuitForm.show(); // Show the LWUIT Form
}
This looks tricky, but yeah, we can switch between both.
The trick is when u show the LWUIT form, after it has been successfully painted on the screen, make a call to
javax.microedition.lcdui.Display.getDisplay(midlet).getCurrent();
this gives you the Displayable holding all the LWUIT views, so with this, you can always switch to LCDUI, and back to LWUIT with the LCDUI's
display.setCurrent
Let me know if this works for you.
Thanks