主题:SWTResourceManager问题,求助
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class ButtonTest {
private static Text text;
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application");
shell.open();
final Button okButton = new Button(shell, SWT.NONE);
okButton.setImage([color=FF0000]SWTResourceManager[/color].getImage(ButtonTest.class, "275.jpg"));
okButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String str = text.getText();
if (str == null || str.equals("")) {
MessageDialog.openInformation(shell, "", "please enter a number");
} else {
MessageDialog.openInformation(shell, "", "your enter the number is true");
}
}
});
okButton.setText("OK.");
okButton.setBounds(81, 183, 244, 54);
text = new Text(shell, SWT.BORDER);
text.setTextLimit(10); //最都只能输入10个字符
text.setBounds(70, 85, 228, 46);
text.addVerifyListener(new VerifyListener(){//检查监听器,每输入一个字符都回触发
public void verifyText(VerifyEvent e) {
//检查输入字符(e.text)是否在0123456789这个字符串中,不在indexOf会返回-1
boolean b = "0123456789".indexOf(e.text) >= 0 ;
e.doit = b; //doit属性如果为true,则字符允许输入,反之不允许
}
});
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
eclipse编辑的时候,红色部分报错,不能处理它,怎么回事哦?求助~ 这个是不是一个类?要导入什么包呢?
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class ButtonTest {
private static Text text;
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application");
shell.open();
final Button okButton = new Button(shell, SWT.NONE);
okButton.setImage([color=FF0000]SWTResourceManager[/color].getImage(ButtonTest.class, "275.jpg"));
okButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String str = text.getText();
if (str == null || str.equals("")) {
MessageDialog.openInformation(shell, "", "please enter a number");
} else {
MessageDialog.openInformation(shell, "", "your enter the number is true");
}
}
});
okButton.setText("OK.");
okButton.setBounds(81, 183, 244, 54);
text = new Text(shell, SWT.BORDER);
text.setTextLimit(10); //最都只能输入10个字符
text.setBounds(70, 85, 228, 46);
text.addVerifyListener(new VerifyListener(){//检查监听器,每输入一个字符都回触发
public void verifyText(VerifyEvent e) {
//检查输入字符(e.text)是否在0123456789这个字符串中,不在indexOf会返回-1
boolean b = "0123456789".indexOf(e.text) >= 0 ;
e.doit = b; //doit属性如果为true,则字符允许输入,反之不允许
}
});
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
eclipse编辑的时候,红色部分报错,不能处理它,怎么回事哦?求助~ 这个是不是一个类?要导入什么包呢?