Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
Java Programs

Java Programs

Ratings: (0)|Views: 59 |Likes:
Published by Sai Kiran

More info:

Published by: Sai Kiran on Jul 27, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

01/17/2011

pdf

text

original

 
Draw lines,rect,oval:Save as choice.java
import javax.swing.*;import java.awt.Graphics;/*<html><body><applet code="choice.class"width=500 height=500></applet></body></html>*/ public class choice extends JApplet{int i,ch; public void init(){String input;input=JOptionPane.showInputDialog("enter your choice( 1-lines,2-rectangles,3-ovals)");ch=Integer.parseInt(input);} public void paint(Graphics g){switch(ch){case 1:{for(i=1;i<=10;i++){g.drawLine(10,10,250,10*i);} break;}case 2:{for(i=1;i<=10;i++){g.drawRect(10*i,10*i,50+10*i,50+10*i);} break;}case 3:{for(i=1;i<=10;i++){g.drawOval(10*i,10*i,50+10*i,50+10*i);} break;}}}
 
}
--------------------------------------------------------------------------JTable with data enter:Save as JTableDemo.java
import java.awt.*;import javax.swing.*;/* <applet code = "JTableDemo"width = 400 height=200> </applet> */ public class JTableDemo extends JApplet { public void init() {//Get Content PaneContainer contentPane = getContentPane();//set layout manger contentPane.setLayout(new BorderLayout());//Initialize column headingsfinal String[] colHeads = { "Name", "Phone", "Fax" };//Initialize datafinal Object[][] data = {{ "Gail", "4567", "8675" },{"Keen", "7566", "5555" },{"Viviane", "5674", "5887"},{"Anne", "1237", "3333" },{ "John", "5656", "3144" },{ "Ellen", "1134", "5335"},{ "Gail", "4567", "8675" },{"Keen", "7566", "5555" },{"Viviane", "5674", "5887"},{"Anne", "1237", "3333" },{ "John", "5656", "3144" },{ "Ellen", "1134", "5335"}};//Create the tableJTable table = new JTable(data, colHeads);//Add table to a scroll paneint v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED ;int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED ;JScrollPane jsp = new JScrollPane(table, v, h);// Add scroll pane to the content panecontentPane.add(jsp, BorderLayout.CENTER);}}-----------------------------------------------------------------
Abstract class named triagle,hexagon:Save as AbstractDemo.java
abstract class shape{void numberofsides(){
 
System.out.println("This is for abstract class");}}class Trapezoid extends shape{void numberofsides(){System.out.println("It is having 4 sides");}}class Triangle extends shape{void numberofsides(){System.out.println("it is having 3 sides");}}class Hexagonal extends shape{void numberofsides(){System.out.println("it is having 6 sides");}}class AbstractDemo{ public static void main(String args[]){Trapezoid tz=new Trapezoid();Triangle t=new Triangle();Hexagonal h=new Hexagonal();tz.numberofsides();t.numberofsides();h.numberofsides();}}----------------------------------------------------------------------
Fibonacci
class Rfib{int fibo(int n){int a=0,b=1,c=2,i;if(n==1)return(a);else if(n==2)return(b);else{for(i=3;i<=n;i++)

Activity (4)

You've already reviewed this. Edit your review.
1 hundred reads
syriluit liked this
yuvraja liked this
Anurag Goel liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->