Not able to set background

+1 sukhman singh · May 9, 2015
I am not able to set the background  color in DispalyMode method. The String is working fine. It is the fifth tutorial  in java game development.

Post a Reply

Replies

Oldest  Newest  Rating
+2 Sharon Fabin · May 9, 2015
please post your code
0 sukhman singh · May 10, 2015
//Screen class

import javax.swing.JFrame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.Window;


public class g03 {

private GraphicsDevice vc;   


public g03(){

GraphicsEnvironment env=GraphicsEnvironment.getLocalGraphicsEnvironment();
vc=env.getDefaultScreenDevice();                                          
}
public void setFullScreen(DisplayMode dm,JFrame window){ 
                                    
window.setUndecorated(true);               
window.setResizable(false);                
vc.setFullScreenWindow(window);            


    if(dm!=null && vc.isDisplayChangeSupported()){ 
    try{
    vc.setDisplayMode(dm);
    }catch(Exception ex){}
    }}
public Window getFullScreenWindow(){
return vc.getFullScreenWindow();
}


public void restoreScreen(){                     
Window w= vc.getFullScreenWindow();
if(w!=null){
w.dispose();                             
}  
vc.setFullScreenWindow(null);                 

}
0 sukhman singh · May 10, 2015
//Bucky class

import java.awt.DisplayMode;
import java.awt.Color;
import javax.swing.JFrame;
import java.awt.*;


public class g05 extends JFrame{
public static void main(String args[]){
DisplayMode dm=new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN );
    g05 b=new g05();                         
    b.run(dm);
}
public void run(DisplayMode dm){
setBackground(Color.PINK);
    setForeground(Color.RED);
    setFont(new Font("Arial",Font.PLAIN,24));

g03 s=new g03();
try{
s.setFullScreen(dm,this);                
try{
Thread.sleep(5000);                  
}catch(Exception ex){}
    }finally{
    s.restoreScreen();
    }}
    
    public void paint(Graphics g){                       
        g.drawString("This is gona be awesome", 200, 200);
        
    }




}
0 sukhman singh · May 14, 2015
Please, Someone help me with this code. I am stuck at this point. Can't move futher in java game development. 
  • 1

Java / Android Development

107,090 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator