jFrame

A JFrame is a little more than just a regular java app. You must extend and import a bunch of graphics classes included with JDK. To do this you need the following:

import java.io.*;
import java.net.*;
import java.awt.*;
import java.util.StringTokenizer;
import javax.swing.*;
import javax.swing.border.*;
public class ClassName extends JFrame {
    static Container c;
    static JFrame x;
    static Int Config_Width;
    static Int Config_Height;
    static Int WindowX;
    static Int WindowY;
    public static void main(String[] args) throws IOException {

        x = new ClassName();
        x.setSize(config_width, config_height);
        x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        x.setResizable(false);
        x.setAlwaysOnTop(true);
        x.setVisible(true);
        x.setLocation(windowX, windowY);
    }
}

Here is a small list of JFrame variables and what they do:

  • SetSize(config_width, config_height); – changes the size of the window
  • setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); – I believe this adds the close button on the upper right corner.
  • setResizeable(true/false); – can you drag the window edges to resize it?
  • setAlwaysOnTop(true/false); – basically a “pin window” command, making it on top of everything else, even if it is out of focus.
  • setVisible(true/false); – is the window visible? It can exist, but it doesn’t have to actually work.
  • setLocation(windowX, windowY); – sets the initial position of the upper left-hand corner of the window with respect to the upper left-hand corner of the monitor (starting at (0,0)).

Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *