Post by hicaduda on Jul 12, 2014 16:20:08 GMT -5
I AM ASSUMING YOU HAVE YOUR IDE AND JDK SET UP AND YOU KNOW HOW TO RUN JAVA PROGRAMS
Java is an object oriented programming language, which means that the file you are programming in can interact with other Java files. Java already has built in class files that you can use to make your projects. To make a basic window, or frame, we use the JFrame class. To get into the JFrame class, you must first make a .java file. Call this class Main. Now, before the first brace, type 'extends JFrame'. You will then get an error. Don't worry, that just means that you need to import JFrame.
You now need to create a constructor of the Main class.
Now you need to call the following methods to initialize the details of your window.
After that your just want to call the constructor via the main method.
Java is an object oriented programming language, which means that the file you are programming in can interact with other Java files. Java already has built in class files that you can use to make your projects. To make a basic window, or frame, we use the JFrame class. To get into the JFrame class, you must first make a .java file. Call this class Main. Now, before the first brace, type 'extends JFrame'. You will then get an error. Don't worry, that just means that you need to import JFrame.
import javax.swing.JFrame;
public class Main extends JFrame {
}
You now need to create a constructor of the Main class.
import javax.swing.JFrame;
public class Main extends JFrame {
public void Main() {
}
}
Now you need to call the following methods to initialize the details of your window.
import javax.swing.JFrame;
public class Main extends JFrame {
public void Main() {
setSize(500, 400); // This says that your window will be 500 pixels wide, and 400 pixels high
setTitle("Test"); // This states that the text at the top of your window will be "Test" or whatever you wanna call it
setDefaultCloseOperation(EXIT_ON_CLOSE); // This says that when you press X, your program will be shut down completely
setLocationRelativeTo(null); // When your window shows, it will be in the center of the screen
setVisible(true); // Finally making sure that your window will be visible
}
}
After that your just want to call the constructor via the main method.
import javax.swing.JFrame;
public class Main extends JFrame {
public void Main() {
setSize(500, 400); // This says that your window will be 500 pixels wide, and 400 pixels high
setTitle("Test"); // This states that the text at the top of your window will be "Test" or whatever you wanna call it
setDefaultCloseOperation(EXIT_ON_CLOSE); // This says that when you press X, your program will be shut down completely
setLocationRelativeTo(null); // When your window shows, it will be in the center of the screen
setVisible(true); // Finally making sure that your window will be visible
}
public static void main(String[] args) {
new Main();
}
}