Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Java 3D / August 2005

Tip: Looking for answers? Try searching our database.

Java3D: changing appearance of a Box

Thread view: 
Angus Parvis - 22 Jun 2005 22:18 GMT
Hi,

I've written some really ugly code for a game. Basically the game-field
consists of a couple of com.sun.j3d.utils.geometry.Box-objects that are
clicked by the user. Now I figured out how to pick a box, but fail to
change the box's color after it was created.

Here's the code:

public class GameField extends Box {

    public final static Color3f EMPTY = new Color3f(0.1f, 0.2f, 0.3f);

    public final static Color3f TRIED = new Color3f(0.4f, 0.2f, 0.7f);

    public final static Color3f SHIP = new Color3f();

    public final static Color3f SHIP_HIT = new Color3f();

    Game _game;

    Position _position;

    private Player _owner;

    public GameField(Game game, Player owner, Position position) {
        super(1f, 1f, 0.5f, new Appearance());
        setCapability(ENABLE_APPEARANCE_MODIFY);
        setCapability(GEOMETRY_NOT_SHARED);
        Appearance appearance = new Appearance();
        ColoringAttributes coloringAttributes = new ColoringAttributes(EMPTY,
                ColoringAttributes.NICEST);
        appearance.setColoringAttributes(coloringAttributes);
        setAppearance(appearance);

        _game = game;
        _position = position;
        _owner = owner;
    }

    public int hit() throws PositionOutOfBoundsException,
            PositionAlreadyTriedException {
        int state = Battlefield.EMPTY;
        if (_game.getCurrentDefender().equals(_owner)) {
            state = _game.attackPosition(_position);
        }

        if (state == Battlefield.TRIED) {
            System.out.println("tried");
            Appearance appearance = new Appearance();
            ColoringAttributes coloringAttributes = new ColoringAttributes(
                    TRIED, ColoringAttributes.NICEST);
            appearance.setColoringAttributes(coloringAttributes);
            setAppearance(appearance);
        } else if (state == Battlefield.SHIP_HIT) {
            System.out.println("hit!");
        }
        return state;
    }
}

The code works for the constructor where I set the appearance for the
first time, but when i try to change it in the hit-method the app throws
an exception, namely this one:

Exception in thread "AWT-EventQueue-0"
javax.media.j3d.CapabilityNotSetException: Shape3D: no capability to set
appearance
    at javax.media.j3d.Shape3D.setAppearance(Shape3D.java:472)
    at com.sun.j3d.utils.geometry.Box.setAppearance(Box.java:277)
    at battleships.gui3d.GameField.hit(GameField.java:60)
    at battleships.gui3d.PickBoxListener.mouseClicked(PickBoxListener.java:49)
    at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)

The Box-class is based on a Primitive, so I wonder what's that talk
about a Shape3D. Anyway, I want to change the color of this box, I've
been trying some variations of my approach, googled some groups, but
couldn't find a solution.

Please save a poor guy's nerves. If you know how to solve this, please
post your solution. Thx for any help u can offer.

Greetings,

Angus
jack - 22 Jun 2005 22:36 GMT
The exception is asking for the ALLOW_APPEARANCE_WRITE capability.

> Hi,
>
[quoted text clipped - 91 lines]
>
> Angus
Angus Parvis - 22 Jun 2005 23:37 GMT
> The exception is asking for the ALLOW_APPEARANCE_WRITE capability.

As far as I found out the ALLOW_APPEARANCE_WRITE capability can be set
for a Shape3D, the Box I use is a subclass of Primitive, not Shape3D.

Any suggestion how to solve this using the Box?

Greetings,

Angus
Ralf Ullrich - 04 Aug 2005 15:42 GMT
>         setCapability(ENABLE_APPEARANCE_MODIFY);
>         setCapability(GEOMETRY_NOT_SHARED);

ENABLE_APPEARANCE_MODIFY and GEOMETRY_NOT_SHARED aren't capability flags.

They have to be provided to the Box constructor to have any effect.

cu


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.