1

I have tried running a small gui program first time in my system. When i compiled the program in command prompt there was no error . But when i run the program it is not displaying the application instead the text file where i have written the program is being opened.I am using command prompt to run the program. I installed java from oracle.com and followed all procedures. Also i can get output for normal java programs.Please give me a solution why i dont get the result in command prompt

This is my program:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Frame1 extends JFrame {

    JPanel pane = new JPanel();
    Frame1() // the frame constructor method {
        super("My Simple Frame"); 
        setBounds(100,100,300,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container con = this.getContentPane(); // inherit main frame
        con.add(pane); // add the panel to frame
        // customize panel here
        // pane.add(someWidget);
        setVisible(true); // display this frame
    }

    public static void main(String args[]) {
        new Frame1();
    }
}
nIcE cOw
  • 24,468
  • 7
  • 50
  • 143
  • 1
    not true at all you would need to add import java.swing.*; .......... – mKorbel Sep 27 '13 at 18:47
  • Can you post the text from the Command Prompt session as well please? – Cruncher Sep 27 '13 at 18:49
  • Missed out the code. I used the import javax.swing.*; in the program. I dint get the output – VaishuSubbu Sep 28 '13 at 02:56
  • @VaishuSubbu : Please refer __Point 9__ from this [post](http://gagandeepbali.uk.to/gaganisonline/webpages/helloworld.html). Whenever you write class on the notepad (if you using this one) when saving it, do remember to select "All Files" with "Save as type". It appears, that the file you had saved is having this name __Frame1.java.txt__ which is why it's opening :-) – nIcE cOw Sep 28 '13 at 03:07
  • @VaishuSubbu : Moreover, I would recommend you to use either Notepad++, JEdit, Vim, Notepad2 instead of notepad, they are all nice options, and great alternative before using an IDE :-) And try to run the Swing Application on the `Event Dispatcher Thread` instead of from `main` method, like any ordinary Java Application, as shown in these [examples](http://stackoverflow.com/a/19006158/1057230) – nIcE cOw Sep 28 '13 at 03:13

0 Answers0