Sign in with
Sign up | Sign in
Your question
Closed

Command prompt not working

Last response: in Applications
Share
February 4, 2010 2:00:05 AM

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();
}
}

More about : command prompt working

a b L Programming
February 4, 2010 2:32:18 AM

This topic has been moved from the section CPU & Components to section Applications by Randomizer
Score
0

Best solution

a b L Programming
February 5, 2010 7:07:36 PM

You need to put it in a JFrame, and then tell the JFrame what action should be taken when the close button is clicked

  1. package test;
  2.  
  3. import java.awt.*;
  4.  
  5. import javax.swing.JFrame;
  6.  
  7. public class test extends Frame {
  8.  
  9. Panel p1;
  10. List l1, l2, l3;
  11.  
  12. public test() {
  13. //create the JFrame
  14. JFrame testFrame = new JFrame();
  15.  
  16. //create the panel, and add everything you want to the panel
  17. p1 = new Panel();
  18.  
  19. l1 = new List();
  20. l2 = new List(3);
  21. l3 = new List(3, true);
  22. add(p1);
  23. p1.add(l1);
  24. p1.add(l2);
  25. p1.add(l3);
  26.  
  27. l1.add("Om");
  28. l1.add("Om");
  29. l1.add("Om");
  30.  
  31. l2.add("Om");
  32. l2.add("Om");
  33. l2.add("Om");
  34.  
  35. l3.add("Om");
  36. l3.add("Om");
  37. l3.add("Om");
  38.  
  39. //add the panel to the JFrame
  40. testFrame.add(p1);
  41.  
  42. //set the JFrame visable and set the default size
  43. testFrame.setVisible(true);
  44. testFrame.setSize(400, 400);
  45.  
  46. //set the what happens when you click the close button (in
  47. //this case, exits the program)
  48. testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  49.  
  50. }
  51.  
  52. public static void main(String args[]) {
  53. test s1 = new test();
  54. }
  55. }


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).
Share
Related resources
June 20, 2010 6:18:12 AM

Best answer selected by aford10.
Score
0
June 20, 2010 6:20:23 AM

This topic has been closed by Aford10
Score
0
!