Java GUIs

LBJuice

n00b
Joined
Jan 23, 2005
Messages
27
I really like the Visual Studio Framework. I'm building a java application and I want my gui to be in a class called "Form" and I want my main method to be in a class "Program" so I can write a simple line of coding saying like Run(Form);

Form Class
public class Form {
private javax.swing.JFrame container;

public void Form() {
InitializeComponent();
}

public void InitializeComponent() {
this.container.setName("Frame");
this.container.setSize(500,500);
this.container.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
this.container.setVisible(true);
}
}

Program Class:

public class Program {
public static void main(String[] args) {
// what would I need to write here to launch an
// instance of Form and for it to be displayed?

}
}
 
it seems like it'd be simpler for your Form class to extend javax.swing.JFrame, then in your main method just put

new Form();

also, please use
Code:
 tags in the future.
anyway this is what you'd get if you put everything in Program.java

[code]
import javax.swing.*;

public class Program {
	public static void main(String[] args) {
		new Form();
	}
}

class Form extends JFrame {
	// note constructors do not have a return type in java
	public Form() {
		super();
		InitializeComponent();
	}

	public void InitializeComponent() {
		this.setName("Frame");
		this.setSize(500,500);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
}
 
Back
Top