Implementation of points in sweep line - class

In sweep line algorithms, I use an array which sorts points by their x-coordinates, and a TreeSet that sorts points by their y-coordinates. Currently, I used two point classes to indicate which comparator to be used (i.e. whether to compare the x-coordinate or the y-coordinate). Is this possible with one point class but two compareTo functions? To illustrate, here's what I have. Apologies for the unprofessional terminology.
public static class Point implements Comparable<Point>{
int x; int y;
public Point(int a, int b){
this.x=a; this.y=b;
}
public int compareTo(Point other){
if(this.x<other.x)return -1;
if(this.x>other.x)return 1;
if(this.y>other.y)return 1;
return -1;
}
}
public static class Point2 implements Comparable<Point2>{
int x; int y;
public Point2(int a, int b){
this.x=a; this.y=b;
}
public int compareTo(Point2 other){
if(this.y<other.y)return -1;
if(this.y>other.y)return 1;
if(this.x>other.x)return 1;
return -1;
}
}

Both arrays and TreeSets allow sorting based on custom Comparators:
new TreeSet<>(new Comparator<T>() {
#Override
public int compare(T t1, T t2) {
// your implementation here
}
});
Arrays.sort(arr, new Comparator<T>() {
#Override
public int compare(T t1, T t2) {
// your implementation here
}
});

Related

Haxe access Class<T> static fields

I have three classes and I would like to be able to call static functions from the returned Class<Access>. I would like to select class type based on conditions.
class Access {
public static function get(item: Int): Int { return -1; }
public static function getAccessType(): Class<Access> {
if(Client.hasConnection())
return Remote;
else return Local;
}
}
class Remote extends Access {
override public static function get(item: Int): Int { return Server.getItem(item); }
}
class Local extends Access {
override public static function get(item: Int): Int { return Client.getItem(item); }
}
You can't override a static function in Haxe.
But you can probably achieve what you're trying to do by simply removing the override in Remote and Local
Can be done with singletons.
However, still the question might relevant whether such feature in Haxe even exists.
Depending on target, you may be able to cast a class to an interface/typedef to pull out values in a type-safe-ish way. "override" does not work for static methods
class Test {
static function pick(z:Bool):HasGetItem {
return z ? cast A : cast B;
}
static function main() {
trace("Haxe is great!");
trace(pick(false).getItem(1));
trace(pick(true).getItem(2));
}
}
#:keep class A {
public static function getItem(i:Int):Int return 10;
}
#:keep class B {
public static function getItem(i:Int):Int return 5;
}
typedef HasGetItem = {
getItem:Int->Int
}
https://try.haxe.org/#b2b87

Using setters and getters between 3 classes

I know this is a basic question but I really struggle with this :(
First class:
public class A{
C c= new C();
B b= new B();
public static void main(String[] args) {
b.start();
System.out.println(c.getSomething());
}
}
Second Class:
public class B{
C c= new C();
public void start(){
c.setSomething(2);
}
}
Third Class:
public class C{
int x;
public int getSomething() {
return x;
}
public void setSomething(int x) {
this.x = x;
}
}
Now I know I make a new object in class A thats why the sysout returns null.
How can I make it so that I GET the value 2 instead of null in class A, and that I'm able to SET things in class B.
So I stay at the same object so to say.
I just want to be able to SET things in class B and GET that same value from the setter-getter-class-C, in class A. Please help
Thanks in advance, Jimme

Is there an event in JavaFX8 when a stage gets disabled by a modal stage?

I am trying to create a status bar for our project. What I would like to happen is to change the status bar message whenever the primary stage got disabled by a modal stage (e.g. dialog).
It is currently implemented by changing the status message manually before and after showing the modal stage. Is there a better way to do this?
There is a very simple way to do this, assuming that you only have one dialog:
statusLabel.textProperty().bind(Bindings.when(dialog.showingProperty())
.then("Modal Dialog is showing").otherwise("Main window is showing"));
Alternatively, if you have multiple dialogs, you can do:
List<Stage> dialogs = ...
statusLabel.textProperty().bind(new StringBinding() {
{
for (Stage dialog : dialogs)
bind(dialog.showingProperty());
}
protected String computeValue() {
for (Stage dialog : dialogs)
if (dialog.isShowing())
return "A modal dialog is showing";
return "Main window is showing";
}
});
EDIT: Currently, there is no simple way to determine whether or not a given window is blocked by another modal window, assuming you have no knowledge of (or don't want to keep track of) all of the child windows you've created. Also, if you are using a FileChooser or a DirectoryChooser, the above method completely falls apart.
However, by inserting a custom Toolkit into javafx, you can obtain the desired behavior. A word of caution: using classes in com.sun.* directly in your code is usually not a good idea. But in the spirit of adventure, I have implemented one such Toolkit which (I believe) is working correctly. It should work with both WINDOW_MODAL and APPLICATION_MODAL windows. Use at your own risk! Here goes:
public class Test extends Application {
public static final StringProperty readyLabelProperty = new SimpleStringProperty("Ready");
public static final StringProperty blockedLabelProperty = new SimpleStringProperty("Blocked");
public static void main(String[] args) {
Tk.register();
Application.launch(args);
}
private static StringBinding statusBinding(Window window) {
return Bindings.when(Tk.blockedProperty(window)).then(blockedLabelProperty).otherwise(readyLabelProperty);
}
#Override
public void start(Stage s) throws Exception {
s.show();
s.titleProperty().bind(statusBinding(s));
Stage stage = new Stage();
stage.initOwner(s);
stage.initModality(Modality.WINDOW_MODAL);
stage.titleProperty().bind(statusBinding(stage));
stage.show();
new FileChooser().showOpenDialog(stage);
}
}
public class Tk extends Toolkit {
public static final BooleanBinding blockedProperty(final Window window) {
Objects.requireNonNull(window);
return new BooleanBinding() {
{
bind(stageImpls, owners);
}
#Override
protected boolean computeValue() {
try {
return StageImpl.get(window).isBlocked();
} catch (NullPointerException e) {
return false;
}
}
};
}
private static final Field TOOLKIT = getField(Toolkit.class, "TOOLKIT");
private static Field getField(Class<?> clazz, String name) {
try {
Field f = clazz.getDeclaredField(name);
f.setAccessible(true);
return f;
} catch (NoSuchFieldException e) {
return getField(clazz.getSuperclass(), name);
}
}
private static Method getMethod(Class<?> clazz, String name, Class<?>...parameterTypes) {
try {
Method m = clazz.getDeclaredMethod(name, parameterTypes);
m.setAccessible(true);
return m;
} catch (NoSuchMethodException e) {
return getMethod(clazz.getSuperclass(), name);
}
}
private static final Object invoke(Method method, Object obj, Object...args) {
try {
return method.invoke(obj, args);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
private final Toolkit qt = Toolkit.getToolkit();
private static Tk current;
public static void register() {
current = new Tk();
rewrap();
}
private static void unwrap() {
current = (Tk)Toolkit.getToolkit();
try {
TOOLKIT.set(null, current.qt);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
private static void rewrap() {
try {
TOOLKIT.set(null, Objects.requireNonNull(current));
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
private static final ObservableList<StageImpl> owners = FXCollections.observableArrayList();
private static final ObservableList<StageImpl> stageImpls = new ModifiableObservableListBase<StageImpl>() {
final ArrayList<StageImpl> list = new ArrayList<>();
final InvalidationListener l = new InvalidationListener() {
public void invalidated(Observable obs) {
beginChange();
nextUpdate(indexOf(StageImpl.get((Window)((ReadOnlyBooleanProperty)obs).getBean())));
endChange();
}
};
public StageImpl get(int index) {
return list.get(index);
}
public int size() {
return list.size();
}
protected void doAdd(int index, StageImpl element) {
list.add(index, element);
element.peer.showingProperty().addListener(l);
}
protected StageImpl doSet(int index, StageImpl element) {
StageImpl replaced = list.set(index, element);
replaced.peer.showingProperty().removeListener(l);
element.peer.showingProperty().addListener(l);
return replaced;
}
protected StageImpl doRemove(int index) {
StageImpl removed = list.remove(index);
removed.peer.showingProperty().removeListener(l);
return removed;
}
};
public TKStage createTKStage(Window w, StageStyle s, boolean primary, Modality m, TKStage owner, boolean rtl, AccessControlContext acc) {
return new StageImpl(qt.createTKStage(w, s, primary, m, owner == null ? null : StageImpl.get(owner).qs, rtl, acc), w, owner, m);
}
public FileChooserResult showFileChooser(TKStage owner, String title, File dir, String name, FileChooserType type,
List<ExtensionFilter> filters, ExtensionFilter selected) {
if (owner == null)
return qt.showFileChooser(null, title, dir, name, type, filters, selected);
StageImpl ownerImpl = StageImpl.get(owner);
owners.add(ownerImpl);
FileChooserResult result = qt.showFileChooser(ownerImpl.qs, title, dir, name, type, filters, selected);
owners.remove(ownerImpl);
return result;
}
public File showDirectoryChooser(TKStage owner, String title, File dir) {
if (owner == null)
return qt.showDirectoryChooser(null, title, dir);
StageImpl ownerImpl = StageImpl.get(owner);
owners.add(ownerImpl);
File file = qt.showDirectoryChooser(ownerImpl.qs, title, dir);
owners.remove(ownerImpl);
return file;
}
public boolean init() {
return qt.init();
}
public void startup(Runnable userStartupRunnable) {
qt.startup(userStartupRunnable);
}
public void checkFxUserThread() {
qt.checkFxUserThread();
}
public Future<?> addRenderJob(RenderJob r) {
return qt.addRenderJob(r);
}
public AppletWindow createAppletWindow(long parent, String serverName) {
return qt.createAppletWindow(parent, serverName);
}
public void closeAppletWindow() {
qt.closeAppletWindow();
}
public Object enterNestedEventLoop(Object key) {
return qt.enterNestedEventLoop(key);
}
public void exitNestedEventLoop(Object key, Object rval) {
qt.exitNestedEventLoop(key, rval);
}
public TKStage createTKPopupStage(Window peerWindow, StageStyle popupStyle,
TKStage owner, AccessControlContext acc) {
return qt.createTKPopupStage(peerWindow, popupStyle, owner, acc);
}
public TKStage createTKEmbeddedStage(HostInterface host,
AccessControlContext acc) {
return qt.createTKEmbeddedStage(host, acc);
}
public ScreenConfigurationAccessor setScreenConfigurationListener(
TKScreenConfigurationListener listener) {
return qt.setScreenConfigurationListener(listener);
}
public Object getPrimaryScreen() {
return qt.getPrimaryScreen();
}
public List<?> getScreens() {
return qt.getScreens();
}
public PerformanceTracker getPerformanceTracker() {
return qt.getPerformanceTracker();
}
public PerformanceTracker createPerformanceTracker() {
return qt.createPerformanceTracker();
}
public ImageLoader loadImage(String url, int width, int height,
boolean preserveRatio, boolean smooth) {
return qt.loadImage(url, width, height, preserveRatio, smooth);
}
public ImageLoader loadImage(InputStream stream, int width, int height,
boolean preserveRatio, boolean smooth) {
return qt.loadImage(stream, width, height, preserveRatio, smooth);
}
public AbstractRemoteResource loadImageAsync(
AsyncOperationListener l, String url, int width, int height,
boolean preserveRatio, boolean smooth) {
return (AbstractRemoteResource) qt.loadImageAsync(l, url, width, height,
preserveRatio, smooth);
}
public void defer(Runnable runnable) {
qt.defer(runnable);
}
public void exit() {
qt.exit();
}
public boolean isForwardTraversalKey(KeyEvent e) {
return qt.isForwardTraversalKey(e);
}
public boolean isBackwardTraversalKey(KeyEvent e) {
return qt.isBackwardTraversalKey(e);
}
public Map<Object, Object> getContextMap() {
return qt.getContextMap();
}
public int getRefreshRate() {
return qt.getRefreshRate();
}
public void setAnimationRunnable(DelayedRunnable animationRunnable) {
qt.setAnimationRunnable(animationRunnable);
}
public void requestNextPulse() {
qt.requestNextPulse();
}
public void waitFor(Task t) {
qt.waitFor(t);
}
public void accumulateStrokeBounds(Shape s, float[] b, StrokeType t, double w, StrokeLineCap c, StrokeLineJoin j, float m, BaseTransform tx) {
qt.accumulateStrokeBounds(s, b, t, w, c, j, m, tx);
}
public boolean strokeContains(Shape s, double x, double y, StrokeType t, double w, StrokeLineCap c, StrokeLineJoin j, float m) {
return qt.strokeContains(s, x, y, t, w, c, j, m);
}
public Shape createStrokedShape(Shape s, StrokeType p, double w, StrokeLineCap c, StrokeLineJoin j, float l, float[] d, float o) {
return qt.createStrokedShape(s, p, w, c, j, l, d, o);
}
public Dimension2D getBestCursorSize(int w, int h) {
return qt.getBestCursorSize(w, h);
}
public int getMaximumCursorColors() {
return qt.getMaximumCursorColors();
}
public int getKeyCodeForChar(String c) {
return qt.getKeyCodeForChar(c);
}
public PathElement[] convertShapeToFXPath(Object s) {
return qt.convertShapeToFXPath(s);
}
public HitInfo convertHitInfoToFX(Object hit) {
return qt.convertHitInfoToFX(hit);
}
public Filterable toFilterable(Image img) {
return qt.toFilterable(img);
}
public FilterContext getFilterContext(Object c) {
return qt.getFilterContext(c);
}
public AbstractMasterTimer getMasterTimer() {
return qt.getMasterTimer();
}
public FontLoader getFontLoader() {
return qt.getFontLoader();
}
public TextLayoutFactory getTextLayoutFactory() {
return qt.getTextLayoutFactory();
}
public Object createSVGPathObject(SVGPath s) {
return qt.createSVGPathObject(s);
}
public Path2D createSVGPath2D(SVGPath s) {
return qt.createSVGPath2D(s);
}
public boolean imageContains(Object image, float x, float y) {
return qt.imageContains(image, x, y);
}
public boolean isNestedLoopRunning() {
return qt.isNestedLoopRunning();
}
public boolean isSupported(ConditionalFeature f) {
return qt.isSupported(f);
}
public boolean isAntiAliasingSupported() {
return qt.isAntiAliasingSupported();
}
public TKClipboard getSystemClipboard() {
return qt.getSystemClipboard();
}
public TKSystemMenu getSystemMenu() {
return qt.getSystemMenu();
}
public TKClipboard getNamedClipboard(String name) {
return qt.getNamedClipboard(name);
}
public void startDrag(TKScene s, Set<TransferMode> tm, TKDragSourceListener l, Dragboard d) {
qt.startDrag(SceneImpl.get(s).qs, tm, l, d);
}
public void enableDrop(TKScene s, TKDropTargetListener l) {
qt.enableDrop(SceneImpl.get(s).qs, l);
}
public void registerDragGestureListener(TKScene s, Set<TransferMode> tm, TKDragGestureListener l) {
qt.registerDragGestureListener(SceneImpl.get(s).qs, tm, l);
}
public void installInputMethodRequests(TKScene s, InputMethodRequests requests) {
qt.installInputMethodRequests(SceneImpl.get(s).qs, requests);
}
public ImageLoader loadPlatformImage(Object platformImage) {
return qt.loadPlatformImage(platformImage);
}
public PlatformImage createPlatformImage(int w, int h) {
return qt.createPlatformImage(w, h);
}
public Object renderToImage(ImageRenderingContext p) {
return qt.renderToImage(p);
}
public long getMultiClickTime() {
return qt.getMultiClickTime();
}
public int getMultiClickMaxX() {
return qt.getMultiClickMaxX();
}
public int getMultiClickMaxY() {
return qt.getMultiClickMaxY();
}
protected Object createColorPaint(Color paint) {
throw new UnsupportedOperationException();
}
protected Object createLinearGradientPaint(LinearGradient paint) {
throw new UnsupportedOperationException();
}
protected Object createRadialGradientPaint(RadialGradient paint) {
throw new UnsupportedOperationException();
}
protected Object createImagePatternPaint(ImagePattern paint) {
throw new UnsupportedOperationException();
}
public boolean isFxUserThread() {
return qt.isFxUserThread();
}
public String toString() {
return qt.toString();
}
public void firePulse() {
qt.firePulse();
}
public void addStageTkPulseListener(TKPulseListener l) {
qt.addStageTkPulseListener(l);
}
public void removeStageTkPulseListener(TKPulseListener l) {
qt.removeStageTkPulseListener(l);
}
public void addSceneTkPulseListener(TKPulseListener l) {
qt.addSceneTkPulseListener(l);
}
public void removeSceneTkPulseListener(TKPulseListener l) {
qt.removeSceneTkPulseListener(l);
}
public void addPostSceneTkPulseListener(TKPulseListener l) {
qt.addPostSceneTkPulseListener(l);
}
public void removePostSceneTkPulseListener(TKPulseListener l) {
qt.removePostSceneTkPulseListener(l);
}
public void addTkListener(TKListener l) {
qt.addTkListener(l);
}
public void removeTkListener(TKListener l) {
qt.removeTkListener(l);
}
public void setLastTkPulseListener(TKPulseListener l) {
qt.setLastTkPulseListener(l);
}
public void addShutdownHook(Runnable hook) {
qt.addShutdownHook(hook);
}
public void removeShutdownHook(Runnable hook) {
qt.removeShutdownHook(hook);
}
public void notifyWindowListeners(List<TKStage> windows) {
qt.notifyWindowListeners(windows);
}
public void notifyLastNestedLoopExited() {
qt.notifyLastNestedLoopExited();
}
public InputStream getInputStream(String url, Class base) throws IOException {
return qt.getInputStream(url, base);
}
public boolean getDefaultImageSmooth() {
return qt.getDefaultImageSmooth();
}
public Object getPaint(Paint paint) {
return qt.getPaint(paint);
}
public TKClipboard createLocalClipboard() {
return qt.createLocalClipboard();
}
public void stopDrag(Dragboard dragboard) {
qt.stopDrag(dragboard);
}
public Color4f toColor4f(Color color) {
return qt.toColor4f(color);
}
public ShadowMode toShadowMode(BlurType blurType) {
return qt.toShadowMode(blurType);
}
public KeyCode getPlatformShortcutKey() {
return qt.getPlatformShortcutKey();
}
public void pauseScenes() {
qt.pauseScenes();
}
public void resumeScenes() {
qt.resumeScenes();
}
public void pauseCurrentThread() {
qt.pauseCurrentThread();
}
public Set<HighlightRegion> getHighlightedRegions() {
return qt.getHighlightedRegions();
}
static final class StageImpl implements TKStage {
final TKStage qs;
final Window peer;
final StageImpl owner;
final Modality modality;
boolean isBlocked() {
for (StageImpl w : owners)
if (w == this || w.isDescendantOf(this))
return true;
for (StageImpl w : stageImpls) {
if (w.peer.isShowing()) {
switch (w.modality) {
case APPLICATION_MODAL:
if (w != this && !this.isDescendantOf(w))
return true;
case WINDOW_MODAL:
if (w.isDescendantOf(this))
return true;
default:
}
}
}
return false;
}
StageImpl(TKStage quantumStage, Window peer, TKStage owner, Modality modality) {
if (quantumStage instanceof StageImpl || map.containsKey(quantumStage))
throw new IllegalArgumentException();
this.owner = owner == null ? null : get(owner);
this.modality = modality == null ? Modality.NONE : modality;
map.put(this.qs = Objects.requireNonNull(quantumStage), this);
if (peers.containsKey(peer))
peers.get(peer).dispose();
peers.put(this.peer = Objects.requireNonNull(peer), this);
stageImpls.add(this);
}
boolean isDescendantOf(StageImpl possibleAncestor) {
for (StageImpl stage = owner; stage != null; stage = stage.owner)
if (stage == possibleAncestor)
return true;
return false;
}
private static final HashMap<TKStage, StageImpl> map = new HashMap<>();
private static final HashMap<Window, StageImpl> peers = new HashMap<>();
static final StageImpl get(TKStage stage) {
if (Objects.requireNonNull(stage) instanceof StageImpl)
return (StageImpl) stage;
return Objects.requireNonNull(map.get(stage));
}
static final StageImpl get(Window peer) {
return peers.get(Objects.requireNonNull(peer));
}
public void dispose() {
map.remove(qs);
peers.remove(peer);
stageImpls.remove(this);
}
public void setTKStageListener(TKStageListener listener) {
qs.setTKStageListener(listener);
}
public TKScene createTKScene(boolean depthBuffer, boolean antiAliasing, AccessControlContext acc) {
return new SceneImpl(qs.createTKScene(depthBuffer, antiAliasing, acc));
}
public void setScene(TKScene scene) {
qs.setScene(scene == null ? null : SceneImpl.get(scene).qs);
}
public void setBounds(float x, float y, boolean xSet, boolean ySet, float w, float h, float cw, float ch, float xGravity, float yGravity) {
qs.setBounds(x, y, xSet, ySet, w, h, cw, ch, xGravity, yGravity);
}
public void setIcons(List icons) {
qs.setIcons(icons);
}
public void setTitle(String title) {
qs.setTitle(title);
}
public void setVisible(boolean visible) {
qs.setVisible(visible);
}
public void setOpacity(float opacity) {
qs.setOpacity(opacity);
}
public void setIconified(boolean iconified) {
qs.setIconified(iconified);
}
public void setMaximized(boolean maximized) {
qs.setMaximized(maximized);
}
public void setResizable(boolean resizable) {
qs.setResizable(resizable);
}
public void setImportant(boolean important) {
qs.setImportant(important);
}
public void setMinimumSize(int w, int h) {
qs.setMinimumSize(w, h);
}
public void setMaximumSize(int w, int h) {
qs.setMaximumSize(w, h);
}
public void setFullScreen(boolean f) {
qs.setFullScreen(f);
}
public void requestFocus() {
qs.requestFocus();
}
public void toBack() {
qs.toBack();
}
public void toFront() {
qs.toFront();
}
public void close() {
qs.close();
}
public void requestFocus(FocusCause cause) {
qs.requestFocus(cause);
}
public boolean grabFocus() {
return qs.grabFocus();
}
public void ungrabFocus() {
qs.ungrabFocus();
}
public void requestInput(String text, int type, double width,
double height, double Mxx, double Mxy, double Mxz, double Mxt,
double Myx, double Myy, double Myz, double Myt, double Mzx,
double Mzy, double Mzz, double Mzt) {
qs.requestInput(text, type, width, height, Mxx, Mxy, Mxz,
Mxt, Myx, Myy, Myz, Myt, Mzx, Mzy, Mzz, Mzt);
}
public void releaseInput() {
qs.releaseInput();
}
public void setRTL(boolean b) {
qs.setRTL(b);
}
public void setAccessibilityInitIsComplete(Object ac) {
qs.setAccessibilityInitIsComplete(ac);
}
public Object accessibleCreateStageProvider(AccessibleStageProvider ac) {
return qs.accessibleCreateStageProvider(ac);
}
public Object accessibleCreateBasicProvider(AccessibleProvider ac) {
return qs.accessibleCreateBasicProvider(ac);
}
public void accessibleDestroyBasicProvider(Object a) {
qs.accessibleDestroyBasicProvider(a);
}
public void accessibleFireEvent(Object a, int eventID) {
qs.accessibleFireEvent(a, eventID);
}
public void accessibleFirePropertyChange(Object a, int p, int o, int n) {
qs.accessibleFirePropertyChange(a, p, o, n);
}
public void accessibleFirePropertyChange(Object a, int p, boolean o, boolean n) {
qs.accessibleFirePropertyChange(a, p, o, n);
}
}
static final class SceneImpl implements TKScene {
public final TKScene qs;
public SceneImpl(TKScene quantumScene) {
if (quantumScene instanceof SceneImpl || map.containsKey(quantumScene))
throw new IllegalArgumentException();
map.put(this.qs = Objects.requireNonNull(quantumScene), this);
Method getPlatformView = getMethod(quantumScene.getClass(), "getPlatformView");
View view = (View)invoke(getPlatformView, quantumScene);
view.setEventHandler(new VEHImpl(view.getEventHandler()));
}
private static final HashMap<TKScene, SceneImpl> map = new HashMap<>();
public static final SceneImpl get(TKScene scene) {
if (Objects.requireNonNull(scene) instanceof SceneImpl)
return (SceneImpl) scene;
return Objects.requireNonNull(map.get(scene));
}
public void dispose() {
map.remove(qs);
qs.dispose();
}
public void waitForRenderingToComplete() {
qs.waitForRenderingToComplete();
}
public void waitForSynchronization() {
qs.waitForSynchronization();
}
public void releaseSynchronization(boolean u) {
qs.releaseSynchronization(u);
}
public void setTKSceneListener(TKSceneListener l) {
qs.setTKSceneListener(l);
}
public void setTKScenePaintListener(TKScenePaintListener l) {
qs.setTKScenePaintListener(l);
}
public void setRoot(NGNode root) {
qs.setRoot(root);
}
public void markDirty() {
qs.markDirty();
}
public void setCamera(NGCamera camera) {
qs.setCamera(camera);
}
public NGLightBase[] getLights() {
return qs.getLights();
}
public void setLights(NGLightBase[] lights) {
qs.setLights(lights);
}
public void setFillPaint(Object f) {
qs.setFillPaint(f);
}
public void setCursor(Object cursor) {
qs.setCursor(cursor);
}
public void enableInputMethodEvents(boolean enable) {
qs.enableInputMethodEvents(enable);
}
public void finishInputMethodComposition() {
qs.finishInputMethodComposition();
}
public void entireSceneNeedsRepaint() {
qs.entireSceneNeedsRepaint();
}
public TKClipboard createDragboard(boolean d) {
return qs.createDragboard(d);
}
}
static final class VEHImpl extends EventHandler {
private final EventHandler qh;
public VEHImpl(EventHandler quantumHandler) {
this.qh = quantumHandler;
}
public void handleViewEvent(View view, long time, int type) {
unwrap();
qh.handleViewEvent(view, time, type);
rewrap();
}
public void handleKeyEvent(View view, long time, int action, int keyCode,char[] keyChars, int m) {
qh.handleKeyEvent(view, time, action, keyCode, keyChars, m);
}
public void handleMenuEvent(View view, int x, int y, int xAbs, int yAbs,boolean k) {
qh.handleMenuEvent(view, x, y, xAbs, yAbs,k);
}
public void handleMouseEvent(View view, long time, int type, int button,int x, int y, int xAbs, int yAbs, int m,boolean p, boolean s) {
qh.handleMouseEvent(view, time, type, button, x, y, xAbs,yAbs, m, p, s);
}
public void handleScrollEvent(View view, long time, int x, int y, int xAbs,int yAbs, double deltaX, double deltaY, int m, int lines,int chars, int l, int c, double xm,double ym) {
qh.handleScrollEvent(view, time, x, y, xAbs, yAbs, deltaX, deltaY, m, lines, chars, l, c,xm, ym);
}
public void handleInputMethodEvent(long time, String text, int[] c, int[] a, byte[] v, int cc, int p) {
qh.handleInputMethodEvent(time, text, c, a, v, cc, p);
}
public double[] getInputMethodCandidatePos(int offset) {
return qh.getInputMethodCandidatePos(offset);
}
public void handleDragStart(View view, int button, int x, int y, int xAbs, int yAbs, ClipboardAssistance d) {
qh.handleDragStart(view, button, x, y, xAbs, yAbs, d);
}
public void handleDragEnd(View view, int p) {
qh.handleDragEnd(view, p);
}
public int handleDragEnter(View view, int x, int y, int xAbs, int yAbs, int r, ClipboardAssistance d) {
return qh.handleDragEnter(view, x, y, xAbs, yAbs, r, d);
}
public int handleDragOver(View view, int x, int y, int xAbs, int yAbs, int r, ClipboardAssistance d) {
return qh.handleDragOver(view, x, y, xAbs, yAbs, r, d);
}
public void handleDragLeave(View view, ClipboardAssistance d) {
qh.handleDragLeave(view, d);
}
public int handleDragDrop(View view, int x, int y, int xAbs, int yAbs, int r, ClipboardAssistance d) {
return qh.handleDragDrop(view, x, y, xAbs, yAbs, r, d);
}
public void handleBeginTouchEvent(View view, long time, int m, boolean isDirect, int tc) {
qh.handleBeginTouchEvent(view, time, m, isDirect, tc);
}
public void handleNextTouchEvent(View view, long time, int type, long touchId, int x, int y, int xAbs, int yAbs) {
qh.handleNextTouchEvent(view, time, type, touchId, x, y, xAbs, yAbs);
}
public void handleEndTouchEvent(View view, long time) {
qh.handleEndTouchEvent(view, time);
}
public void handleScrollGestureEvent(View v, long t, int type, int m, boolean d, boolean i, int c, int x, int y, int xAbs, int yAbs, double dx, double dy, double tdx, double tdy, double mx, double my) {
qh.handleScrollGestureEvent(v, t, type, m, d, i, c, x, y, xAbs, yAbs, dx, dy, tdx, tdy, mx, my);
}
public void handleZoomGestureEvent(View v, long t, int type, int m, boolean d, boolean i, int x, int y, int xAbs, int yAbs, double scale, double e, double s, double te) {
qh.handleZoomGestureEvent(v, t, type, m, d, i, x, y, xAbs, yAbs, scale, e, s, te);
}
public void handleRotateGestureEvent(View v, long t, int type, int m, boolean d, boolean i, int x, int y, int xAbs, int yAbs, double dangle, double a) {
qh.handleRotateGestureEvent(v, t, type, m, d, i, x, y, xAbs, yAbs, dangle, a);
}
public void handleSwipeGestureEvent(View v, long t, int type, int m, boolean d, boolean i, int c, int dir, int x, int y, int xAbs, int yAbs) {
qh.handleSwipeGestureEvent(v, t, type, m, d, i, c, dir, x, y, xAbs, yAbs);
}
}
}

interfaces in java - MyClass is not abstract and does not override abstract method eq(Object) in MyClass error

I know there is a Comparable interface, trying to figure out how to write my own.
Here's the interface
public interface MyComparable {
public boolean lt(Object other);
}
and a class that implements it and packages an int (yes, I know there is an Integer class)
public class MyInteger implements MyComparable {
private int value;
public MyInteger(int v)
{ value = v; }
public void set(int v)
{ value = v; }
public int get()
{ return value; }
public boolean lt(MyInteger other)
{ return get() < other.get(); }
}
I get " MyInteger is not abstract and does not override abstract method eq(Object) in MyInteger error". MyComparable doesn't declare an eq method. So it's comping from the superclass but I don't understand.

Instance variables in Java

Please explain the following behaviour.
class Base
{
public int num = 3;
public int getNum()
{
return num;
}
public void setNum(int num)
{
this.num = num;
}
}
class child
extends Base
{
public int num = 4;
public child()
{
}
public child(int i)
{
this.num = i;
}
public int getNum()
{
return num;
}
public void setNum(int num)
{
this.num = num;
}
}
public class Main
{
public static void main(String[] args)
{
Base obj2 = new child();
System.out.println(obj2.num);
System.out.println(obj2.getNum());
Base obj3 = new child(10);
System.out.println(obj3.num);
System.out.println(obj3.getNum());
}
}
Output :
3
4
3
10
Here how obj2.num and obj3.num still point to the value 3 which is assigned in the Base class instance variable. Wont it get overidded like the obj2.getNum() and obj3.getNum().
Thanks in advance.
Because the objects are declared with super class type, you get the super member variable value.
If the object was declared with sub class type, the value would be overridden value.
If the Base obj3 = new child(10); is modified to child obj3 = new child(10); the output would be 3 4 10 10
This is well explained here