Empty Java Window

Charles

Member
Reputation
0
This is the code for an empty window in Java. There are two classes needed.

Class one:
Code:
import javax.swing.JOptionPane;
import javax.swing.JFrame;
public class charles {
	public static void main(String[] args){
		/*Nom is the name of the class all the code is being called from. Change it according to your class name.*/
		nom charlie = new nom();
		/*The Exit on close makes it so when a user hits "X" on the bar thingy it closes it.*/
		charlie.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		/*This is the size of the window*/
		charlie.setSize(350, 200);
		charlie.setVisible(true);
	}
}

Class 2:
Code:
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class nom extends JFrame{
	private JLabel item1;
	
	public nom(){
		/*This is where the title of the window goes*/
		super("Title Goes Here");
		setLayout(new FlowLayout());
		/*Words go here.*/
		item1 = new JLabel("This is a sentence.");
		add(item1);
	}
}

Hope you learned something ::thumbsup::
 
thank you for this i need it.
 
Haha. Well that is where the words that are output on the window go :3
 
Back
Top