i need windowed and not fullscreen

i can run fullscreen fast java gfx with example from Developing Games in Java - David Brackeen
this is good
but i can’t make it windowed
this is bad

Developing Games in Java - David Brackeen


import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class AnimationTest2 {

    public static void main(String args[]) {
        AnimationTest2 test = new AnimationTest2();
        test.run();
    }

    private static final DisplayMode POSSIBLE_MODES[] = {
        new DisplayMode(800, 600, 32, 0),
        new DisplayMode(800, 600, 24, 0),
        new DisplayMode(800, 600, 16, 0),
        new DisplayMode(640, 480, 32, 0),
        new DisplayMode(640, 480, 24, 0),
        new DisplayMode(640, 480, 16, 0)
    };

    private static final long DEMO_TIME = 10000;

    private ScreenManager screen;
    private Image bgImage;
    private Animation anim;


    public void loadImages() {
        // load images
        bgImage = loadImage("images/background.jpg");
        Image player1 = loadImage("images/player1.png");
        Image player2 = loadImage("images/player2.png");
        Image player3 = loadImage("images/player3.png");

        // create animation
        anim = new Animation();
        anim.addFrame(player1, 250);
        anim.addFrame(player2, 150);
        anim.addFrame(player1, 150);
        anim.addFrame(player2, 150);
        anim.addFrame(player3, 200);
        anim.addFrame(player2, 150);
    }


    private Image loadImage(String fileName) {
        return new ImageIcon(fileName).getImage();
    }


    public void run() {
        screen = new ScreenManager();
        try {
            DisplayMode displayMode =
                screen.findFirstCompatibleMode(POSSIBLE_MODES);
            screen.setFullScreen(displayMode);
            //JFrame jf = screen.getFullScreenWindow();
            //screen.restoreScreen();
            loadImages();
            animationLoop();
        }
        finally {
            screen.restoreScreen();
        }
    }


    public void animationLoop() {
        long startTime = System.currentTimeMillis();
        long currTime = startTime;

        while (currTime - startTime < DEMO_TIME) {
            long elapsedTime =
                System.currentTimeMillis() - currTime;
            currTime += elapsedTime;

            // update animation
            anim.update(elapsedTime);

            // draw and update screen
            Graphics2D g = screen.getGraphics();
            draw(g);
            g.dispose();
            screen.update();

            // take a nap
            try {
                Thread.sleep(20);
            }
            catch (InterruptedException ex) { }
        }

    }


    public void draw(Graphics g) {
        // draw background
        g.drawImage(bgImage, 0, 0, null);

        // draw image
        g.drawImage(anim.getImage(), 0, 0, null);
    }

}

removing “screen.setFullScreen(displayMode);” doesn’t help
“screen.restoreScreen();” doesn’t help too

i missed u like a desert miss a rainbow
hedgehogs r good
but not u
in my life i had 2 or maybe 3 hedgehogs

yeah i am lazy
so what
and not just i am lazy to dig the shit
i usually think that if i created things like libraries i would provide a nice simple and working example
with no need to dig the things by myself
btw i wrote pretty cool and short java tutorial for total newbs in russian

you youngsters may not know but m77 actually has skill, he made like pseudo 3d shooters and stuff

as to your question m77, it has been way too long since I used Java2D
you say

[quote]removing “screen.setFullScreen(displayMode);” doesn’t help
[/quote]
Surprises me… without that there is no command to initiate any screen change… but I dont know what the screenmanager does at all

SwordsMiner i have a problem that u r a gamer
but i have even more problem with the fact that u r not my facebook follower
even more
u do not do stuffs with me

  • u r 2 young and i don’t like your look and voice

In that book, Brackeen explicitly decided to cover full-screen games and not windowed mode. He writes about the decision to do so on page 23 of my copy.

If there is going to be a way to fiddle with his code to make it windowed, I think it will be part of the class ScreenManager (referenced in this program sample). I took a look at it, but would have to do some digging (e.g., check definitions of GraphicsDevice, GraphicsEnvironment for starters) to say exactly if and how one could alter the code to make it work for windowed mode. It might be doable.

But if you want to have the animation display in a window, maybe just using a JPanel or JComponent for the display screen makes more sense. As far as I know, most of the “high speed” benefits of using his ScreenManager go away if you decide to put the game in a windowed mode. Maybe animating via Graphics2D and Swing/AWT would be sufficient.

The go-to libraries for high speed graphics these days seems to be LWJGL, and LibGDX which relies on LWJGL wrapper to OpenGL. These can be made to work in a windowed environment.

P.S. You used to have a Milla Jojovich avatar, yes? I’m curious where that photo came from. Was it one of her movies? (Which one?) I’ve recently become a fan.

P.P.S. Congratulations on recent alcohol avoidance reported on another thread.

already got throw
just found some simple and working another example

Link? [Filler text so that this is not 90%+ a quote]

The posts about m77 are unnecessary, try talking about the question instead. I’ll move the first couple posts to chitchat later.

M77 has also made several posts unrelated to the topic, but they remain in the thread. But maybe they were warranted or something, but its really hard to follow this thread.

He was responding to the posts that I moved to chitchat.

If you show me the screen manager, I’ll get a solution up for you :wink:

http://www.brackeen.com/javagamebook/#download

It’s in chapter 2.