Hi Dreamtime
I made the game window appeared. It repeated every time I ran 32 bit or 64 bit - exe. Though I’ve seen no console output when running the exe. It’s appearing only when i simply run the jar.
It happened after I modified the sources:
Game.java:
package game;
import javax.swing.*;
import java.awt.*;
public class Game
{
Draw draw;
Frame frame;
Insets insets;
boolean isRunning = true;
private int FPS = 30;
private double averageFPS;
public static void main( String[] args )
{
System.out.println( "Hello! "+ Thread.currentThread() );
Game game = new Game();
game.run();
//
// System.exit( 0 );
}
void run()
{
final Runnable doHelloWorld = new Runnable()
{
public void run()
{
System.out.println( "Hello World on " + Thread.currentThread() );
}
};
Thread appThread = new Thread()
{
public void run()
{
try
{
SwingUtilities.invokeLater( doHelloWorld );
initialize();
long startTime;
long URDTimeMillis;
long waitTime;
long totalTime = 0;
int frameCount = 0;
int maxFrameCount = 30;
long targetTime = 1000 / FPS;
while ( isRunning )
{
startTime = System.nanoTime();
update();
draw();
URDTimeMillis = ( System.nanoTime() - startTime ) / 1000000;
waitTime = targetTime - URDTimeMillis;
try
{
Thread.sleep( waitTime );
}
catch ( Exception e )
{
}
totalTime += System.nanoTime() - startTime;
frameCount++;
if ( frameCount == maxFrameCount )
{
averageFPS = 1000.0 / ( ( totalTime / frameCount ) / 1000000 );
frameCount = 0;
totalTime = 0;
}
}
frame.close();
}
catch ( Exception e )
{
e.printStackTrace();
}
System.out.println( "Finished on " + Thread.currentThread() );
}
};
appThread.start();
}
void initialize()
{
draw = new Draw();
frame = new Frame();
frame.add( draw );
}
void update()
{
}
void draw()
{
System.out.println( "Game running on " + Thread.currentThread() );
//frame.draw();
}
}
Frame.java:
package game;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Frame extends JFrame
{
int windowWidth = 960;
int windowHeight = 480;
Insets insets;
public Frame()
{
setTitle( "Game" );
setSize( windowWidth, windowHeight );
setResizable( false );
// setDefaultCloseOperation( EXIT_ON_CLOSE );
setDefaultCloseOperation( DO_NOTHING_ON_CLOSE );
addWindowListener( new WindowAdapter()
{
/**
* Invoked when a window is in the process of being closed.
* The close operation can be overridden at this point.
* @param e
*/
@Override
public void windowClosing( WindowEvent e )
{
System.out.println( "Good Bye World on " + Thread.currentThread() );
System.exit( 0 );
}
} );
insets = getInsets();
setSize( insets.left + windowWidth + insets.right, insets.top + windowHeight + insets.bottom );
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
setLocation( dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2 );
setVisible( true );
}
public void close()
{
setVisible( false );
}
}
I modified also jwrapper.xml a bit but I think it does no affect the result in fact because I’ve ran the xml with initial build without the success.