Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

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)).

Programming

So I got a JFrame app the other day for a plugin on a program. I found out how to change variable values in a text file without a recompile of the java class. Here it is (I did not include the preliminary java declarations/import classes, but they must also be included as usual).




The var declare portion of app.java file

Static int varName = Integer.parseInt(readData("config.txt", "WindowWidth"));



The config.txt file

WindowWidth = 205


After compiling the java file (cmd "javac app.java"), you will be able to change the initial value of varName by changing the value of WindowWidth in the text file. It works great!!