Results 1 to 3 of 3
- 05-31-2012, 06:12 PM #1
Senior Member
- Join Date
- Apr 2012
- Posts
- 115
- Rep Power
- 0
problems with outputting to screen
I've started the newboston java gmae developement tutorials and I have a problem, I've set the background to PINK but whenever I run it its actually black. can someone give an explaination and possible fix for why this might be the case?
Java Code:package gameDevelopement; import java.awt.*; import javax.swing.JFrame; public class Game extends JFrame { public void run(DisplayMode dm) { // set window properties setBackground(Color.PINK); setForeground(Color.WHITE); setFont(new Font("Arial", Font.PLAIN, 24)); // screen variable to use screen methods Screen screen = new Screen(); try { // set full screen screen.setFullScreen(dm, this); try { // do nothing for 5 secs Thread.sleep(5000); } catch(Exception ex) { } } finally { // after 5 secs return to regular size screen.restoreScreen(); } } public void paint(Graphics g) { // whenever you make a JFrame it calls the paint method automatically g.drawString("This is gonna be awesome", 200, 200); } public static void main(String[] args) { // in order to use displayMode method we need a display mode object DisplayMode dm = new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN); // we need an object of this class for run method Game game = new Game(); game.run(dm); } }Java Code:package gameDevelopement; import java.awt.*; import javax.swing.JFrame; public class Screen { //gives interface to graphics card private GraphicsDevice gc; public Screen() { //env contains all your graphics device objects GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); //gives access to computer screen gc = env.getDefaultScreenDevice(); } // convert window to full screen // DisplayMode contains 4 parameters (screen res x, screen res y, bit depth, refresh rate) public void setFullScreen(DisplayMode dm, JFrame window) { //no tool bars window.setUndecorated(true); //can not be resized window.setResizable(false); //converts window to full screen gc.setFullScreenWindow(window); // if graphics card is able to display those settings if( dm != null && gc.isDisplayChangeSupported()) { try { gc.setDisplayMode(dm); } catch(Exception ex) { } } } public Window getFullScreenWindow() { return gc.getFullScreenWindow(); } // return screen to normal public void restoreScreen() { Window w = gc.getFullScreenWindow(); // if the window contains something if( w != null ) { // free resources w.dispose(); } // takes anything away from full screen gc.setFullScreenWindow(null); } }Legend has it the moderators and senior members of java-forums.org were able to code skyrim using only 701 lines of java... or so the legend goes.
- 05-31-2012, 06:20 PM #2
Re: problems with outputting to screen
Read the API for JRootPane, which is the single child of a JFrame container (also see the API for the interface RootPaneContainer) and you'll easily see why.I've set the background to PINK but whenever I run it its actually black.
Don't try doing any fancy stuff directly in the content area of any top level window. Base your GUI on a JPanel (or in comparatively rare cases, on another subclass of JComponent) and either add(...) that to the top level window or set it as the top level window's content pane.
Additionally, please post in an appropriate section. I'm moving this to AWT/Swing
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-31-2012, 07:02 PM #3
Senior Member
- Join Date
- Apr 2012
- Posts
- 115
- Rep Power
- 0
Re: problems with outputting to screen
I cant make that kind of judgement call, because swing topics can also be a subset of new to java.
this is bugging me
I dont understand this... it looks like I've just created a variable w and immediately destroyed it? why... surely w would be a copy of the screen output but not the actual one thats executing.Java Code:public void restoreScreen() { Window w = gc.getFullScreenWindow(); // if the window contains something if( w != null ) { // free resources w.dispose(); } // takes anything away from full screen gc.setFullScreenWindow(null); }
wouldnt this be all I need?
gc.setFullScreenWindow(null);Legend has it the moderators and senior members of java-forums.org were able to code skyrim using only 701 lines of java... or so the legend goes.
Similar Threads
-
help with buttons and outputting to a file
By tom2zip in forum New To JavaReplies: 1Last Post: 11-09-2011, 04:21 AM -
outputting different letters in different colours
By Sarah24 in forum Java AppletsReplies: 4Last Post: 03-02-2011, 02:32 PM -
Outputting a * triangle
By blackbeltsas in forum New To JavaReplies: 1Last Post: 10-17-2010, 11:39 AM -
Full screen problems
By doctorned in forum New To JavaReplies: 4Last Post: 12-10-2009, 09:40 AM -
Screen Resolution Problems
By RicKaufman in forum AWT / SwingReplies: 1Last Post: 10-04-2009, 06:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks