Monday, 13 July 2015

Java Programs[Important]

  1. WRITE A JAVA PROGRAM that allows user to draw lines, rectangles and ovals.
  2.  
  3. Program : import   x.swing.*; import   .awt.Graphics;
  4.  
  5. public class choice extends JApplet
  6.  { 
  7. int i,ch; public void init()
  8.  { 
  9. String input; 
  10. input=JOptionPane.showInputDialog("enter choice(1-lines,2-rectangles,3-ovals)"); 
  11. ch=Integer.parseInt(input);
  12.  } 
  13. public void paint(Graphics g) 
  14. switch(ch) 

  15. case 1:
  16. your

  17. for(i=1;i<=10;i++) 
  18. g.drawLine(10,10,250,10*i); 
  19. break; 
  20. }
  21.  
  22. case 2:{
  23.  for(i=1;i<=10;i++) 
  24. g.drawRect(10*i,10*i,50+10*i,50+10*i);
  25.  }
  26.  break; 
  27. }
  28.  
  29. case 3:
  30. for(i=1;i<=10;i++) 
  31. g.drawOval(10*i,10*i,50+10*i,50+10*i);
  32.  } 
  33. break; 
  34. }
  35. }
  36. }
  37. }