Skip to main content
gamedev.net
🔒 Locked

[java] Java Fullscreen Mode and Key Down event

Started by dannyxyz23 Jan 3, 2003 at 10:47 PM 1 replies 600+ views
Original Post
dannyxyz23
dannyxyz23
Hello, I read a trail help in Sun''s site about using FullScreen in Java, and I used a lot of methods I am not familiarized to, so, when I tried to use the public boolean keyDown(Event e, int key), as used in the applets, I got no response for the keydown event. I wonder this happens because there`s no call to this event in the main() of the program. So I thought of using the System.in.read() routine to collect keydown presses, but it wasn''t successful, since it need to hit the Enter key to start processing the events... My questions are: 1- HOW DO I GET KEYPRESSES IN A STANDALONE APP IN JAVA and 2- HOW WILL I BE ABLE TO USE A SIMILAR PAINT() ROUTINE IN THIS FULLSCREEN MODE. 3- Can I REALLY get high-performance graphics and fast answers for my keyboard presses this way? Or should I go back to C/C++? links to tutorials will be very much welcome, also. ps. my program code was something like this: public class Full { p s void main() { frame my_window; initialize my_window...; get devices, graphics and stuff; set fullscreen mode; } public boolean keyDown(Event e,int key) { do something...; } } THANK YOU ALL Daniel Happy New Year, everybody!
iCERAiN
iCERAiN
In Application you should you the KeyListener, the code also uses the pait method (with doublebuffering^^). Use ESC to exit this little program.
I hope this code helps:

import java.awt.*;
import java.awt.event.*; // keylistener
import java.awt.image.*; // volatileimage

public final class Test extends Frame
{
private Graphics dbg;
private VolatileImage dbImage;

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

public Test()
{
addKeyListener(new myKeyListener());

GraphicsDevice myDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode oldMode = myDevice.getDisplayMode();
DisplayMode newMode = new DisplayMode(640, 480, 16, oldMode.getRefreshRate());

if(myDevice.isFullScreenSupported()) {
try {
this.setVisible(false);
this.dispose();
this.setUndecorated(true);
myDevice.setFullScreenWindow(this);
myDevice.setDisplayMode(newMode);
}
catch (Exception e) {
myDevice.setDisplayMode(oldMode);
}
} else {
System.out.println("Sorry No Fullscreen");
System.exit(0);
}
}

/** Doublebuffer */
public final void update(Graphics g)
{
if (dbImage == null || dbImage.validate(getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) {
dbImage = createVolatileImage(this.getSize().width, this.getSize().height);
dbg = dbImage.createGraphics();
}
paint(dbg);
g.drawImage(dbImage, 0, 0, this);
}

public void paint(Graphics g)
{
g.drawString("Hello World", 100, 100);
}

public void mainloop()
{
while(true) {
repaint();
}
}

class myKeyListener implements KeyListener
{
public void keyPressed(java.awt.event.KeyEvent keyEvent)
{
int keyCode = keyEvent.getKeyCode();

switch (keyCode) {
case KeyEvent.VK_ESCAPE:
System.exit(0);
break;
}
}

public void keyReleased(java.awt.event.KeyEvent keyEvent)
{
}

public void keyTyped(java.awt.event.KeyEvent keyEvent)
{
}

} // class myKeyListener
}


Highperformance graphics hmm no idea, I''m trying to make a IsoTileEngine but I have more trouble with the tile engine then with java. But as far as I''m now the frame rates let me hope. It''s time to show the world what ya can do with Java^^

role
role
thanx iCERAiN

i got a lot of question in :

http://www.gamedev.net/community/forums/topic.asp?topic_id=131302

plz answer it, thanx

make me sick!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.