So I'm kind of new to coding in java and I'm making a GUI application for a project, but I have no idea how to actually view the GUI. I don't mean how to get to a design editor, but how to make the GUI come up like a window or app on the screen when I run it. All it does is tell me I had a successful build, then it's done. I feel like there is some sort of code to use, but I don't know where to put it or how to use it. For reference, my GUI's name is Visual.java and my main class's is StemNav.java. Please help because I have no idea what to do now. Thanks!
Asked
Active
Viewed 673 times
-2
-
1[Creating a GUI With JFC/Swing](http://docs.oracle.com/javase/tutorial/uiswing/); [Getting Started with JavaFX](https://docs.oracle.com/javafx/2/get_started/jfxpub-get_started.htm) – MadProgrammer Jan 09 '16 at 03:20
-
It's a duplicated question of [Popup Message boxes](http://stackoverflow.com/questions/7080205/popup-message-boxes) – caot Jan 09 '16 at 03:50
3 Answers
3
Here is an example of a very simple Java program that makes a window pop up:
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.show();
}
}
There are a ton of customization options for JFrame, but a couple of the most useful/common:
frame.setSize(width, height);
frame.setTitle("My Window Title");
frame.pack() is a useful alternative to frame.setSize().
You could look through the javadocs for java.awt and javax.swing to figure out how to use graphics in Java, but there are so many methods and properties of most Java graphics objects that it's probably better to find a streamlined graphics tutorial. Here's a good one for swing: http://www.tutorialspoint.com/swing/

kmell96
- 1,365
- 1
- 15
- 39
0
Here's a bare minimum example
import java.awt.Dimension;
import javax.swing.JFrame;
public class Main {
public static void main(String args[]){
JFrame frame = new JFrame("Test Frame");
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setSize( new Dimension( 1000, 600 ));
frame.setVisible(true);
}
}

Priyath Gregory
- 927
- 1
- 11
- 37
0
/**
* Example code of way to get output on the screen
*/
public class Visual {
public static void main(String[] args) {
StemNav sNav = new StemNav(); // pass in parameters required by StemNav
sNav.methodInStem() // pass in parameters required by methods
System.out.println("Output Example")
}
}

Greg Marsh
- 209
- 1
- 2
- 9