How to run a java frames without getting any error. Can you tell me the correct code for java frames. | Sololearn: Learn to code for FREE!

0

How to run a java frames without getting any error. Can you tell me the correct code for java frames.

4/6/2021 1:10:34 PM

Soujanya...

3 Answers

New Answer

+2

Soujanya... Having looked at your code you seem to be attempting to use the Java Abstract Windowing Toolkit (AWT). I haven't seen an AWT application in decades. It is preferable these days to use either Java Swing or JavaFX. The following is similar to what you are trying to do but it does not run in the SoloLearn Code Playground. import javax.swing.*; public class GUITest001 extends JFrame { public GUITest001() { // Default constructor super("GUI Test 001"); setSize(640, 480); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { // Initiate program GUITest001 gt = new GUITest001(); } } The JFrame class is the Java Swing equivalent of the AWT Frame class.

+1

Did you mean Swing ?

+1

You can't compile or run Java GUI applications in the SoloLearn code playground. If you want information on building Java GUI applications on your pc locally then see... https://docs.oracle.com/javase/tutorial/ scroll down the page to see the section titled "Creating Graphical User Interfaces"