- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经问过了,但我需要进一步的知识。我正在尝试使用按钮命令将两个类链接在一起。我在这里遵循了最后一个答案,但是当我分开类(class)时,它不起作用。我使用 b2Command 来触发事件。这是我的代码:
MainMidlet.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Display;
/**
* @author bon
*/
public class MainMidlet extends MIDlet implements CommandListener,
ItemCommandListener, ItemStateListener{
private Display display;
private Form form;
private Command okCommand, backCommand, exitCommand, b1Command, b2Command, exCommand, boutCommand;
private StringItem b1stringItem, b2stringItem, boutstringItem, exstringItem;
public AddCalendarEvent addcalendarevent;
public MainMidlet(){
okCommand = new Command ( "OK", Command.OK, 1);
exitCommand = new Command ( "EXIT", Command.EXIT, 1);
backCommand = new Command ( "BACK", Command.BACK, 1);
b1Command = new Command ( "BUTTON", Command.ITEM, 2);
b2Command = new Command ( "BUTTON", Command.ITEM, 2);
exCommand = new Command ( "BUTTON", Command.ITEM, 2);
boutCommand = new Command ( "BUTTON", Command.ITEM, 2);
form = new Form ( "CyberMe");
b1stringItem = new StringItem (null, "Make Todo", Item.BUTTON);
b1stringItem.setItemCommandListener (this);
b1stringItem.setDefaultCommand (b1Command);
b2stringItem = new StringItem (null, "Set Alarm", Item.BUTTON);
b2stringItem.setItemCommandListener (this);
b2stringItem.setDefaultCommand (b2Command);
boutstringItem = new StringItem (null, "About", Item.BUTTON);
boutstringItem.setItemCommandListener (this);
boutstringItem.setDefaultCommand (boutCommand);
exstringItem = new StringItem (null, "Exit", Item.BUTTON);
exstringItem.setItemCommandListener (this);
exstringItem.setDefaultCommand (exCommand);
form.append ( "Any Appointment?");
form.append (b1stringItem);
form.append (b2stringItem);
form.append (boutstringItem);
form.append (exstringItem);
form.addCommand (okCommand);
form.addCommand (exitCommand);
form.setCommandListener (this);
}
public void startApp() {
display = Display.getDisplay(this);
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void commandAction(Command c, Item item) {
if (c == b1Command) {
//display.setCurrent ();
}
else if (c == b2Command){
addcalendarevent = new AddCalendarEvent(this);
display.setCurrent(addcalendarevent);
}
else if (c == exCommand){
destroyApp(false);
notifyDestroyed ();
}
//else if (c == boutCommand)
//display.setCurrent ();
}
public void itemStateChanged(Item item) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Alert;
import javax.microedition.pim.PIM;
import javax.microedition.pim.PIMItem;
import javax.microedition.pim.EventList;
import javax.microedition.pim.Event;
import javax.microedition.pim.PIMException;
import java.util.Date;
/**
*
* @author bon
*/
public class AddCalendarEvent extends MainMidlet{
private Display display;
// Form where user can enter data of new event.
private Form addEventForm;
// Command for adding event to list of events. Placed on addEventForm.
private Command cmdAddEvent;
// Command for exiting from application. Placed on addEventForm.
private Command cmdExit;
// Text field for summary of event.
private TextField summaryField;
// Date field for start data of event.
private DateField startDateField;
// Date field for end data of event.
private DateField endDateField;
// Text field for note of event.
private TextField noteField;
// Text field for location of event.
private TextField locationField;
/**
* Constructor.
*/
public AddCalendarEvent() {
if(checkPIMSupport() == false) {
exitMIDlet();
}
initializeComponents();
}
/**
* Initializes components of midlet.
*/
public void initializeComponents() {
display = Display.getDisplay(this);
// Create form for adding event.
addEventForm = new Form("Add event");
// Add commands to form and set listener for it.
cmdAddEvent = new Command("Add event", Command.SCREEN, 0);
addEventForm.addCommand(cmdAddEvent);
cmdExit = new Command("Exit", Command.EXIT, 0);
addEventForm.addCommand(cmdExit);
addEventForm.setCommandListener(this);
try {
// Get list of events.
EventList eventList = (EventList)PIM.getInstance().openPIMList(
PIM.EVENT_LIST, PIM.READ_WRITE);
// Create controls based on supported fields for event.
if(eventList.isSupportedField(Event.SUMMARY) == true) {
summaryField = new TextField("Summary", null, 20,
TextField.ANY);
addEventForm.append(summaryField);
} else {
// At least "summary" field must be supported.
// If not, throw exception.
eventList.close();
throw new Exception("Summary field is not supported");
}
if(eventList.isSupportedField(Event.START) == true) {
startDateField = new DateField("Start date",
DateField.DATE_TIME);
startDateField.setDate(new Date());
addEventForm.append(startDateField);
}
if(eventList.isSupportedField(Event.END) == true) {
endDateField = new DateField("End date", DateField.DATE_TIME);
endDateField.setDate(new Date());
addEventForm.append(endDateField);
}
if(eventList.isSupportedField(Event.NOTE) == true) {
noteField = new TextField("Note", null, 20, TextField.ANY);
addEventForm.append(noteField);
}
if(eventList.isSupportedField(Event.LOCATION) == true) {
locationField = new TextField("Location", null, 20,
TextField.ANY);
addEventForm.append(locationField);
}
// Close list of events.
eventList.close();
} catch(PIMException pimExc) {
// TODO: Handle error on working with PIM.
}
catch(SecurityException secExc) {
// TODO: Handle error on access to PIM.
}
catch(Exception exc) {
// If unknown error was catched, exit from application.
exitMIDlet();
}
}
/**
* Checks PIM support.
* @return - true if PIM is supported, false otherwise.
*/
private boolean checkPIMSupport() {
String propValue = System.getProperty("microedition.pim.version");
if(propValue != null) {
return true;
} else {
return false;
}
}
/**
* Adds event to list of events.
* Gets data for event from addEventForm controls.
*/
private void addEvent() {
try {
// Get list of events.
EventList eventList = (EventList)PIM.getInstance().openPIMList(
PIM.EVENT_LIST, PIM.READ_WRITE);
// Create new event.
Event event = eventList.createEvent();
// Get data from controls
if(eventList.isSupportedField(Event.SUMMARY) == true) {
String summary = summaryField.getString();
event.addString(Event.SUMMARY, PIMItem.ATTR_NONE, summary);
} else {
// At least summary must be supported.
eventList.close();
throw new Exception("Summary field for event is not supported");
}
if(eventList.isSupportedField(Event.START) == true) {
long startDate = startDateField.getDate().getTime();
event.addDate(Event.START, PIMItem.ATTR_NONE, startDate);
}
if(eventList.isSupportedField(Event.END) == true) {
long endDate = endDateField.getDate().getTime();
event.addDate(Event.END, PIMItem.ATTR_NONE, endDate);
}
if(eventList.isSupportedField(Event.NOTE) == true) {
String note = noteField.getString();
event.addString(Event.NOTE, PIMItem.ATTR_NONE, note);
}
if(eventList.isSupportedField(Event.LOCATION) == true) {
String location = locationField.getString();
event.addString(Event.LOCATION, PIMItem.ATTR_NONE, location);
}
// Commit event.
event.commit();
// Close list of events.
eventList.close();
// Notify user that event was added
showAlert("Info", "Event was successfully added.");
} catch(PIMException pimExc) {
// TODO: Handle error on working with PIM.
showAlert("PIMException", pimExc.getMessage());
}
catch(SecurityException secExc) {
// TODO: Handle error on access to PIM.
showAlert("SecurityException", secExc.getMessage());
}
catch(Exception exc) {
// TODO: Handle all other errors.
showAlert("Exception", exc.getMessage());
}
}
/**
* Shows alert with specified title and text.
* @param title - Title of alert.
* @param message - text of alert.
*/
private void showAlert(String title, String message) {
Alert alert = new Alert(title);
alert.setString(message);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
private void exitMIDlet() {
notifyDestroyed();
}
public void commandAction(Command command, Displayable displayable) {
if(command == cmdAddEvent) {
addEvent();
}
if(command == cmdExit) {
exitMIDlet();
}
}
}
最佳答案
试试这个,
//在 MainMidlet 类中定义一个公共(public)静态方法
private static Display display; // declare static Display variable.
public static Display getDisplay ()
{
return display;
}
private void showAlert(String title, String message)
{
Alert alert = new Alert(title);
alert.setString(message);
alert.setTimeout(Alert.FOREVER);
MainMidlet.getDisplay().setCurrent(alert); // this line has been changed
}
关于java - J2ME setCurrent(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12416929/
在C语言中,当有变量(假设都是int)i小于j时,我们可以用等式 i^=j^=i^=j 交换两个变量的值。例如,令int i = 3,j = 5;在计算 i^=j^=i^=j 之后,我有 i = 5,
我为以下问题编写了以下代码: 给定一个由 N 个正整数组成的序列 A,编写一个程序来查找满足 i > A[j]A[i](A[i] 的 A[j] 次方 > A[j] 的 A[i] 次方)。 我的代码通过
这个表达式是从左到右解析的吗?我试图解释解析的结果,但最后的结果是错误的。 int j=10, k=10; j+=j-=j*=j; //j=j+(j-=j*=j)=j+(j-j*j) k+=k*=
给定一个整数数组 A ,我试图找出在给定位置 j ,A[j] 从每个 i=0 到 i=j 在 A 中出现了多少次。我设计了一个如下所示的解决方案 map CF[400005]; for(int i=0
你能帮我算法吗: 给定 2 个相同大小的数组 a[]和 b[]具有大于或等于 1 的整数。 查找不相等的索引 i和 j ( i != j ) 使得值 -max(a[i]*b[i] + a[i] * b
每次用J的M.副词,性能显着下降。因为我怀疑艾弗森和许比我聪明得多,我一定是做错了什么。 考虑 Collatz conjecture .这里似乎有各种各样的内存机会,但不管我放在哪里M. ,性能太差了
假设一个包含各种类型的盒装矩阵: matrix =: ('abc';'defgh';23),:('foo';'bar';45) matrix +---+-----+--+|abc|defgh|23|+
是否有可能对于两个正整数 i 和 j,(-i)/j 不等于 -(i/j)?我不知道这是否可能......我认为这将是关于位的东西,或者 char 类型的溢出或其他东西,但我找不到它。有什么想法吗? 最
假设两个不同大小的数组: N0 =: i. 50 N1 =: i. 500 应该有一种方法可以获得唯一的对,只需将两者结合起来即可。我发现的“最简单”是: ]$R =: |:,"2 |: (,.N0)
我是 J 的新用户,我只是想知道 J 包中是否实现了三次样条插值方法? 最佳答案 我自己不熟悉,但是我确实安装了所有的包,所以 $ rg -l -i spline /usr/share/j/9.02
在 Q/kdb 中,您可以使用 ': 轻松修改动词,它代表每个优先级。它会将动词应用于一个元素及其之前的邻居。例如 =': 检查值对是否相等。在 J 中,您可以轻松折叠 /\ 但它是累积的,是否有成对
嗨,我有一个 4x4 双矩阵 A 1+2i 2-1i -3-2i -1+4i 3-1i -3+2i 1-3i -1-3i 4+3i 3+5i 1-2i -1-4i
刚刚发现 J 语言,我输入: 1+^o.*0j1 I expected the answer to be 0 ,但我得到了 0j1.22465e_16。虽然这非常接近于 0,但我想知道为什么 J 应该
这个问题在这里已经有了答案: With arrays, why is it the case that a[5] == 5[a]? (20 个答案) 关闭 3 年前。 我正在阅读“C++ 编程语言”
当第一行是 1, 1/2 , 1/3 ....这是支持该问题的图像。 是否存在比朴素的 O(n^2) 方法更有效的方法? 我在研究伯努利数时遇到了这个问题,然后在研究“Akiyama-Tanigawa
我写了一段Java代码,它在无限循环中运行。 下面是代码: public class TestProgram { public static void main(String[] args){
for (int i = n; i > 0; i /= 2) { for (int j = 0; j 0; i /= 2) 的第一个循环结果 O(log N) . 第二个循环for (int
如问题中所述,需要找到数组中 (i,j) 对的总数,使得 (1) **ia[j]** 其中 i 和 j 是数组的索引。没有空间限制。 我的问题是 1) Is there any approach w
for l in range(1,len(S)-1): for i in range(1,len(S)-l): j=i+l for X in N:
第二个for循环的复杂度是多少?会是n-i吗?根据我的理解,第一个 for 循环将执行 n 次,但第二个 for 循环中的索引设置为 i。 //where n is the number elemen
我是一名优秀的程序员,十分优秀!