我是 Squeak Smalltalk 的新手。如何捕获按钮单击事件并在单击按钮时执行一些代码。
我尝试了这段代码,但它不起作用!
我创建了一个新的按钮类:
SimpleButtonMorph subclass: #ButtonTest
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'test'
Run Code Online (Sandbox Code Playgroud)
在这个类中我写了这个方法:
handleMouseDown: event
^ true.
Run Code Online (Sandbox Code Playgroud)
我想在另一个 Morph 中使用按钮,所以我创建了新的 Morph 类:
RectangleMorph subclass: #RectangleMorphTest
instanceVariableNames: 'textField button stringLabel mouseAction'
classVariableNames: ''
poolDictionaries: ''
category: 'test'
Run Code Online (Sandbox Code Playgroud)
在Initialize方法中,我在RectangleMorph中编写了buttonMorph,矩形Morph的初始化方法:
initialize
super initialize.
self bounds: ((0@0) extent: (400@400)).
self color: Color gray.
textField := TextFieldMorph new.
textField color: Color lightYellow.
textField contents: 'text'.
textField bounds: ((25@25) extent: (300@75)).
button := ButtonTest new.
button borderWidth: 2.
button bounds: ((150@150) …
Run Code Online (Sandbox Code Playgroud) 我使用纸莎草创建了一个类图,我得到了一个*.uml模型.现在我想通过编写一些Java代码来遍历*.uml元素.
我试过这段代码:
URI uri = URI.createURI("*.uml");
ResourceSet set = new ResourceSetImpl();
set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap()
.put("uml", UMLResource.Factory.INSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put("xmi", new XMIResourceFactoryImpl());
//set.createResource(uri);
Resource res = set.getResource(URI.createURI(new URL("*.uml").toString(),true),true);
Run Code Online (Sandbox Code Playgroud)
但我得到了例外:
线程"main"中的异常java.lang.NoSuchMethodError:org.eclipse.emf.ecore.resource.URIConverter.createInputStream(Lorg/eclipse/emf/common/util/URI; Ljava/util/Map;)Ljava/io/InputStream ;
如何使用Java加载纸莎草uml模型?