Swing

Write a program to draw line from corner to corner in JAVA. import javax.swing.JPanel; import java.awt.Graphics; public class MP4 extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); int width=getWidth(); int height=getHeight(); for(int i=1;i<=15;i++) { g.drawLine(0,0,width,0); width=width+15; height=height+15; } } }  

October 4, 2012 at IST / Language.

Write a program to add two two number in JAVA import javax.swing.JOptionPane; public class MP3 { public static void main(String args[]) { String n1=JOptionPane.showInputDialog("Enter the 1 st number."); String n2=JOptionPane.showInputDialog("Enter the 2 nd number."); double a,b,c; a=Double.parseDouble(n1); b=Double.parseDouble(n2); c=a+b; String message=String.format("the sum of the entered two numbers is %.2f",c); JOptionPane.showMessageDialog(null,message); } }  

October 4, 2012 at IST / Language.

GUI program to show basic input using a dialog box. import javax.swing.JOptionPane; public class MP2 { public static void main(String args[]) { String hobby=JOptionPane.showInputDialog("What is your hobby?"); String message=String.format("Hi i am Piyush and my hobby is %s",hobby); JOptionPane.showMessageDialog(null,message); } }  

October 4, 2012 at IST / Language.