I am use a button and when u click this button a text field is automatic created and button status is automatic disable but if u click on disable button text field is automatic delete and button status is changed to enable.i going through this process.
public class ConfigurationScreen extends MainScreen implements FieldChangeListener{
TextField tf_text;
tf_text = new TextField(TextField.TYPE_PLAIN,img_text[1],img_text[0],TextField.FIELD_HCENTER);
tf_text.setWidth(Display.getWidth()/2+20);
ImageButton btn_en;
btn_en = new ImageButton(imgs_tmintrvl1,"enable",ImageButton.FIELD_HCENTER);
ImageButton btn_dis;
btn_dis=new ImageButton(imgs_tmintrvl1,"Disable",ImageButton.FIELD_HCENTER);
add(btn_en);
btn_en.setChangeListener(this);
public void fieldChanged(Field field, int context) {
if( field==btn_en)
{
delete(btn_en);
insert(btn_dis, 4);
insert(tf_text, 5);
System.out.println(ex);
}else if (field == btn_dis){
delete(btn_dis);
delete(tf_text);
insert(btn_en, 4);
System.out.println("Disable Button="+ex);
}
}
But when i run this code i am getting null pointerr exception please help me where i am making mistake.
package org.maxmobility.wmp.beta;
import com.maxmobility.customfield.H_FieldManager;
import com.maxmobility.customfield.ImageButton;
import com.maxmobility.customfield.LabelField;
import com.maxmobility.customfield.PillButtonField;
import com.maxmobility.customfield.PillButtonSet;
import com.maxmobility.customfield.TextArea;
import com.maxmobility.customfield.TextField;
import com.maxmobility.util.AppColors;
import net.rim.device.api.collection.List;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.FocusChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
public class ConfigurationScreen extends MainScreen implements FieldChangeListener{
TextField tf_phn1;
TextField tf_phn2;
TextField tf_msg;
TextArea ta_msg;
ImageButton btn_add;
ImageButton btn_subtract;
ImageButton btn_en;
ImageButton btn_dis;
ImageButton btn_time1, btn_time2, btn_time3;
LabelField lf_msg;
LabelField lf_time;
LabelField lf1,lf2,lf3,lf4;
private Bitmap[] imgs_addbtn;
private Bitmap[] imgs_subbtn;
private Bitmap[] imgs_tmintrvl1;
private Bitmap[] imgs_tmintrvl2;
private Bitmap[] imgs_tmintrvl3;
private EncodedImage[] img_text;
private H_FieldManager hfm1 , hfm2;
private HorizontalFieldManager hfm3,hfm4;
private VerticalFieldManager vfm;
private boolean show = false;
PillButtonField pbf1;
PillButtonField pbf2;
PillButtonField pbf3;
PillButtonSet pbf_set;
public ConfigurationScreen(){
super(USE_ALL_HEIGHT | USE_ALL_WIDTH);
Background background = BackgroundFactory
.createSolidBackground(AppColors.APP_BG);
this.getMainManager().setBackground(background);
LabelField lf = new LabelField("Configuration Screen", LabelField.FIELD_HCENTER | LabelField.USE_ALL_WIDTH);
lf.setColor(Color.RED);
setTitle(lf);
img_text = new EncodedImage[2];
img_text[0] = EncodedImage.getEncodedImageResource("edittext_selected.png");
img_text[1] = EncodedImage.getEncodedImageResource("edittext.png");
imgs_addbtn = new Bitmap[3];
imgs_addbtn[0] = Bitmap.getBitmapResource("btn_add_sub.png");
imgs_addbtn[1] = Bitmap.getBitmapResource("btn_add_subfocused.png");
imgs_addbtn[2] = Bitmap.getBitmapResource("btn_add_subfocused.png");
imgs_subbtn = new Bitmap[3];
imgs_subbtn[0] = Bitmap.getBitmapResource("btn_add_sub.png");
imgs_subbtn[1] = Bitmap.getBitmapResource("btn_add_subfocused.png");
imgs_subbtn[2] = Bitmap.getBitmapResource("btn_add_subfocused.png");
imgs_tmintrvl1 = new Bitmap[3];
imgs_tmintrvl1[0] = Bitmap.getBitmapResource("default_btn_Unfocused.png");
imgs_tmintrvl1[1] = Bitmap.getBitmapResource("default_btn_focused.png");
imgs_tmintrvl1[2] = Bitmap.getBitmapResource("default_btn_focused.png");
// imgs_tmintrvl2 = new Bitmap[3];
// imgs_tmintrvl2[0] = Bitmap.getBitmapResource("default_btn_Unfocused.png");
// imgs_tmintrvl2[1] = Bitmap.getBitmapResource("default_btn_focused.png");
// imgs_tmintrvl2[2] = Bitmap.getBitmapResource("default_btn_focused.png");
//
// imgs_tmintrvl3 = new Bitmap[3];
// imgs_tmintrvl3[0] = Bitmap.getBitmapResource("default_btn_Unfocused.png");
// imgs_tmintrvl3[1] = Bitmap.getBitmapResource("default_btn_focused.png");
// imgs_tmintrvl3[2] = Bitmap.getBitmapResource("default_btn_focused.png");
//
tf_phn1 = new TextField(TextField.TYPE_PHONE,img_text[1],img_text[0],TextField.FIELD_LEFT);
tf_phn2 = new TextField(TextField.TYPE_PHONE,img_text[1],img_text[0],TextField.FIELD_LEFT);
tf_msg = new TextField(TextField.TYPE_PLAIN,img_text[1],img_text[0],TextField.FIELD_HCENTER);
tf_phn1.setWidth(Display.getWidth()/2+50);
tf_phn2.setWidth(Display.getWidth()/2+50);
tf_msg.setWidth(Display.getWidth()/2+95);
ta_msg = new TextArea(Display.getWidth()/2+130, 100,TextArea.FIELD_HCENTER);
btn_add = new ImageButton(imgs_addbtn," +",ImageButton.FIELD_HCENTER);
btn_subtract = new ImageButton(imgs_subbtn," -",ImageButton.FIELD_RIGHT);
btn_en = new ImageButton(imgs_tmintrvl1,"Enable",ImageButton.FIELD_HCENTER);
btn_dis = new ImageButton(imgs_tmintrvl1,"Disable",ImageButton.FIELD_HCENTER);
// btn_time1 = new ImageButton(imgs_tmintrvl1, "15 min",ImageButton.FIELD_LEFT);
// btn_time2 = new ImageButton(imgs_tmintrvl1, "30 min",ImageButton.FIELD_HCENTER);
// btn_time3 = new ImageButton(imgs_tmintrvl1, "45 min",ImageButton.FIELD_RIGHT);
// btn_time1.set_Margin(35,0, 0,0);
// btn_time2.set_Margin(0,0, 0,0);
// btn_time3.set_Margin(0,0, 0,0);
//btn_add.set_Margin(0,0, 8,8);
LabelField lf1 = new LabelField("",Display.getWidth(),45,LabelField.FIELD_LEFT);
LabelField lf2 = new LabelField("",Display.getWidth(),45,LabelField.FIELD_LEFT);
LabelField lf3 = new LabelField("",Display.getWidth(),45,LabelField.FIELD_LEFT);
LabelField lf4 = new LabelField("",Display.getWidth(),45,LabelField.FIELD_LEFT);
lf_msg = new LabelField("Alert Message",LabelField.FIELD_LEFT);
lf_msg.set_pos(35,0);
lf_time = new LabelField("Select Time Interval",LabelField.FIELD_LEFT);
lf_time.set_pos(35,20);
pbf1 = new PillButtonField("15 min");
pbf2 = new PillButtonField("30 min");
pbf3 = new PillButtonField("45 min");
pbf_set = new PillButtonSet(300,40);
pbf_set.add(pbf1);
pbf_set.add(pbf2);
pbf_set.add(pbf3);
hfm1 = new H_FieldManager(tf_phn1, btn_add, true, H_FieldManager.FIELD_HCENTER);
hfm2 = new H_FieldManager(tf_phn2, btn_subtract, true, H_FieldManager.FIELD_HCENTER);
// hfm3 = new HorizontalFieldManager(HORIZONTAL_SCROLL_MASK);
hfm4 = new HorizontalFieldManager(pbf1.FIELD_HCENTER);
// hfm3.add(btn_time1);
// hfm3.add(btn_time2);
// hfm3.add(btn_time3);
hfm4.add(pbf_set);
vfm = new VerticalFieldManager();
add(lf1);
add(hfm1);
add(lf_msg);
//add(tf_msg);
add(ta_msg);
add(btn_en);
add(lf_time);
//add(hfm3);
add(hfm4);
System.out.println(" insert label");
btn_add.setChangeListener(this);
btn_subtract.setChangeListener(this);
btn_en.setChangeListener(this);
btn_dis.setChangeListener(this);
}
public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
if(field == btn_add){
insert(hfm2, 2);
}else if(field == btn_subtract){
delete(hfm2);
//}
}else if(field == btn_en){
replace(btn_en, btn_dis);
insert(tf_msg, 5);
}else if(field == btn_dis){
replace(btn_dis, btn_en);
delete(tf_msg);
}
}
}
I hope your Problem will solve in this code.
Related
I have a problem using the JavaFX WebView. What I want to achieve is pre-fetching a web page in the background and visualiszing it only when the page is totally loaded.
I have made a simple exmaple program to reproduce the problem. After the page is loaded I enable a button. A Click on this button then makes the WebView visible.
The problem I have is, that if I click on the button when it gets enabled, the web page is not visible directly. Instead the following happens: At first there is a totally white panel and then after a short time the web page is visible. I don't understand why the page is not visible directly. How can I achieve it, that the web page is directly visible?
The following link points to an animated gif which shows the behaviour:
http://tinypic.com/view.php?pic=oh66bl&s=5#.Ujmv1RddWKk
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class WebViewTest extends javax.swing.JPanel {
private static JFXPanel browserFxPanel;
private WebView webView;
private WebEngine eng;
/**
* Creates new form WebViewTest
*/
public WebViewTest() {
initComponents();
Platform.setImplicitExit(false);
browserFxPanel = new JFXPanel();
Platform.runLater(new Runnable() {
public void run() {
webView = createBrowser();
Scene scene = new Scene(webView);
scene.setFill(null);
browserFxPanel.setScene(
scene);
}
});
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
* content of this method is always regenerated by the Form Editor.
*/
#SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
pnlMain = new javax.swing.JPanel();
showWebpageButton = new javax.swing.JButton();
setLayout(new java.awt.GridBagLayout());
pnlMain.setLayout(new java.awt.BorderLayout());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
add(pnlMain, gridBagConstraints);
showWebpageButton.setText("show web page");
showWebpageButton.setEnabled(false);
showWebpageButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
showWebpageButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
add(showWebpageButton, gridBagConstraints);
}// </editor-fold>
private void showWebpageButtonActionPerformed(java.awt.event.ActionEvent evt) {
pnlMain.removeAll();
pnlMain.add(browserFxPanel, BorderLayout.CENTER);
WebViewTest.this.invalidate();
WebViewTest.this.revalidate();
}
// Variables declaration - do not modify
private javax.swing.JPanel pnlMain;
private javax.swing.JButton showWebpageButton;
// End of variables declaration
private WebView createBrowser() {
Double widthDouble = pnlMain.getSize().getWidth();
Double heightDouble = pnlMain.getSize().getHeight();
final WebView view = new WebView();
view.setMinSize(widthDouble, heightDouble);
view.setPrefSize(widthDouble, heightDouble);
eng = view.getEngine();
eng.load("http://todomvc.com/architecture-examples/angularjs/#/");
eng.getLoadWorker().workDoneProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
final double workDone = eng.getLoadWorker().getWorkDone();
final double totalWork = eng.getLoadWorker().getTotalWork();
if (workDone == totalWork) {
showWebpageButton.setEnabled(true);
}
}
});
return view;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final JFrame f = new JFrame("Navigator Dummy");
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setSize(new Dimension(1024, 800));
final WebViewTest navDummy = new WebViewTest();
f.getContentPane().add(navDummy);
f.setVisible(true);
}
});
}
}
JFX needs a "stage" to show up its face. Modify your codes as following and it will work perfectly
/**
* Creates new form WebViewTest
*/
private Stage stage; // insert this line
public WebViewTest() {
initComponents();
Platform.setImplicitExit(false);
browserFxPanel = new JFXPanel();
Platform.runLater(new Runnable() {
public void run() {
webView = createBrowser();
Scene scene = new Scene(webView);
scene.setFill(null);
stage = new Stage(); // <<<
stage.setScene(scene); // <<<
browserFxPanel.setScene(scene);
}
});
}
...
private void showWebpageButtonActionPerformed(java.awt.event.ActionEvent evt) {
pnlMain.removeAll();
pnlMain.add(browserFxPanel, BorderLayout.CENTER);
WebViewTest.this.invalidate();
WebViewTest.this.revalidate();
stage.show(); // <<< afer click Button
}
Horizontally, I want to display two custom buttons, and between them display a label field in a BlackBerry app. I looked at "BlackBerry HorizontalFieldManager alignment", but did not achieve any success.
Here is a screenshot that I want to create in BlackBerry.
Here is the code that I created for this screen:
package mypackage;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
/**
* A class extending the MainScreen class, which provides default standard * behavior for BlackBerry GUI applications. */ public final class HelloBlackBerryScreen extends MainScreen { BasicEditField username; PasswordEditField password;
/**
* Creates a new MyScreen object
*/ public HelloBlackBerryScreen() { // Set the linear background. this.getMainManager().setBackground(BackgroundFactory.createLinearGradientBackground(0x91e7ff,0x0099CCFF,0x00336699,0x91e7ff));
// SET HEADER OF SCREEN VerticalFieldManager vfm = new
VerticalFieldManager(Manager.USE_ALL_WIDTH); BitmapField header = new
BitmapField(Bitmap.getBitmapResource("header.png"),FIELD_HCENTER);
HorizontalFieldManager hfm = new
HorizontalFieldManager(Field.FIELD_VCENTER |Manager.USE_ALL_WIDTH);
setTitle(header);
hfm.add(vfm); add(hfm);
//SET Container
LabelField usernameTxt = new LabelField("Username:",LabelField.FIELD_TOP);
usernameTxt.setFont(Font.getDefault().derive(Font.PLAIN, 30));
usernameTxt.setMargin(20, 0, 0, 160);
LabelField passwordTxt = new LabelField("Password :",LabelField.FIELD_BOTTOM);
passwordTxt.setFont(Font.getDefault().derive(Font.PLAIN, 30));
passwordTxt.setMargin(10, 0, 0, 160);
username = new BasicEditField(BasicEditField.FIELD_BOTTOM);username.setMargin(10, 110, 0, 160); //username.setMaxSize(getHeight());
username.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3,3, 3), 0x999999, Border.STYLE_FILLED));
username.setBackground(BackgroundFactory.createSolidBackground(0xe0e0e0));
password = new PasswordEditField(); password.setMargin(10, 110, 0,160); password.setBorder(BorderFactory.createRoundedBorder(new
XYEdges(3, 3, 3, 3), 0x999999, Border.STYLE_FILLED));
password.setBackground(BackgroundFactory.createSolidBackground(0xe0e0e0));
ButtonField loginBtn = new ButtonField(" Log-In ", ButtonField.CONSUME_CLICK); loginBtn.setMargin(30, 0, 0,240);
ButtonField recoveryBtn = new ButtonField("Forget Password", ButtonField.CONSUME_CLICK); recoveryBtn.setMargin(10, 0, 0,200);
add(usernameTxt); add(username); add(passwordTxt); add(password);
add(loginBtn); add(recoveryBtn);
loginBtn.setChangeListener(btnlistener); } FieldChangeListener
btnlistener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
//Open a new screen
String uname = username.getText();
String pwd =password.getText();
//If there is no input if (uname.length() == 0 || pwd.length()==0)
Dialog.alert("One of the textfield is empty!");
else if
(uname.equals("user") && pwd.equals("admin"))
UiApplication.getUiApplication().pushScreen(newwelcome());
//Open a
new Screen else
Dialog.alert("Username or password not found!");
}
};
FieldChangeListener btnlistener2 = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
screen if variables are not empty
[1]: http://i.stack.imgur.com/PlDRu.png
For that you need to use custom manager like this.
Main Field Manager for this screen
VerticalFieldManager vfm = new VerticalFieldManager(VerticalFieldManager.USE_ALL_HEIGHT
|VerticalFieldManager.USE_ALL_WIDTH|VerticalFieldManager.FIELD_VCENTER|VerticalFieldManager.FIELD_HCENTER){
//Override the paint method to draw the background image.
public void paint(Graphics graphics){
//Draw the background image and then call super.paint
//to paint the rest of the screen.
graphics.setBackgroundColor(Color.DEEPSKYBLUE);
graphics.clear();
super.paint(graphics);
}
};
add(vfm);
and add custom manger like this
//Placing back,home icon and title at particular positions
HorizontalFieldManager customManager = new HorizontalFieldManager(HorizontalFieldManager
.USE_ALL_WIDTH)
{
//Applying background color for that Manager
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(Color.DEEPSKYBLUE);//blue
graphics.clear();
super.paint(graphics);
}
//Placing the Fields
protected void sublayout(int width, int height) {
setPositionChild(
getField(0),
0,
0);
layoutChild(
getField(0),
getField(0).getPreferredWidth(),
getField(0).getPreferredHeight());
setPositionChild(
getField(1),
Display.getWidth()/2 - getField(1).getPreferredWidth()/2,
0);
layoutChild(
getField(1),
getField(1).getPreferredWidth(),
getField(1).getPreferredHeight());
setPositionChild(
getField(2),
Display.getWidth() - getField(2).getPreferredWidth(),
0);
layoutChild(
getField(2),
getField(2).getPreferredWidth(),
getField(2).getPreferredHeight());
setExtent(width, 50);
}
};
//To display Back icon
final Bitmap bmp1 = Bitmap.getBitmapResource("back.png");
BitmapField bmpfield1 = new BitmapField(bmp1,BitmapField.FOCUSABLE|BitmapField.FIELD_LEFT);
//To display Home icon
final Bitmap bmp2 = Bitmap.getBitmapResource("home.png");
BitmapField bmpfield2 = new BitmapField(bmp2,BitmapField.FOCUSABLE |BitmapField.FIELD_RIGHT);
//To display Title
LabelField lbl = new LabelField("Login",LabelField.FIELD_VCENTER);
//To Add Fields
customManager.add(bmpfield1);
customManager.add(lbl);
customManager.add(bmpfield2);
vfm. add(customManager);
If you want to fix your header at the top as I understood from your comments what you can do is create a HorizontalFieldManager and add your back, title and home button to it then you can set that horizontal field manager in your title using setTitle(hfm). Similarly if you also need to fix your footer you may use setStatus(hfm).
ObjectChoiceField not working because the below code:
protected boolean navigationUnclick(int status, int time) {
return true;
}
I have added this code to remove the menus on touchevent. Means I have made a custom bottom tab and adding and deleting verticalfields on screen. When i touch any HorizontalField it shows menu that's why i added the above code.
This is my code contains ObjectChoiceField added in horizontalfield:
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.ObjectChoiceField;
import net.rim.device.api.ui.container.VerticalFieldManager;
import com.ec.pleasewaitpopup.PleaseWaitPopupScreen;
import com.np.naijapings.ApplicationFont;
import com.np.naijapings.Constant;
import com.np.naijapings.TabControlScreen;
import com.np.naijapings.intermediateclasses.GetUserListIntermediator;
import com.tv.servercommunication.WebServiceDetails;
public class FindUsersScreen extends VerticalFieldManager implements FieldChangeListener{
private VerticalFieldManager _mainVfm;
private VerticalFieldManager _contentVfm;
private BitmapField _headerBmp;
private EncodedImage _bitmap;
private LabelField _gender;
private LabelField _age;
private LabelField _religion;
private ObjectChoiceField _genderChoiceField;
private ObjectChoiceField _ageChoiceField;
private ObjectChoiceField _religionChoiceField;
private ButtonField _findUser;
private static String[] _genderChoices={"Both gender","Male","Female"};
private static String[] _ageChoices={"Any age","18-25","26-30","31-35","36-45","46-50"};
private String[] _religionChoices={"Any religion","Hindu","Muslim"};
public FindUsersScreen(){
//HEADER IMG
_bitmap = EncodedImage.
getEncodedImageResource("find-user_header.png");
_headerBmp = new BitmapField(Constant.sizePic(_bitmap, _bitmap.getHeight(), _bitmap.getWidth()));
//MAIN VFM
_mainVfm=new VerticalFieldManager();
//CONTENT VFM
final Bitmap tabBackGroundImage = Bitmap
.getBitmapResource("finduserscr_bg.png");
_contentVfm=new VerticalFieldManager(){
protected void paint(Graphics graphics) {
int y = FindUsersScreen.this.getManager().getVerticalScroll();
graphics.drawBitmap( 0, y, tabBackGroundImage.getWidth(), tabBackGroundImage.getHeight(), tabBackGroundImage, 0, 0 );
super.paint( graphics );
}
};
//CREATE WIDGETS
_gender=new LabelField("Gender");
_genderChoiceField=new ObjectChoiceField("Gender", _genderChoices,0){
protected boolean touchEvent(TouchEvent message) {
return super.touchEvent(message);
}
};
_age=new LabelField("Age");
_ageChoiceField=new ObjectChoiceField("Age", _ageChoices,0);
_religion=new LabelField("Religion");
_religionChoiceField=new ObjectChoiceField("Religion", _religionChoices,0);
_findUser=new ButtonField(" Find Users ",ButtonField.CONSUME_CLICK);
_findUser.setChangeListener(this);
//SET FONT TYPE
/*_gender.setFont(ApplicationFont.labelFont_16);
_genderChoiceField.setFont(ApplicationFont.labelFont_16);
_ageChoiceField.setFont(ApplicationFont.labelFont_16);
_age.setFont(ApplicationFont.labelFont_20);
_religionChoiceField.setFont(ApplicationFont.labelFont_20);
_religion.setFont(ApplicationFont.labelFont_20);
*/
//SET MARGIN
/*_gender.setMargin(5,20,5,20);
_age.setMargin(5,20,5,20);
_religion.setMargin(5,20,5,20);
*/
_contentVfm.setMargin(15,30,15,0);
_genderChoiceField.setMargin(10,5,5,5);
_religionChoiceField.setMargin(10,5,5,5);
_ageChoiceField.setMargin(10,5,5,5);
_findUser.setMargin(10,80,20,80);
_contentVfm.setMargin(30,10,30,10);
//ADD FIELDS TO CONTENT VFM
//_contentVfm.add(_gender);
_contentVfm.add(_genderChoiceField);
//_contentVfm.add(_age);
_contentVfm.add(_ageChoiceField);
//_contentVfm.add(_religion);
_contentVfm.add(_religionChoiceField);
_contentVfm.add(_findUser);
_mainVfm.add(_headerBmp);
_mainVfm.add(_contentVfm);
add(_mainVfm);
}
public void fieldChanged(Field field, int context) {
if(field==_findUser){
Object obAgeRange = _ageChoiceField.getChoice(_ageChoiceField.getSelectedIndex());
String ageRange = obAgeRange.toString();
Object obgender = _genderChoiceField.getChoice(_genderChoiceField.getSelectedIndex());
String gender = obgender.toString();
Object obReligion = _religionChoiceField.getChoice(_religionChoiceField.getSelectedIndex());
String religion = obReligion.toString();
GetUserListIntermediator getUserListIntermediator=new GetUserListIntermediator(ageRange,gender,religion);
PleaseWaitPopupScreen.showScreenAndWait(getUserListIntermediator, Constant.PLEASE_WAIT_TEXT);
}
}
}
could anyone answer me how to solve this problem.
You don't get drop-down list because the field code does not process unclick event. You have intercepted and consumed this event (via return true;) before your field can process it.
Try this code for your event handler.
protected boolean navigationUnclick(int status, int time) {
super.navigationUnclick(status, time);
return true;
}
code is working properly.but i am not able to display the final data which is from "setDataURL("ds/test_data/employees.data.xml".so tel me where shud i create dis file and how to create.
package com.smartgwt.sample.showcase.client;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceFloatField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.grid.CellFormatter;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeGridField;
import com.google.gwt.i18n.client.NumberFormat;
import com.smartgwt.sample.showcase.shared.FieldVerifier;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class Showcase implements EntryPoint {
/**
* The message displayed to the user when the server cannot be reached or
* returns an error.
*/
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";
/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
private final GreetingServiceAsync greetingService = GWT
.create(GreetingService.class);
/**
* This is the entry point method.
*/
public void onModuleLoad() {
RootPanel.get().add(getViewPanel());
}
public Canvas getViewPanel() {
EmployeeXmlDS employeesDS = EmployeeXmlDS.getInstance();
TreeGrid treeGrid = new TreeGrid();
treeGrid.setCanEdit(true);
treeGrid.setLoadDataOnDemand(false);
treeGrid.setWidth(500);
treeGrid.setHeight(400);
treeGrid.setDataSource(employeesDS);
treeGrid.setNodeIcon("icons/16/person.png");
treeGrid.setFolderIcon("icons/16/person.png");
treeGrid.setShowOpenIcons(false);
treeGrid.setShowDropIcons(false);
treeGrid.setClosedIconSuffix("");
treeGrid.setAutoFetchData(true);
TreeGridField nameField = new TreeGridField("Name");
TreeGridField jobField = new TreeGridField("Job");
TreeGridField salaryField = new TreeGridField("Salary");
salaryField.setCellFormatter(new CellFormatter() {
public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
if (value != null) {
NumberFormat nf = NumberFormat.getFormat("#,##0");
try {
return "$" + nf.format(((Number) value).longValue());
} catch (Exception e) {
return value.toString();
}
} else {
return null;
}
}
});
treeGrid.setFields(nameField, jobField, salaryField);
return treeGrid;
}
}
class EmployeeXmlDS extends DataSource {
private static EmployeeXmlDS instance = null;
public static EmployeeXmlDS getInstance() {
if (instance == null) {
instance = new EmployeeXmlDS("employeesDS");
}
return instance;
}
public EmployeeXmlDS(String id) {
setID(id);
setTitleField("Name");
setRecordXPath("/List/employee");
DataSourceTextField nameField = new DataSourceTextField("Name", "Name", 128);
DataSourceIntegerField employeeIdField = new DataSourceIntegerField("EmployeeId", "Employee ID");
employeeIdField.setPrimaryKey(true);
employeeIdField.setRequired(true);
DataSourceIntegerField reportsToField = new DataSourceIntegerField("ReportsTo", "Manager");
reportsToField.setRequired(true);
reportsToField.setForeignKey(id + ".EmployeeId");
reportsToField.setRootValue("1");
DataSourceTextField jobField = new DataSourceTextField("Job", "Title", 128);
DataSourceTextField emailField = new DataSourceTextField("Email", "Email", 128);
DataSourceTextField statusField = new DataSourceTextField("EmployeeStatus", "Status", 40);
DataSourceFloatField salaryField = new DataSourceFloatField("Salary", "Salary");
DataSourceTextField orgField = new DataSourceTextField("OrgUnit", "Org Unit", 128);
DataSourceTextField genderField = new DataSourceTextField("Gender", "Gender", 7);
genderField.setValueMap("male", "female");
DataSourceTextField maritalStatusField = new DataSourceTextField("MaritalStatus",
"Marital Status", 10);
setFields(nameField, employeeIdField, reportsToField, jobField, emailField, statusField,
salaryField, orgField, genderField, maritalStatusField);
setDataURL("ds/test_data/employees.data.xml");
setClientOnly(true);
}
}
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
NoClassDefFoundError importing a library project
My blackberry application suddenly stopped working. My simulator or/and my application does not load up, I get the " Uncaught Exception: java.lang.NoClassDefFoundError ". I have not made any changes to my code since I last tested it. What has gone wrong?
package mypackage;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.Vector;
import javacard.framework.UserException;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.location.Location;
import javax.microedition.location.LocationProvider;
import org.kobjects.base64.Base64;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
import org.xmlpull.v1.XmlPullParserException;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.component.pane.TitleView;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.image.Image;
public class LoginTest extends UiApplication
{
public static void main(String[] args)
{
//Create a new instance of the app
//and start the app on the event thread.
LoginTest app = new LoginTest();
app.enterEventDispatcher();
}
public LoginTest()
{
//Display a new screen.
pushScreen(new LoginTestScreen());
}
}
//Create a new screen that extends MainScreen and provides
//behaviour similar to that of other apps.
final class LoginTestScreen extends MainScreen
{
//declare variables for later use
private InfoScreen _infoScreen;
private ObjectChoiceField choiceField;
private int select;
BasicEditField username;
PasswordEditField passwd;
CheckboxField checkBox1;
ButtonField loginBtn;
public LoginTestScreen()
{
//Invoke the MainScreen constructor.
super();
//Add a screen title.
setTitle("Track24ELMS");
LabelField login = new LabelField("ELMS Login", LabelField.FIELD_HCENTER);
login.setFont(Font.getDefault().derive(Font.BOLD, 30));
login.setMargin(10, 0, 20, 0); //To leave some space from top and bottom
HorizontalFieldManager user = new HorizontalFieldManager();
user.setMargin(0, 0, 10, 0);
HorizontalFieldManager pass = new HorizontalFieldManager();
pass.setMargin(0, 0, 20, 0);
HorizontalFieldManager checkbox = new HorizontalFieldManager();
checkbox.setMargin(0, 0, 30, 0);
HorizontalFieldManager btns = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
LabelField usernameTxt = new LabelField("Username :");
LabelField passwordTxt = new LabelField("Password :");
username = new BasicEditField();
passwd = new PasswordEditField();
loginBtn = new ButtonField("Login", ButtonField.CONSUME_CLICK);
loginBtn.setChangeListener(new LoginButtonListener());
checkBox1 = new CheckboxField("Remember me",false);
user.add(usernameTxt);
user.add(username);
pass.add(passwordTxt);
pass.add(passwd);
btns.add(loginBtn);
add(login);
add(user);
add(pass);
add(checkBox1);
add(btns);
}
private class LoginButtonListener implements FieldChangeListener {
public void fieldChanged(Field field, int context) {
//Open a new screen
String uname = username.getText();
String pwd = passwd.getText();
String sep = "</>";
//If there is no input
if (uname.length() == 0 || pwd.length()==0)
Dialog.alert("One of the textfield is empty!");
else
{
String URL = "http://xxx.xxx.com/xxx/xxx.asmx";
String METHOD_NAME = "ValidateCredentials";
String NAMESPACE = "http://tempuri.org/";
String SOAP_ACTION = NAMESPACE+METHOD_NAME;
//final String URL = "http://prerel.track24elms.com/Android/T24AndroidLogin.asmx/ValidateCredentials";
SoapObject resultRequestSOAP = null;
HttpConnection httpConn = null;
HttpTransport httpt;
System.out.println("The username" + uname + "password" + pwd );
SoapPrimitive response = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//String usernamecode = Base64.encode(uname.getBytes());
//String pwdEncodeString = Base64.encode(pwd.getBytes());
request.addProperty("username", uname);
request.addProperty("password", pwd);
System.out.println("The request is=======" + request.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//envelope.bodyOut = request;
envelope.dotNet = true;
//envelope.encodingStyle = SoapSerializationEnvelope.XSD;
envelope.setOutputSoapObject(request);
System.out.println("The envelope has the value++++"+ envelope.toString());
/* URL+ Here you can add paramter so that you can run on device,simulator etc. this will work only for wifi */
httpt = new HttpTransport(URL+ ";deviceside=true;ConnectionUID=S TCP");
//httpt.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
httpt.debug = true;
try
{
System.out.println("SOAP_ACTION == " + SOAP_ACTION);
httpt.call(SOAP_ACTION, envelope);
response = (SoapPrimitive) envelope.getResponse();
String result = response.toString();
System.out.println("response == " + result);
resultRequestSOAP = (SoapObject) envelope.bodyIn;
System.out.println("result == " + resultRequestSOAP);
String[] listResult = split(result, sep);
}
catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("The exception is IO==" + e.getMessage());
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
System.out.println("The exception xml parser example==="
+ e.getMessage());
}
System.out.println( resultRequestSOAP);
//UiApplication.getUiApplication().pushScreen(new InfoScreen()); //Open a new Screen
}
}
};
private String[] split(String original, String separator) {
Vector nodes = new Vector();
int index = original.indexOf(separator);
while (index >= 0) {
nodes.addElement(original.substring(0, index));
original = original.substring(index + separator.length());
index = original.indexOf(separator);
}
nodes.addElement(original);
String[] result = new String[nodes.size()];
if (nodes.size() > 0) {
for (int loop = 0; loop < nodes.size(); loop++) {
result[loop] = (String) nodes.elementAt(loop);
System.out.println(result[loop]);
}
}
return result;
}
//To display a dialog box when a BlackBerry device user
//closes the app, override the onClose() method.
public boolean onClose()
{
Dialog.alert("Goodbye!");
System.exit(0);
return true;
}
//Create a menu item for BlackBerry device users to click to see more
//information about the city they select.
private MenuItem _viewItem = new MenuItem("More Info", 110, 10)
{
public void run()
{
//Store the index of the city the BlackBerry device user selects
select = choiceField.getSelectedIndex();
//Display a new screen with information about the
//city the BlackBerry device user selects
_infoScreen = new InfoScreen();
UiApplication.getUiApplication().pushScreen(_infoScreen);
}
};
//Create a menu item for BlackBerry device users to click to close
//the app.
private MenuItem _closeItem = new MenuItem("Close", 200000, 10)
{
public void run()
{
onClose();
}
};
//Create an inner class for a new screen that displays
//information about the city a BlackBerry device user selects.
private class InfoScreen extends MainScreen
{
String latitude, logitude, altitude;
public InfoScreen()
{
super();
setTitle("Itinerary");
LabelField login = new LabelField("Employee Itinerary", LabelField.FIELD_HCENTER);
HorizontalFieldManager userDetails = new HorizontalFieldManager();
userDetails.setMargin(0, 0, 10, 0);
HorizontalFieldManager statusBox = new HorizontalFieldManager();
statusBox.setMargin(0, 0, 20, 0);
HorizontalFieldManager locationDetails = new HorizontalFieldManager();
locationDetails.setMargin(0, 0, 30, 0);
HorizontalFieldManager imgBtn = new HorizontalFieldManager();
imgBtn.setMargin(0, 0, 40, 0);
//BitmapField userImg = new BitmapField(Bitmap.getBitmapResource("img1.jpg"));
LabelField userFetched = new LabelField("Sarah Farukh");
LabelField lastStatus = new LabelField("I am OK");
EditField statusMsg = new EditField("Status Message", "Update status here");
EditField lat = new EditField("Latitude", "latitude");
EditField longi = new EditField("Longitude", "logitude");
EditField alti = new EditField("Attitude", "altitude");
//BitmapField btnOK = new BitmapField(Bitmap.getBitmapResource("ok.png"),Field.FIELD_BOTTOM);
//BitmapField btnNO = new BitmapField(Bitmap.getBitmapResource("no.png"),Field.FIELD_BOTTOM);
//BitmapField btnHN = new BitmapField(Bitmap.getBitmapResource("hn.png"),Field.FIELD_BOTTOM);
//userDetails.add(userImg);
userDetails.add(userFetched);
userDetails.add(lastStatus);
statusBox.add(userFetched);
locationDetails.add(lat);
locationDetails.add(longi);
locationDetails.add(alti);
//imgBtn.add(btnOK);
//imgBtn.add(btnNO);
//imgBtn.add(btnHN);
add(login);
add(userDetails);
add(statusBox);
add(locationDetails);
add(imgBtn);
}
}
}
It is possible that you are accessing a class in a separate library. You have set up your project so that the class is found at build time.
If that library was not deployed to the device for some reason (forgot to? error when deploying?), then your class will not be found at runtime.
Either make sure to deploy this library properly onto the device (by uploading the correct compiled COD file).
Or include the library into your project by setting up your build path correctly.
(my answer based on this one: NoClassDefFoundError importing a library project)