[求助]关于eclipse下开发串口操作插件的问题
2008-02-23 10:07:03来源:互联网 阅读 ()
请教一下,我用Eclipse开发一个可以读取串口信息的插件,把它单独作为应用程序可以正常运行.但以插件形式运行时点击按钮就会出现异常.不知道是什么问题?
插件窗口程序:
package com.plugin.Hello;
import org.eclipse.core.runtime.*;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import com.leon.serial.*;
/**
* This class demonstrates JFace's ErrorDialog class
*/
public class DialogSample extends ApplicationWindow {
/**
* ShowError constructor
*/
public DialogSample() {
super(null);
}
/**
* Runs the application
*/
public void run() {
// Don't return from open() until window closes
setBlockOnOpen(true);
// Open the main window
open();
// Dispose the display
Display.getCurrent().dispose();
}
/**
* Configures the shell
*
* @param shell the shell
*/
protected void configureShell(Shell shell) {
super.configureShell(shell);
// Set the title bar text and the size
shell.setText("read com");
shell.setSize(400, 400);
}
/**
* Creates the main window's contents
*
* @param parent the main window
* @return Control
*/
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
// Create a big text box to accept error text
final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
text.setLayoutData(new GridData(GridData.FILL_BOTH));
// Create the button to launch the error dialog
Button show = new Button(composite, SWT.PUSH);
show.setText("open serial port");
show.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SerialBean SB = new SerialBean(2);
String Msg = "";
SB.Initialize();
Msg = SB.ReadPort(10);
SB.ClosePort();
text.setText(Msg);
}
});
return composite;
}
/**
* The application entry point
*
* @param args the command line arguments
*/
/* public static void main(String[] args) {
new DialogSample().run();
}
*/
}
插件是根据helloworld改过来的
package com.plugin.Hello;
import org.eclipse.ui.plugin.*;
import org.osgi.Framework.BundleContext;
import Java.util.*;
/**
* The main plugin class to be used in the desktop.
*/
public class HelloPlugin extends AbstractUIPlugin {
//The shared instance.
private static HelloPlugin plugin;
//Resource bundle.
private ResourceBundle resourceBundle;
/**
* The constructor.
*/
public HelloPlugin() {
super();
plugin = this;
try {
resourceBundle = ResourceBundle.getBundle("com.plugin.Hello.HelloPluginResources");
} catch (MissingResourceException x) {
resourceBundle = null;
}
}
/**
* This method is called upon plug-in activation
*/
public void start(BundleContext context) throws Exception {
super.start(context);
}
/**
* This method is called when the plug-in is stopped
*/
public void stop(BundleContext context) throws Exception {
super.stop(context);
}
/**
* Returns the shared instance.
*/
public static HelloPlugin getDefault() {
return plugin;
}
/**
* Returns the string from the plugin's resource bundle,
* or 'key' if not found.
*/
public static String getResourceString(String key) {
ResourceBundle bundle = HelloPlugin.getDefault().getResourceBundle();
try {
return (bundle != null) ? bundle.getString(key) : key;
} catch (MissingResourceException e) {
return key;
}
}
/**
* Returns the plugin's resource bundle,
*/
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
}
上一篇: 把JSP预编译成class文件进行JSP文件的保护
下一篇: 用JDOM建立XML文件
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash