Closed Solved

Command prompt not working

Hello,
Respected sir I am ganesh Patekar.
when i type java GUI code in notepad and it compiles in command prompt and alos runs but after running it hangs and i cant close GUi frame and cant type anything in command prompt please tell me what to do
example of program:-

import java.awt.*;

class simple1 extends Frame
{

Panel p1;
List l1,l2,l3;

public simple1()
{

p1= new Panel();

l1= new List();
l2= new List(3);
l3= new List(3,true);
add(p1);
p1.add(l1);
p1.add(l2);
p1.add(l3);

l1.add("Om");
l1.add("Om");
l1.add("Om");

l2.add("Om");
l2.add("Om");
l2.add("Om");

l3.add("Om");
l3.add("Om");
l3.add("Om");


setSize(400,400);
setVisible(true);

}
public static void main(String args[ ])
{
simple1 s1= new simple1();
}
}
4 answers Last reply Best Answer
More about command prompt working
  1. This topic has been moved from the section CPU & Components to section Applications by Randomizer
  2. Best answer
    You need to put it in a JFrame, and then tell the JFrame what action should be taken when the close button is clicked

    
    package test;
    
    import java.awt.*;
    
    import javax.swing.JFrame;
    
    public class test extends Frame {
    
    	Panel p1;
    	List l1, l2, l3;
    
    	public test() {
    		//create the JFrame
    		JFrame testFrame = new JFrame();
    
    		//create the panel, and add everything you want to the panel
    		p1 = new Panel();
    
    		l1 = new List();
    		l2 = new List(3);
    		l3 = new List(3, true);
    		add(p1);
    		p1.add(l1);
    		p1.add(l2);
    		p1.add(l3);
    
    		l1.add("Om");
    		l1.add("Om");
    		l1.add("Om");
    
    		l2.add("Om");
    		l2.add("Om");
    		l2.add("Om");
    
    		l3.add("Om");
    		l3.add("Om");
    		l3.add("Om");
    
    		//add the panel to the JFrame
    		testFrame.add(p1);
    
    		//set the JFrame visable and set the default size
    		testFrame.setVisible(true);
    		testFrame.setSize(400, 400);
    
    		//set the what happens when you click the close button (in 
    		//this case, exits the program)
    		testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    	}
    
    	public static void main(String args[]) {
    		test s1 = new test();
    	}
    }
    


    I would highly recommend going over Sun's Swing tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/

    It outlines everything for build GUI's in java, and also shows you how to use NetBeans to build a GUI graphically instead of all by code (much much much easier i promise).
  3. Best answer selected by aford10.
  4. This topic has been closed by Aford10
Ask a new question

Read More

Programming Java Notepad Command Prompt Apps