Add to Google Reader or Homepage

jframe fullscreen

How to set JFrame to fullscreen


To set the size of the frame to full screen, you should have knowledge about the screen size of your laptop,PC. But you cannot ensure that the frame size will cover the entire screen on an other device,since screen size of the devices may vary.

In order to get rid of this problem Abstract Window Toolkit library has been provided.It enables you to calculate the screen size of the current device.

See the following program which will create a frame that covers the full-screen and it will work fine on any PC or laptop.

Program:

 

Myframe.java

import javax.swing.*;
import java.util.*;
class Myframe
{
public static void main(String args[])
{
Firstframe f1=new Firstframe();
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.setVisible(true);
}
}
 


Firstframe.java

  
import javax.swing.*;
import java.util.*;
import java.awt.*;
class Firstframe extends JFrame
{
Firstframe()
{
Toolkit k=Toolkit.getDefaultToolkit();
Dimension scr=k.getScreenSize();
int swidth=(int)scr.getWidth();
int sheight=(int)scr.getHeight();
setSize(swidth,sheight);
setTitle("My FirstFrame");
}
}



0 comments:

Post a Comment

 
java errors and exceptions © 2010 | Designed by Chica Blogger | Back to top