2 sbcx 2h sbcx_2h 于 2014.04.08 10:56 提问

import org.eclipse.swt.*; 程序提示找不到这个包,请问下到这个包放到什么地方?

import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

这一堆包都没有
下载了org.eclipse包可能放错地方了,程序还是跑不起来

下面是主函数
package visualizer;

import interpreter.*;
import java.io.*;
import java.util.*;
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**

  • Main class, implements a window with a menu
  • and a cardbox for holding the AbstractTab items
  • @author Martin Bättig
  • @version 1.0
    */
    public class Main {
    private Shell shell = null;
    private Menu menu = null;
    private TabFolder tabFolder = null;
    private MenuItem roundRobinItem = null;
    private MenuItem uniformItem = null;
    private MenuItem userItem = null;
    boolean firstOpen = true;

    private void menuFileNew() {
    TabItem[] tabItem = new TabItem[1];
    tabItem[0] = new TabItem(tabFolder, SWT.NONE);
    tabItem[0].setControl(new VisualizerTab(tabFolder, SWT.NONE));
    tabItem[0].setText("Unnamed.mwl");
    ((AbstractTab) tabItem[0].getControl()).setFilename("Unnamed.mwl");
    tabFolder.setSelection(tabItem);
    firstOpen = false;
    }

    private void menuFileOpen() {
    FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
    fileDialog.setFilterExtensions(new String[] { "*.mwl" });
    if (fileDialog.open() == null)
    return;
    String fileSeparator = System.getProperty("file.separator");
    String filename = fileDialog.getFilterPath() + fileSeparator
    + fileDialog.getFileName();

    String program = getStringFromFile(filename);
    if (program == null)
        return;
    
    TabItem[] tabItem = new TabItem[1];
    tabItem[0] = null;
    if (firstOpen && !getCurrentTab().getChanged()) {
        tabItem[0] = tabFolder.getItem(0);
    } else {
        tabItem[0] = new TabItem(tabFolder, SWT.NONE);
        tabItem[0].setControl(new VisualizerTab(tabFolder, SWT.NONE));
    }
    tabItem[0].setText(fileDialog.getFileName());
    AbstractTab exploit = (AbstractTab) tabItem[0].getControl();
    exploit.setFilename(filename);
    exploit.setCode(program);
    tabFolder.setSelection(tabItem);
    firstOpen = false;
    

    }

    private void menuFileClose() {
    TabItem[] tabItems = tabFolder.getSelection();
    if (tabItems.length != 1)
    return;
    AbstractTab exploit = (AbstractTab) tabItems[0].getControl();
    if (!exploit.close())
    return;
    tabItems[0].dispose();
    }

    private void menuFileSave() {
    AbstractTab tab = getCurrentTab();
    writeStringToFile(tab.getFilename(), tab.getCode());
    }

    private void menuFileSaveAs() {
    // get the filename
    AbstractTab tab = getCurrentTab();
    int index = tabFolder.getSelectionIndex();
    if (index == -1)
    return;
    TabItem tabItem = tabFolder.getItem(index);
    String filename = tabItem.getText();

    // prepare save dialog
    FileDialog saveDialog = new FileDialog(shell, SWT.SAVE);
    saveDialog.setFileName(getCurrentTab().getFilename());
    if (saveDialog.open() == null)
        return;
    String fileSeparator = System.getProperty("file.separator");
    
    // execute dialog, save file and refresh filename fields
    filename = saveDialog.getFilterPath() + fileSeparator + saveDialog.getFileName();
    writeStringToFile(filename, tab.getCode());
    tabItem.setText(saveDialog.getFileName());
    tab.setFilename(filename);
    

    }

    private void menuFileExit() {
    // only close the shell if all tabs have been closed
    TabItem[] tabItems = tabFolder.getItems();
    for (int i = 0; i < tabItems.length; i++) {
    AbstractTab exploit = (AbstractTab) tabItems[i].getControl();
    if (!exploit.close())
    return;
    }
    shell.close();
    }

    private AbstractTab getCurrentTab() {
    int index = tabFolder.getSelectionIndex();
    if (index == -1)
    return null;
    TabItem tabItem = tabFolder.getItem(index);
    return (AbstractTab) tabItem.getControl();
    }

    public String getStringFromFile(String filename) {
    String code = "";
    try {
    InputStreamReader in = new InputStreamReader(new FileInputStream(filename));
    char[] buf = new char[1000];
    int num = 0;
    while (true) {
    num = in.read(buf);
    if (num < 0)
    break;
    code += new String(buf, 0, num);
    }
    } catch (FileNotFoundException e) {
    MessageBox messageBox = new MessageBox(shell, SWT.ICON_ERROR);
    messageBox.setMessage("File: " + filename + " not found");
    messageBox.open();
    } catch (IOException e) {
    MessageBox messageBox = new MessageBox(shell, SWT.ICON_ERROR);
    messageBox.setMessage("Error while reading from file: " + filename);
    messageBox.open();
    }
    return code;
    }

    public void writeStringToFile(String filename, String text) {
    try {
    OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(
    filename));
    out.write(text);
    out.flush();
    } catch (FileNotFoundException e) {
    MessageBox messageBox = new MessageBox(shell, SWT.ICON_ERROR);
    messageBox.setMessage("File: " + filename + " not found");
    messageBox.open();
    } catch (IOException e) {
    MessageBox messageBox = new MessageBox(shell, SWT.ICON_ERROR);
    messageBox.setMessage("Error while writing to file: " + filename);
    messageBox.open();
    }
    }

    private void createMenu() {
    menu = new Menu(shell, SWT.BAR);

    Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
    MenuItem fileItem = new MenuItem(menu, SWT.CASCADE);
    fileItem.setText("&File");
    fileItem.setMenu(fileMenu);
    
    MenuItem newItem = new MenuItem(fileMenu, SWT.PUSH);
    newItem.setText("&New\tCrtl+N");
    newItem.setAccelerator(SWT.CTRL + 'N');
    newItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            menuFileNew();
        }
    });
    
    MenuItem openItem = new MenuItem(fileMenu, SWT.PUSH);
    openItem.setText("&Open\tCrtl+O");
    openItem.setAccelerator(SWT.CTRL + 'O');
    openItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            menuFileOpen();
        }
    });
    
    MenuItem closeItem = new MenuItem(fileMenu, SWT.PUSH);
    closeItem.setText("&Close\tCrtl+C");
    closeItem.setAccelerator(SWT.CTRL + 'C');
    closeItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            menuFileClose();
        }
    });
    
    MenuItem saveItem = new MenuItem(fileMenu, SWT.PUSH);
    saveItem.setText("&Save\tCrtl+S");
    saveItem.setAccelerator(SWT.CTRL + 'S');
    saveItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            menuFileSave();
        }
    });
    
    MenuItem saveAsItem = new MenuItem(fileMenu, SWT.PUSH);
    saveAsItem.setText("&Save as...\tCrtl+A");
    saveAsItem.setAccelerator(SWT.CTRL + 'A');
    saveAsItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            menuFileSaveAs();
        }
    });
    
    new MenuItem(fileMenu, SWT.SEPARATOR);
    
    MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
    exitItem.setText("Exit\tCrtl+E");
    exitItem.setAccelerator(SWT.CTRL + 'E');
    exitItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            menuFileExit();
        }
    });
    
    Menu editMenu = new Menu(shell, SWT.DROP_DOWN);
    MenuItem editItem = new MenuItem(menu, SWT.CASCADE);
    editItem.setText("&Edit");
    editItem.setMenu(editMenu);
    
    MenuItem cutItem = new MenuItem(editMenu, SWT.PUSH);
    cutItem.setText("Cu&t\tShift+Delete");
    cutItem.setAccelerator(SWT.SHIFT + SWT.DEL);
    cutItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            getCurrentTab().cut();
        }
    });
    
    MenuItem copyItem = new MenuItem(editMenu, SWT.PUSH);
    copyItem.setText("&Copy\tCrtl+Insert");
    copyItem.setAccelerator(SWT.CTRL + SWT.INSERT);
    copyItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            getCurrentTab().copy();
        }
    });
    
    MenuItem pasteItem = new MenuItem(editMenu, SWT.PUSH);
    pasteItem.setText("&Paste\tShift+Insert");
    pasteItem.setAccelerator(SWT.SHIFT + SWT.INSERT);
    pasteItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            getCurrentTab().paste();
        }
    });
    
    Menu actionMenu = new Menu(shell, SWT.DROP_DOWN);
    MenuItem actionItem = new MenuItem(menu, SWT.CASCADE);
    actionItem.setText("&Action");
    actionItem.setMenu(actionMenu);
    
    MenuItem runItem = new MenuItem(actionMenu, SWT.PUSH);
    runItem.setText("&Visualize\tF1");
    runItem.setAccelerator(SWT.F1);
    runItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            getCurrentTab().simulate();
        }
    });
    
    MenuItem stepItem = new MenuItem(actionMenu, SWT.PUSH);
    stepItem.setText("&Step\tF2");
    stepItem.setAccelerator(SWT.F2);
    stepItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            getCurrentTab().step();
        }
    });
    
    MenuItem resetItem = new MenuItem(actionMenu, SWT.PUSH);
    resetItem.setText("&Reset\tF3");
    resetItem.setAccelerator(SWT.F3);
    resetItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            getCurrentTab().reset();
        }
    });
    
    MenuItem checkItem = new MenuItem(actionMenu, SWT.PUSH);
    checkItem.setText("&Check\tF4");
    checkItem.setAccelerator(SWT.F4);
    checkItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            getCurrentTab().check();
        }
    });
    
    MenuItem transformItem = new MenuItem(actionMenu, SWT.PUSH);
    transformItem.setText("&Transform\tF5");
    transformItem.setAccelerator(SWT.F5);
    transformItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            getCurrentTab().transform();
        }
    });
    
    Menu schedulerMenu = new Menu(shell, SWT.DROP_DOWN);
    MenuItem schedulerItem = new MenuItem(menu, SWT.CASCADE);
    schedulerItem.setText("&Scheduler");
    schedulerItem.setMenu(schedulerMenu);
    
    roundRobinItem = new MenuItem(schedulerMenu, SWT.RADIO);
    roundRobinItem.setText("&Round Robin");
    roundRobinItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            getCurrentTab().setScheduler(new RoundRobinScheduler());
        }
    });
    roundRobinItem.setSelection(true);
    
    uniformItem = new MenuItem(schedulerMenu, SWT.RADIO);
    uniformItem.setText("&Uniform");
    uniformItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            getCurrentTab().setScheduler(new UniformScheduler());
        }
    });
    

    }

    private void setScheduler() {
    AbstractTab exploit = getCurrentTab();
    if (exploit == null)
    return;
    Scheduler scheduler = exploit.getScheduler();
    roundRobinItem.setSelection(false);
    uniformItem.setSelection(false);
    if (scheduler instanceof RoundRobinScheduler)
    roundRobinItem.setSelection(true);
    else if (scheduler instanceof UniformScheduler)
    uniformItem.setSelection(true);
    else
    roundRobinItem.setSelection(true);
    }

    private void createShell() {
    shell = new Shell();
    FillLayout fillLayout = new FillLayout();
    fillLayout.type = SWT.VERTICAL;
    shell.setLayout(fillLayout);
    tabFolder = new TabFolder(shell, SWT.NONE);
    tabFolder.addListener(SWT.Selection, new Listener() {
    public void handleEvent(Event e) {
    setScheduler();
    }
    });
    createMenu();
    shell.setMenuBar(menu);
    menuFileNew();
    shell.setText("Information Leak Visualizer");
    shell.setSize(new Point(1024, 768));
    }

    public static void main(String[] args) {
    Display display = Display.getDefault();
    Main test = new Main();
    test.createShell();
    test.shell.open();
    while (!test.shell.isDisposed()) {
    if (!display.readAndDispatch())
    display.sleep();
    }
    display.dispose();
    }
    }

1个回答

u014084117
u014084117   2014.04.10 14:16

你看下你的eclipse安装目录下的plugins文件下有没有你需要的jar包

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
[乐意黎原创] org.eclipse.swt包的引入
我在做Java可视化程序时,用到下面这几个包,应该怎么处理:(Eclipse环境) import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; 提示:the import org.eclipse can not be resolved.
org.apache.commons.lang3.xwork.StringUtils找不到的问题
问题排错:    首先看你是否导入了commons-lang3-3.2.jar,主意必须是lang3,而不是lang。后面版本可以忽略 如果没问题的话你找一下你版本jar包是否匹配!我就是因为jar包零散下载版本不匹配导致引用出错 一开始找翻了百度:全都是导入xwork-core-2.1.6.jar,导入commons-lang-2.6.jar。那几个版本跟不上现在版本了,完全可以忽略掉。
IDEA 包导入了,但依然提示找不到
项目名称右键-》Maven(可能需要滚动弹出的菜单才能找到)->Reimport
python有时候import不了当前的包
python有时候import不了当前的包问题描述: ImportError: No module named ‘XXXX’解决方式一: 将XXXX包放在python的site-package文件夹下 解决方式二: 可能是XXXX包没有新建init.py 解决方式三: init.py需要声明包含XXXX包的函数 解决方式四: sys.path.append(Ur ‘XXXX’s
解决IDEA无法提示导入java.util.Date的问题F
  之前有一段时间在使用IDEA的时候,发现通过快捷键Alt + Enter导入并没有提示有java.util.Date的包,仅仅只有java.sql.Date的包。于是每次使用都需要通过手写import java.util.Date;来进行导包。博主在好生不爽了一段时间后,终于在网上找到了解决办法,本文就是用来记录一下解决过程的。   找到设置(Alt ...
pip装了一个包,但是python里Import的时候找不到怎么办?
通常作为没有管理员权限的用户,在服务器上用Pip装包需要装到自己Home底下(过程见上篇)。 有时候装了之后找不到这个包,import不进来,no module named xxx, 为什么呢?因为虽然装到了一个路径底下,但是Python找不到这个路径,这个时候需要改环境变量。 例如,在.bashrc中加一行 export PYTHONPATH=$PYTHONPATH:"/h
silverlight4 SDK
VS2010 SP1升级提示找不到silverlight4 SDK,可以用这个包,或者卸载MVC4的时候提示需要这个包,也可以。
python已安装了一个包,但是导入包中的模块时报错没有这个包
执行import sys; print(sys.path)查看python搜索路径,确保自己的模块在python搜索路径中 python的搜索路径与包(package) python的搜索路径其实是一个列表,它是指导入模块时,python会自动去找搜索这个列表当中的路径,如果路径中存在要导入的模块文件则导入成功,否则导入失败: &amp;amp;amp;gt;&amp;amp;amp;gt;&amp;amp;amp;gt; import sys &amp;amp;amp;gt;...
ROS:找不到程序包
上次成功地写了hello ROS程序,但是今天我想再次打开这个结点时,显示cannot find the package这个问题的解决办法一:每次打开命令窗都使用一次source ~/ros_ws/devel/setup.bash解决方法二:在住文件夹的图形界面使用快捷键Ctrl+H,可以看到很多原先不显示的隐藏文件,打开&quot;.bashrc&quot;文件,在最后一行加上source ~/ros_ws/dev...
编译源码出现的问题couldn't find import for class
项目中需要修改源码,加入对以太网的支持。找到了一个开源的android项目,将其中的ethernet部分移到eclair的源码下。出现以下问题。 frameworks/base/ethernet/java/android/net/ethernet/IEthernetManager.aidl:3: couldnt find import for class android.net.ethe