Computer Science Canada

JFrame help

Author:  LiquidDragon [ Wed Jul 07, 2004 9:03 am ]
Post subject:  JFrame help

I am very new to java and it is very confusing. I started first with turing and now im onto java so i took this course. One of our labs was to create a program to maximize the size of the frame and put it at the top of the screen.

Here is what i have so far.

code:

/**
 * A JFrame that can double in width.
 */

import javax.swing.*;
import java.awt.*;

public class MaxWindow extends JFrame {
   
  Dimension d= Toolkit.getDefaultToolkit().getScreenSize();
  int screenWidth= (int) d.getWidth();
  int screenHeight= (int) d.getHeight();
 
  public MaxWindow(String t) {
    super (t);
  }
 
  public MaxWindow() {
    // this automatically calls super().
  }
 
  public void maxWidth() {
    setSize (screenWidth, getHeight());
  }
 
  public void maxHeight() {
 
  }
}


NOTE: I am using DrJava to write and test all this. Any help would be great.

Author:  rizzix [ Wed Jul 07, 2004 9:00 pm ]
Post subject: 

ur trying to make a fullscreen window right?.. heh ask Dan, i know he did it for his FP.

Author:  Dan [ Wed Jul 07, 2004 9:40 pm ]
Post subject: 

i do not think that is what he whonts, b/c he side maximised like the window mode. but i will post the fullscreen code just the same:

class from my FP that dose fullscreen:

code:

import java.awt.*;
import javax.swing.*;

/**
 *a fullscreen frame to be used for the game
 *@author Dan
 */
public class QFTBFrame extends JFrame
{       
        private GraphicsEnvironment env;
        private GraphicsDevice device;
        private boolean isFullScreen;
       
        /**
         *a new frame that will be fullscreen if the system suports it
         */
        public QFTBFrame()
        {
                super();
               
                env = GraphicsEnvironment.getLocalGraphicsEnvironment();
                device = env.getDefaultScreenDevice();
               
                isFullScreen = device.isFullScreenSupported();

                if(isFullScreen)
                {
                        setUndecorated(true);
                setResizable(false);
            device.setFullScreenWindow(this);
                }
                else
                {
                        setUndecorated(false);
                setResizable(true);
                        System.out.println("Error: your system dose not sport fullscreen, trying normal size...");
                }
        }
       
        /**
         *should take the system out of fullscreen mode (untested)
         */
        public void end()
        {
                if(isFullScreen)
                {
                        device.setFullScreenWindow(null);
                }
        }
}



fullscreen is a bit bugy esepltay when using it with GUIs like awt and swing and it dose not work on all systems.

Author:  LiquidDragon [ Thu Jul 08, 2004 5:51 pm ]
Post subject: 

It's not the fullscreen i want. I need to write a class that has a method that can maximize the width and another method to maximize the height. We are learning all this in a class im taking but i find java very confusing.

Author:  LiquidDragon [ Fri Jul 09, 2004 7:24 pm ]
Post subject: 

It's ok now. I got some guy at U of T to help me Wink

Author:  Delta [ Sat Jul 24, 2004 8:24 am ]
Post subject: 

Care to post your solution so if others have this problem it's already answered?

Author:  LiquidDragon [ Sat Jul 24, 2004 5:33 pm ]
Post subject: 

I dont remember the problem anymore Embarassed


: