- 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/
所以我尝试使用与 this answer 类似的方法将文本叠加到 PDF 文档上. 我使用一个函数来设置当前的图形上下文,就像它在文档中所说的那样。 let pdfPage: CGPDFPage =
我已经问过了,但我需要进一步的知识。我正在尝试使用按钮命令将两个类链接在一起。我在这里遵循了最后一个答案,但是当我分开类(class)时,它不起作用。我使用 b2Command 来触发事件。这是我的代
所以我正在为我的项目准备 redux 并陷入困境。所有事情看起来都是正确的,因为 redux devtools 显示了状态。 当我尝试通过 this.props.function_name 调用组件中
在为预先存在的 QDir 对象重新分配新路径时,我在 Qt (v4.8.4) 中遇到了异常情况。这是一个证明这一点的简化示例: QString path1("F:/"); //Path m
(大致)相当于 BlackBerry() 中的 setCurrent()? 我有一些 J2ME 代码正在移植到 BB RIM 类。 J2ME 代码使用 setCurrent() 在应用程序中“更改页面
本文整理了Java中pl.edu.icm.model.bwmeta.y.YStructure.setCurrent()方法的一些代码示例,展示了YStructure.setCurrent()的具体用法
我是一名优秀的程序员,十分优秀!