Building a java class for Vassal ... I am blind

Hi,

I am trying to build a java module extension. I have written the following, which is basically just a bunch of empty methods and placeholders …

[b][size=85]/*
Testing.java

Test module for Vassal.
See if I can make a class and import it.
*/

package VASSAL.build.module.map.boardPicker.board.mapgrid;

import VASSAL.build.Buildable;
import VASSAL.build.module.map.boardPicker.board.HexGrid;
import VASSAL.build.AutoConfigurable;
import VASSAL.configure.StringEnum;

import java.awt.Point;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Rectangle;

public class Testing extends RegularGridNumbering {

private HexGrid grid;
private char param = ‘F’;

public void addTo(Buildable parent) {
grid = (HexGrid) parent;
grid.setGridNumbering(this);
}

public static final String PARAM = “param”;

public HexGrid getGrid() {
return grid;
}

public static class A extends StringEnum {
public String[] getValidValues(AutoConfigurable target) {
return new String[]{“First”, “Second”};
}
}

public String[] getAttributeDescriptions() {
String[] s = super.getAttributeDescriptions();
String[] val = new String[s.length + 1];
System.arraycopy(s, 0, val, 0, s.length);
val[s.length] = “Paramter?”;
return val;
}

public String[] getAttributeNames() {
String[] s = super.getAttributeNames();
String[] val = new String[s.length + 1];
System.arraycopy(s, 0, val, 0, s.length);
val[s.length] = PARAM;
return val;
}

public Class<?>[] getAttributeTypes() {
final Class<?>[] s = super.getAttributeTypes();
final Class<?>[] val = new Class<?>[s.length + 1];
System.arraycopy(s, 0, val, 0, s.length);
val[s.length] = A.class;
return val;
}

public void setAttribute(String key, Object value) {
if (PARAM.equals(key)) {
param = ((String) value).charAt(0);
}
else {
super.setAttribute(key, value);
}
}

public String getAttributeValueString(String key) {
if (PARAM.equals(key)) {
return String.valueOf(param);
}
else {
return super.getAttributeValueString(key);
}
}

/* Important overrides */
@Override
public Point getCenterPoint(int col, int row) {

Point p = new Point();

p.x = p.y = 0;
return p;

}

public int getColumn(Point p) {
return 0;
}

public int getRow(Point p) {
return 0;
}

public void removeFrom(Buildable parent) {
grid.setGridNumbering(null);
}

protected JComponent getGridVisualizer() {
visualizer = new JPanel() {
} ;
return visualizer;
}

public void draw(Graphics g, Rectangle bounds, Rectangle visibleRect, double scale, boolean reversed) {
}

public static void main(String[] args) {
}

}
[/size][/b]

I built this into a class using the online java compiler at innovation.ch/java/java_compile.htm.

And I then have some compiled files, which I place in a folder called “testing” like this …

[size=85]bash-4.1$ ls testing/ -lrta
total 3072
-rw-r–r-- 1 scottp scottp 2800 2012-03-13 11:51 Testing.class
-rw-r–r-- 1 scottp scottp 519 2012-03-13 11:51 Testing$A.class
-rw-r–r-- 1 scottp scottp 580 2012-03-13 11:51 Testing$1.class
drwx------ 2 scottp scottp 0 2012-03-13 11:56 .
drwx------ 5 scottp scottp 0 2012-03-13 12:02 …
bash-4.1$
[/size]

I place this folder into my test module zip archive (Test Module.vmod), so that the structure is …

[b][size=85]bash-4.1$ unzip -l “Test Module.vmod”
Archive: Test Module.vmod
Length Date Time Name


 4689  03-12-2012 23:10   buildFile
  264  03-12-2012 23:10   moduledata

2112793 03-12-2012 23:10 images/Map.png
0 03-13-2012 11:56 testing/
2800 03-13-2012 11:51 testing/Testing.class
580 03-13-2012 11:51 testing/Testing$1.class
519 03-13-2012 11:51 testing/Testing$A.class


2121645 7 files
bash-4.1$[/size][/b]

And then I open the module in Vassal, and go to the Main Map > Map Boards > Board > Hex Grid, and try to import my class. I have tried various names include testing.Testing, and other combinations of. I even tried placing the class files in the root folder of the Module etc. None work. If it cannot find the class file it says so, but when I use testing.Testing I get the following error …

[size=85]java.lang.NoClassDefFoundError: testing/Testing (wrong name: VASSAL/build/module/map/boardPicker/board/mapgrid/Testing)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at VASSAL.tools.DataArchive.findClass(DataArchive.java:372)
at VASSAL.tools.DataArchive.loadClass(DataArchive.java:348)
at java.lang.ClassLoader.loadClass(Unknown Source)
at VASSAL.configure.ConfigureTree.importConfigurable(ConfigureTree.java:804)
at VASSAL.configure.ConfigureTree$5.actionPerformed(ConfigureTree.java:452)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
[/size]

I gather it must be something very simple and fundamental, but I am C, TCL and Embedded Control engineer not a Java programmer, and to be honest I have no desire to be, I am just trying to get some simple tasks done in Vassal without spending too many hours. Can someone please shine some light on my blindness.

Kind regards,
Scott Pitcher

Thus spake anonemous123:

Hi,

I am trying to build a java module extension. I have written the
following, which is basically just a bunch of empty methods and
placeholders …

The combination of these two things is your problem:

package VASSAL.build.module.map.boardPicker.board.mapgrid;

And I then have some compiled files, which I place in a folder called
“testing” like this …

You’re declaring the class Testing to be in the
VASSAL.build.module.map.boardPicker.board.mapgrid package, when it is in
fact in the testing package. Try this instead:

package testing;


J.

Hi,

Thanks for the reply. I made the change and now I get these compile errors …

[size=85]/tmp/jc_13589/Testing.java:21: cannot find symbol
symbol: class RegularGridNumbering
public class Testing extends RegularGridNumbering {
^
/tmp/jc_13589/Testing.java:28: setGridNumbering(VASSAL.build.module.map.boardPicker.board.mapgrid.GridNumbering) in VASSAL.build.module.map.boardPicker.board.HexGrid cannot be applied to (testing.Testing)
grid.setGridNumbering(this);
^
/tmp/jc_13589/Testing.java:46: cannot find symbol
symbol : variable super
location: class testing.Testing
String[] s = super.getAttributeDescriptions();
^
/tmp/jc_13589/Testing.java:54: cannot find symbol
symbol : variable super
location: class testing.Testing
String[] s = super.getAttributeNames();
^
/tmp/jc_13589/Testing.java:62: cannot find symbol
symbol : variable super
location: class testing.Testing
final Class[] s = super.getAttributeTypes();
^
/tmp/jc_13589/Testing.java:74: cannot find symbol
symbol : variable super
location: class testing.Testing
super.setAttribute(key, value);
^
/tmp/jc_13589/Testing.java:83: cannot find symbol
symbol : variable super
location: class testing.Testing
return super.getAttributeValueString(key);
^
/tmp/jc_13589/Testing.java:88: method does not override a method from its superclass
@Override
^
/tmp/jc_13589/Testing.java:110: cannot find symbol
symbol : variable visualizer
location: class testing.Testing
visualizer = new JPanel() {
^
/tmp/jc_13589/Testing.java:112: cannot find symbol
symbol : variable visualizer
location: class testing.Testing
return visualizer;
^
10 errors
[/size]

A lot of unresolved symbols here!

lol

Scott

I just answered my own question. I compiled the files again with …

[size=85]package VASSAL.build.module.map.boardPicker.board.mapgrid;[/size]

… then I moved the compiled class files into a directory structure like this …

[b][size=85]bash-4.1$ tree
.
|-- AllClasses.tar.gz
|-- ObliqueHexGridNumbering.java
|-- ObliqueHexGridNumbering.java~
|-- Test Module.vmod
|-- Testing-AllClasses.tar.gz
|-- Testing.java
|-- Testing.java~
|-- VASSAL
| -- build | – module
| -- map | – boardPicker
| -- board | – mapgrid
| |-- Testing$1.class
| |-- Testing$A.class
| -- Testing.class – testing

8 directories, 10 files
bash-4.1$
[/size][/b]

… Oh it doesn’t show up too well, but that folder is VASSAL/build/module/map/boardPicker/board/mapgrid …

… and I then placed the VASSAL folder and all it’s contents including the Testing*.class files into the module, then I tried to import VASSAL.build.module.map.boardPicker.board.mapgrid.Testing, and it worked! In the Grid Numbering dialog I see my “Parameter?” option at the bottom of the dialog.

Is there a better way of doing this, without the directory structure?

Scott

Thus spake anonemous123:

Hi,

Thanks for the reply. I made the change and now I get these compile
errors …

__/tmp/jc_13589/Testing.java:21: cannot find symbol
symbol: class RegularGridNumbering
public class Testing extends RegularGridNumbering {
^

Are you importing RegularGridNumbering now that your class is no longer
in the same package with it? I’ll bet you’re not.


J.


messages mailing list
messages@vassalengine.org
vassalengine.org/mailman/listinfo/messages

Ah that worked.

[b][size=85]/*
Testing.java

Test module for Vassal.
See if I can make a class and import it.

Import as imports.Testing

*/

package imports;

import VASSAL.build.Buildable;
import VASSAL.build.module.map.boardPicker.board.HexGrid;
import VASSAL.build.module.map.boardPicker.board.mapgrid.RegularGridNumbering;

import VASSAL.build.AutoConfigurable;
import VASSAL.configure.StringEnum;

import java.awt.Point;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Rectangle;

public class Testing extends RegularGridNumbering {
…[/size][/b]

Thanks :slight_smile: