#235 using a GUI Swing type style of Java

open
nobody
None
5
2005-07-28
2005-07-28
Nigel
No

Let's see if I can get my preferred result from a GUI
Swing type style:

> cat t92.java
class A1 {
public String out() {
return "Nigel is best";
}
}

abstract class Nigel {

A1 a;
String str;

public Nigel(A1 a) {
this.a = a;
}

public String toString() {
return str;
}

public abstract void set();
}

class t92 {

public t92(Nigel x) {
x.set();
System.out.println(x);
}

public static void main(String[] args) {
A1 a = new A1();
t92 t92 = new t92(
new Nigel(a) {
public void
set() {

str = a.out();
}
});
}
}
Process cat exited with code 0

Compiling and running with java produces my favourite
result:

> javac t92.java
Process javac exited with code 0
> java t92
Nigel is best
Process java exited with code 0

BeanShell takes exception:

> java -classpath /opt/bsh-2.0b5.jar bsh.Interpreter
t92.java
Class: class t92 main method threw exception:Typed
variable declaration : Error constructing inner class
instance: bsh.ReflectError: Can't find constructor: main$1
( A1 ) in class: main$1 : at Line: 39 : in file: t92.java :
new Nigel ( a ) {

Called from method: main : at Line: -1 : in file: <Called
from Java Code> : <Compiled Java Code>
Process java exited with code 0

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks