not show the result - blackberry

here is my code and through the source code is not available exception. in the code we require that popup screen that show but the value of the average speed is not show.
class popUpScreen extends PopupScreen
{
private EditField _sp;
// Speed s = new Speed();
//public double _averageSpeed =s._averageSpeed ;
StringBuffer sb = new StringBuffer();
popUpScreen()
{
super(new VerticalFieldManager(),Field.FOCUSABLE);
Speed s = new Speed();
double _averageSpeed =s._averageSpeed ;
_sp = new EditField(" The Average Speed is: ",""+_averageSpeed );
add(_sp);
//Speed._averageSpeed=sb.;
//sb.append("\n_averageSpeed : ");
//sb.append(_averageSpeed);
}
}

you should save that VerticalFieldManager you passed to the super; add your label to the manager.
It is not necessary to override the whole class you could do like this:
DialogFieldManager dfm = new DialogFieldManager();
dfm.add(_sp);
PopupScreen popUpScreen = new BasePopupScreen(dfm, Manager.VERTICAL_SCROLL);

Related

Fixing resizing issue in BorderLayout. Either the buttons move or dont show

I need to make a GUI interface (using BorderLayout) that looks like the image attached.(http://i.imgur.com/wRN4vlH.jpg)
the issue is that I am not allowed to restrict resizing and the buttons can not move to another row. I have the code working to display the proper image I dont know how to make it show the buttons without resizing and without the buttons moving. Any suggestions would be truly helpful
import java.awt.*;
import javax.swing.*;
class MyComponents extends JFrame{
MyComponents (String title){
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
BorderLayout layout = new BorderLayout(2,3);
frame.setLayout(layout);
JPanel northPanel = new JPanel();
//JPanel westPanel = new JPanel();
JPanel centerPanel = new JPanel();
//JPanel eastPanel = new JPanel();
JTextField Text = new JTextField();
northPanel.add(new JLabel("Current Value:"));
northPanel.add(Text);
Text.setPreferredSize(new Dimension(50,24));
centerPanel.add(new JButton("+"));
centerPanel.add(new JButton("-"));
centerPanel.add(new JButton("Reset"));
centerPanel.add(new JButton("Quit"));
frame.add(northPanel, BorderLayout.NORTH);
frame.add(centerPanel, BorderLayout.CENTER);
frame.setVisible(true);
}
}
public class Homework7b {
public static void main (String [] args)
{
MyComponents Homework7b = new MyComponents("Part 02 Using getSource");
}
}

How to create a number of Fields dynamically in Blackberry Java SDK 5.0?

I'm trying to create a couple of BasicEditField objects after i get the number of fields that i want from an ObjectChoiceField.
Problem: the BasicEditField fields that i add to my screen don't refresh unless i do it in the listener from my ObjectChoiceField.
what i want to do :
select the number of BasicEditFields that i want.
refresh the screen so the fields added appear.
PD: if you need more info, just tell me, and sorry about my english. I'm new at developing for the BlackBerry plataform
public final class MyScreen extends MainScreen
{
private int fields_lenght;
public MyScreen()
{
// Set the displayed title of the screen
setTitle("Example");
fields_lenght =0;
final String shortcodes[] = {"1","2","3"};
final ObjectChoiceField dropdownlist=new ObjectChoiceField("Select a number of fields",shortcodes);
this.add(dropdownlist);
dropdownlist.setChangeListener( new FieldChangeListener() {
public void fieldChanged( Field arg0, int arg1 ) {
if(arg1 != PROGRAMMATIC){
fields_lenght= Integer.parseInt(shortcodes[dropdownlist.getSelectedIndex()]);
}
}
} );
// how to refresh the screen with the new fields ???
BasicEditField fields[]=new BasicEditField [fields_lenght] ;
for(int i = 0; i<fields.length;i++){
fields[i]=new BasicEditField("Campo "+i,"");
this.add(fields[i]);
}
}
}
You really should add or delete the fields from within your ObjectChoiceField listener. That's when you know what the proper number of fields is. (Certainly, if you just want to keep your code neat and clean, you could define a separate method, that is called from the choice field listener ... that's not much different).
Try something like this:
public final class MyScreen extends MainScreen {
/** A cached vector of the BasicEditFields, to make deleting easier */
private Vector fields;
public MyScreen() {
super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
setTitle("Example");
final String shortcodes[] = {"1","2","3"};
final ObjectChoiceField dropdownlist = new ObjectChoiceField("Select a number of fields", shortcodes);
add(dropdownlist);
fields = new Vector();
final Screen screen = this;
dropdownlist.setChangeListener( new FieldChangeListener() {
public void fieldChanged( Field field, int context ) {
if (context != PROGRAMMATIC) {
// how many fields has the user chosen?
int fieldsLength = Integer.parseInt(shortcodes[dropdownlist.getSelectedIndex()]);
while (fieldsLength > fields.size()) {
// we need to ADD more fields
Field f = new BasicEditField("Campo " + fields.size(), "");
fields.addElement(f);
screen.add(f);
}
while (fieldsLength < fields.size()) {
// we need to DELETE some fields
Field f = (Field)fields.elementAt(fields.size() - 1);
fields.removeElement(f);
screen.delete(f);
}
}
}
});
}
I defined a new member named fields, which just makes it easier to keep track of the basic edit fields (in case this screen has many other fields, too).
When the choice field listener is called, I determine how many fields the user wants; if they need more, I add them to the screen, and to the fields Vector. If they want fewer, I delete some fields from the end of the Vector, and remove them from the Screen.
Note: there should be no need to call invalidate() here. Calling Screen#add() or Screen#delete() should add/delete the fields and cause repainting.

Wait panel on smartgwt

Do you know any components in smartgwt in order to do some like this?
I´ve done it using several componets, Labels, Camva, Img, Layouts....
Thanks
Well, I have found this option SC.showPrompt and SC.clearPrompt but I think that it´s not possible add images into of panel.
I did this in the past you can have a try
public class Attente extends Window{
private Label message = new Label();
public String getMessage() {
return message.getTitle();
}
public void setMessage(String message) {
this.message.setContents(message) ;
}
private Img image = new Img("64/Wait-icon.png",64,64);
/**
* Instantie un nouveau attente.
*/
public Attente(){
this.setTitle("Opération en cours, veuillez patienter");
this.setShowHeader(true);
this.centerInPage();
this.setAutoCenter(true);
this.setWidth(300);
this.setHeight(140);
this.setShowCloseButton(false);
this.setShowMinimizeButton(false);
this.setShowMaximizeButton(false);
VLayout layout = new VLayout();
HLayout hLayout = new HLayout();
message.setHeight(15);
message.setAlign(Alignment.CENTER);
message.setStyleName("plVersionCatalogue");
hLayout.addMember(new LayoutSpacer());
hLayout.addMember(image);
hLayout.addMember(new LayoutSpacer());
layout.addMember(new LayoutSpacer());
layout.addMember(hLayout);
layout.addMember(new LayoutSpacer());
layout.addMember(message);
this.addItem(layout);
}
}
And in the code I had a singleton instance of this class which I can use like this when I need:
MyContext.getAttente().show();
or
MyContext.getAttente().hide();

EditField And Buttonfield On same Line

I want to add editfield and labelfield on same line . first editfield and then buttonfield . I have tried many times but it didn't work for me .I have added horizontal field manager and also used tables but none of it can help . The issue is it is not showing the buttonfield,i can see only editfield. enter code here
public class MyScreen extends MainScreen {
/**
* Creates a new MyScreen object
*/
public MyScreen()
{
// Set the displayed title of the screen
setTitle("MyTitle");
HorizontalFieldManager m= new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
final GridFieldManager grid = new GridFieldManager(4,4,0);
grid.setColumnPadding(5);
grid.setRowPadding(5);
EditField c= new EditField("","",5,EditField.EDITABLE);
// m.add(c);
Border border=BorderFactory.createRoundedBorder(new XYEdges(10,10,10,10),Border.STYLE_SOLID);
grid.setBorder(border);
ButtonField b= new ButtonField("Select ",ButtonField.CONSUME_CLICK);
//m.add(b);
grid.insert(b,1);
grid.insert(c,0);
//add(m);
add(grid);
}
}
Override getPreferredWidth() of both EditField and ButtonField like this:
public int getPreferredWidth() {
return Display.getWidth()/2;
}
Override sublayout() and layout() method of your EditField & ButtonField than set its width Ex: 100 .. now add both this field in your m.add(); .. its works ..

Blackberry custom slideshow-style BitmapField manager

Right now, I'm trying to figure out how to implement the following:
Suppose I have a custom Manager that has about 10 or so BitmapFields layed out in a horizontal manner (similar to a slideshow contained in a HFM ) . What I want to achieve is to be able to move the image HFM via touchEvent horizontally, where a BitmapField would take focus on the left-hand side of the custom Manager. In other words, will I have to give a value to setHorizontalScroll and if so, is it a matter of just incrementing that value when the user makes a left or right touch event. Also, how can I get the focus of a Field within a given position on the screen (i.e. the left-most Field on the HFM) when the HFM is scrolling sideways via touchEvent?
1 - yes, setHorizontalScroll should work, don't forget to use HORIZONTAL_SCROLL in manager constructor
2 - try to test each Field getContentRect() for EventTouch getX(int) and getY(int)
UPDATE
To simplify global field position calculation use
public XYPoint getGlobalXY(Field field) {
XYPoint result = new XYPoint(field.getLeft(), field.getTop());
if (field.getManager() != null) {
result.translate(getGlobalXY(field.getManager()));
}
return result;
}
Thread safe message dialog:
public void showMessage(final String message) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.inform(message);
}
});
}
Sample code:
class Scr extends MainScreen {
HorizontalFieldManager hfm;
public Scr() {
add(new LabelField("asdfsad"));
hfm = new HorizontalFieldManager(HORIZONTAL_SCROLL);
for (int i = 0; i < 5; i++) {
Bitmap bmp = new Bitmap(100, 100);
Graphics g = Graphics.create(bmp);
g.setFont(g.getFont().derive(100));
String txt = String.valueOf(i);
int x = g.getFont().getAdvance(txt);
g.drawText(txt, x, 0);
BitmapField bf = new BitmapField(bmp);
hfm.add(bf);
}
add(hfm);
}
protected boolean touchEvent(TouchEvent message) {
if (message.getEvent() == TouchEvent.CLICK) {
int x = message.getX(1);
int y = message.getY(1);
XYRect r = hfm.getExtent();
r.setLocation(getGlobalXY(hfm));
if (r.contains(x, y)) {
XYRect rf = hfm.getField(2).getExtent();
rf.setLocation(getGlobalXY(hfm.getField(2)));
if (x < rf.x) {
showMessage("left side");
} else if (x > rf.X2()) {
showMessage("right side");
} else {
showMessage("field");
}
}
}
return super.touchEvent(message);
}
}

Resources