So that old GUI stuff was cool and what now, but now, lets move into making our own GUI, and make it look however we want, and do whatever we want. Lets start with the basic GUI layout. Type what I have typed below
import javax.swing.*;
public class Main extends JFrame {
public Main() {
super("My first GUI!");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false); //Delete this line if you want your program resizable
setVisible(true);
}
}
And that should create a blank GUI that goes away when the red X is hit, and not resizeable unless you set it to true. Now, to look at the code. The super statement just sets the title. The next line just sets the size of your GUI, you can fiddle around with that all you want. The line after that says that the program will terminate when you hit the red X or red button for mac. The last line just makes it so that the GUI is visible. Have some fun with that. Next chapter we will add stuff to our GUI
YOU ARE READING
Java Swing GUI Development
Non-FictionLearn all the necessities of Java Swing GUI development right here, from me, not some huge cooperate company, that can't find a good way to get the message across. Learn it here, learn it once.
