J2ME怎么让TextField全屏像TextBox显示?
代码如下,我要让TextField全屏,不是用TextBox!!!importjavax.microedition.lcdui.Display;importjavax.m...
代码如下,我要让TextField全屏,不是用TextBox!!!
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class a extends MIDlet {
private Display display;
private Form messForm=new Form("请输入短信");
private TextField mtf=new TextField("","",255,TextField.ANY);
public a() {
display=Display.getDisplay(this);
display.setCurrent(messForm);
messForm.append(mtf);
mtf.setLayout(TextField.LAYOUT_EXPAND);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
}
mtf.setLayout(TextField.LAYOUT_EXPAND);
这段不是设置TextField的样式吗,我知道还有个方法叫setPreferredSize(int width, int height) 的方法,用后一个方法我试过了,可以调整TextField的大小,但是我就是不死心啊,开发的API上明明写着Item类里有个叫setLayout(int layout) 的方法啊,TextField是Item类的子类啊,为什么调用没有反应啊,救命啊~~~~谁能告诉我setLayout(int layout)怎么用啊? 展开
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class a extends MIDlet {
private Display display;
private Form messForm=new Form("请输入短信");
private TextField mtf=new TextField("","",255,TextField.ANY);
public a() {
display=Display.getDisplay(this);
display.setCurrent(messForm);
messForm.append(mtf);
mtf.setLayout(TextField.LAYOUT_EXPAND);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
}
mtf.setLayout(TextField.LAYOUT_EXPAND);
这段不是设置TextField的样式吗,我知道还有个方法叫setPreferredSize(int width, int height) 的方法,用后一个方法我试过了,可以调整TextField的大小,但是我就是不死心啊,开发的API上明明写着Item类里有个叫setLayout(int layout) 的方法啊,TextField是Item类的子类啊,为什么调用没有反应啊,救命啊~~~~谁能告诉我setLayout(int layout)怎么用啊? 展开
2个回答
展开全部
看一下下面的TextBox源码,你可能就知道了它是SUN公司开发的
package javax.microedition.lcdui;
// Referenced classes of package javax.microedition.lcdui:
// Screen, Form, TextField, Display,
// Ticker, Item, Graphics
public class TextBox extends Screen
{
private Form form;
private TextField textField;
public TextBox(String title, String text, int maxSize, int constraints)
{
super(title);
synchronized (Display.LCDUILock)
{
form = new Form(title);
form.paintDelegate = this;
if ((0x20000 & constraints) == 0x20000)
form.paintBorder = 2;
else
form.paintBorder = 1;
textField = new TextField(null, text, maxSize, constraints);
textField.setBorder(false);
form.append(textField);
}
}
public String getString()
{
return textField.getString();
}
public void setString(String text)
{
textField.setString(text);
}
public int getChars(char data[])
{
return textField.getChars(data);
}
public void setChars(char data[], int offset, int length)
{
textField.setChars(data, offset, length);
}
public void insert(String src, int position)
{
textField.insert(src, position);
}
public void insert(char data[], int offset, int length, int position)
{
textField.insert(data, offset, length, position);
}
public void delete(int offset, int length)
{
textField.delete(offset, length);
}
public int getMaxSize()
{
return textField.getMaxSize();
}
public int setMaxSize(int maxSize)
{
return textField.setMaxSize(maxSize);
}
public int size()
{
return textField.size();
}
public int getCaretPosition()
{
return textField.getCaretPosition();
}
public void setConstraints(int constraints)
{
textField.setConstraints(constraints);
}
public int getConstraints()
{
return textField.getConstraints();
}
public void setInitialInputMode(String characterSubset)
{
textField.setInitialInputMode(characterSubset);
}
public void setTitle(String s)
{
super.setTitle(s);
form.setTitle(s);
}
public void setTicker(Ticker ticker)
{
super.setTicker(ticker);
form.setTicker(ticker);
}
void commitPendingInteraction()
{
textField.commitPendingInteraction();
}
void callShowNotify(Display d)
{
super.callShowNotify(d);
form.callShowNotify(d);
}
void callHideNotify(Display d)
{
super.callHideNotify(d);
form.callHideNotify(d);
}
void callInvalidate(Item src)
{
form.callInvalidate(src);
}
void callItemStateChanged(Item src)
{
form.callItemStateChanged(src);
}
void callKeyPressed(int keyCode)
{
form.callKeyPressed(keyCode);
}
void callKeyReleased(int keyCode)
{
form.callKeyReleased(keyCode);
}
void callKeyRepeated(int keyCode)
{
form.callKeyRepeated(keyCode);
}
void callKeyTyped(char keyCode)
{
form.callKeyTyped(keyCode);
}
void callPaint(Graphics g, Object target)
{
form.callPaint(g, target);
}
}
package javax.microedition.lcdui;
// Referenced classes of package javax.microedition.lcdui:
// Screen, Form, TextField, Display,
// Ticker, Item, Graphics
public class TextBox extends Screen
{
private Form form;
private TextField textField;
public TextBox(String title, String text, int maxSize, int constraints)
{
super(title);
synchronized (Display.LCDUILock)
{
form = new Form(title);
form.paintDelegate = this;
if ((0x20000 & constraints) == 0x20000)
form.paintBorder = 2;
else
form.paintBorder = 1;
textField = new TextField(null, text, maxSize, constraints);
textField.setBorder(false);
form.append(textField);
}
}
public String getString()
{
return textField.getString();
}
public void setString(String text)
{
textField.setString(text);
}
public int getChars(char data[])
{
return textField.getChars(data);
}
public void setChars(char data[], int offset, int length)
{
textField.setChars(data, offset, length);
}
public void insert(String src, int position)
{
textField.insert(src, position);
}
public void insert(char data[], int offset, int length, int position)
{
textField.insert(data, offset, length, position);
}
public void delete(int offset, int length)
{
textField.delete(offset, length);
}
public int getMaxSize()
{
return textField.getMaxSize();
}
public int setMaxSize(int maxSize)
{
return textField.setMaxSize(maxSize);
}
public int size()
{
return textField.size();
}
public int getCaretPosition()
{
return textField.getCaretPosition();
}
public void setConstraints(int constraints)
{
textField.setConstraints(constraints);
}
public int getConstraints()
{
return textField.getConstraints();
}
public void setInitialInputMode(String characterSubset)
{
textField.setInitialInputMode(characterSubset);
}
public void setTitle(String s)
{
super.setTitle(s);
form.setTitle(s);
}
public void setTicker(Ticker ticker)
{
super.setTicker(ticker);
form.setTicker(ticker);
}
void commitPendingInteraction()
{
textField.commitPendingInteraction();
}
void callShowNotify(Display d)
{
super.callShowNotify(d);
form.callShowNotify(d);
}
void callHideNotify(Display d)
{
super.callHideNotify(d);
form.callHideNotify(d);
}
void callInvalidate(Item src)
{
form.callInvalidate(src);
}
void callItemStateChanged(Item src)
{
form.callItemStateChanged(src);
}
void callKeyPressed(int keyCode)
{
form.callKeyPressed(keyCode);
}
void callKeyReleased(int keyCode)
{
form.callKeyReleased(keyCode);
}
void callKeyRepeated(int keyCode)
{
form.callKeyRepeated(keyCode);
}
void callKeyTyped(char keyCode)
{
form.callKeyTyped(keyCode);
}
void callPaint(Graphics g, Object target)
{
form.callPaint(g, target);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询