Core Java Material 3
Core Java Material 3
{
public void run()
{
for(int i=0;i<10;i++)
{
[Link]("i value is :"+i);
}
}
public static void main(String[] args)
{
SecondThread st = new SecondThread();
Thread t = new Thread(st);
[Link]();
}
}
import [Link].*;
class sequencedemo
{
public static void main(String[] args) throws Exception
{
FileInputStream fis1 = new FileInputStream("[Link]");
FileInputStream fis2 = new FileInputStream("[Link]");
int k;
while((k=[Link]())!=-1)
{
[Link]((char)k);
}
}
}
class student
{
int sno;
int m1,m2,m3;
public student(int sno,int m1,int m2,int m3){
[Link]=sno;
this.m1=m1;
this.m2=m2;
this.m3=m3;
}
void modify(){
m1++;m2++;m3++;
}
void display(){
[Link]("sno= "+sno+" m1="+m1+" m2="+m2+" m3="+m3);
}
}
class result
{
int sno;
String result;
public result(int sno,String result){
[Link]=sno;
[Link]=result;
}
void modify(String ne){
result=ne;
}
void display(){
[Link]("sno="+sno+" result="+result);
}
}
student stud;
result res;
public mytest(int sno,int m1,int m2,int m3,String r){
stud=new student(sno,m1,m2,m3);
res=new result(sno,r);
}
public Object clone() throws CloneNotSupportedException {
return [Link]();
}
}
class test{
public static void main(String args[]) throws Exception {
[Link]();
[Link]();
[Link]();
[Link]("destention");
[Link]("after modifictation ");
[Link]();
[Link]();
[Link]();
[Link]();
}
}
abstract class shape
{
abstract void area();
void behavior()
{
[Link]("this example show hierarchical inheritance");
}
}
class Rect extends shape
{
int length,breadth;
void getRect()
{
length=20;
breadth=30;
}
void area()
{
int z=length * breadth;
[Link]("the area of reactangle is :"+z);
}
}
class square extends shape
{
int a;
void getsquare()
{
a=40;
}
void area()
{
int x=a * a;
[Link]("the area of square is :"+x);
}
}
class shapedemo
{
public static void main(String[] args)
{
//shape s = new shape();
//[Link]();
}
}
class Simple
{
public static void main(String args[])
{
[Link]("original main method");
int x=10;
main(x);
}
public static void main(int x)
{
[Link]("x value is :"+x);
}
}
class Simple
{
void display()
{
[Link]("hello");
}
}
class simpledemo
{
public static void main(String[] args)
{
Simple s[]=new Simple[5];
s[0]=new Simple();
s[0].display();
}
}
class sleeptest extends Thread
{
public void run()
{
try
{
for(int i=0;i<10;i++)
{
[Link](1000);
[Link]("i value is :"+i);
}
}
catch(Exception e)
{
[Link](e);
}
}
public static void main(String[] args)
{
sleeptest s1 = new sleeptest();
sleeptest s2 = new sleeptest();
[Link]();
[Link]();
}
}
.
class sortarray
{
public static void main(String[] args)
{
int a[]={50,30,20,60,45};
int n=[Link];
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int temp;
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(int i=0;i<n;i++)
{
[Link](a[i]);
}
}
}
import [Link].*;
class sorting
{
public static void main(String args[])
{
[Link](args);
for(int i=0;i<[Link];i++)
{
[Link](args[i]);
}
}
}
class Speed
{
public static void main(String[] args)
{
Speed objref = new Speed();
double s = [Link](12.0,-3.0);
[Link]("speed (km/h):"+s);
}
private double calcspeed(double distance,double time)
{
assert distance >0.0;
assert time >0.0 :"time is not a positive value:"+time;
double sp=distance/time;
assert sp >=0.0;
return sp;
}
}
import [Link].*;
class stackdemo
{
public static void main(String []a)
{
Stack s=new Stack();
[Link](new Integer(33));
[Link](new String("java"));
[Link](new Float(45.67));
[Link](new Integer(67));
[Link](null);
[Link](null);
[Link](s);
Object o=[Link]();
[Link]("PEEK"+[Link]());
[Link](s);
Object o1=[Link]();
[Link]("after deletion"+[Link]());
[Link](s);
}
}
class StackTrace
{
IllegalArgumentException ex;
public static void main(String[] argv)
{
StackTrace st = new StackTrace();
[Link]();
[Link]("CONSTRUCTED BUT NOT THROWN");
[Link]();
[Link]();
// MAY BE NOTREACHED - THINK ABOUT IT!
[Link]("CONSTRUCTED BUT NOT THROWN");
[Link]();
}
class staticoverride
{
public static void main(String args[])
{
AA a1 = new AA();
BB b1 = new BB();
AA x;
x=a1;
[Link]();
[Link]();
x=b1;
[Link]();
[Link]();
}
}
class ABCD
{
static void one()
{
[Link]("class ABCD one method");
}
static void one(int x)
{
[Link]("x vlaue is :"+x);
}
}
class XYZ extends ABCD
{}
class staticinheritdemo
{
public static void main(String[] args)
{
XYZ x1 = new XYZ();
[Link]();
[Link](10);
}
}
1
class outer
{
int a=10;
static int b=20;
class inner
{
int c=30;
static int d=40;
void display()
{
[Link]("this is the method in inner class");
[Link]("the outer a is"+b);
}
}
}
class StaticInner
{
public static void main(String args[])
{
outer ou = new outer();
[Link]("a value is :"+ou.a);
[Link]("b value is :"+outer.b);
class inner
{
int c=30;
//static int d=40;
}
}
class StaticInner
{
public static void main(String args[])
{
outer ou = new outer();
[Link]("a value is :"+ou.a);
[Link]("b value is :"+outer.b);
class staticoverride
{
public static void main(String args[])
{
AA a1 = new AA();
BB b1 = new BB();
AA x;
x=a1;
[Link]();
[Link]();
x=b1;
[Link]();
[Link]();
}
}
class stopdemo implements Runnable
{
}
}
class stringdemo1
{
public static void main(String[] args)
{
//String str = new
StringBuffer().append("hello").append("World").toString();
String str="hello"+"world";
[Link](str);
}
}
class StringDemo2
{
public static void main(String[] args)
{
String s1 = new String("hello");
String s2 = new String("hello");
String s9="hai";
String s10="hai";
String s11="hello";
// =============================================
if([Link]("hello"))
[Link]("s1 equals hello");
else
[Link]("s1 not equals hello");
//==============================================
if([Link](s2))
[Link]("s1 and s2 both are equal");
else
[Link]("both are not equal");
//==============================================
if(s1=="hello")
[Link]("s1 and hello both references same");
else
[Link]("not same reference");
//==============================================
if(s1==s2)
[Link]("s1 and s2 references are same");
else
[Link]("s1 and s2 both references are not same");
//==============================================
if(s3==s4)
[Link]("s3 and s4 references are same");
else
[Link]("s3 and s4 references are not same");
//==============================================
if(s9==s10)
[Link]("s9 and s10 references are same");
else
[Link]("s9 and s10 references are not same");
//==============================================
if(s1==s3)
[Link]("s1 and s3 references are same");
else
[Link]("s1 and s3 references are not same");
//==============================================
if(s1==s11)
[Link]("s1 and s11 references are same");
else
[Link]("s1 and s11 references are not same");
//==============================================
if([Link](s6))
[Link]("s5 and s6 both contents are same");
else
[Link]("s5 and s6 contents are different");
//==============================================
String s7="god";
String s8="good";
[Link]("s1 compare to s2 is :"+[Link](s2));
[Link]("s7 compare to s8 is :"+[Link](s8));
[Link]("s8 compare to s7 is :"+[Link](s7));
//==============================================
[Link]("s1 starts with :"+[Link]("he"));
[Link]("s1 starts with :"+[Link]("e",1));
[Link]("s5 ends with :"+[Link]("day"));
//==============================================
String str = "activenetinformaticslimitednet";
[Link]("t located at :"+[Link]('t'));
[Link]("t located at :"+[Link]('t',3));
[Link]("net located at :"+[Link]("net"));
[Link]("net located at :"+[Link]("net",9));
[Link]("last i located at :"+[Link]('i'));
[Link]("last i located at :"+[Link]('i',10));
[Link]("last net located at :"+[Link]("net"));
//==============================================
[Link]("sub string from index 10 to end is :"+[Link](10));
[Link]("sub string from index 0 to 9 is :"+[Link](0,9));
[Link]("result of [Link](s3) is"+[Link](s3));
[Link]("after concatenation:"+s1);
[Link]("replace 'l' with 'L' in s1 is :"+[Link]('l','L'));
[Link]("s1 to Uppercase is :"+[Link]());
[Link]("s6 to lowercase is :"+[Link]());
String str1=" activenet ";
[Link]("str1 after trim :"+[Link]());
boolean b = true;
char c = 's';
int i = 9;
double d = 99.99;
[Link]([Link]());
[Link]([Link]());
}
}
import [Link].*;
class Student1
{
public static void main(String[] args) throws Exception
{
FileInputStream fis = new FileInputStream("[Link]");
ObjectInputStream ois = new ObjectInputStream(fis);
Object o= [Link]();
Student st =(Student)o;
[Link]();
}
}
class Student implements Cloneable
{
int sno;
String sname;
public Student(int x,String y)
{
sno=x;
sname=y;
}
void display()
{
[Link]("the sno is :"+sno);
[Link]("the sname is :"+sname);
}
void setname(String name)
{
sname=name;
}
public static void main(String[] args) throws Exception
{
Student s1 = new Student(101,"ram");
[Link]();
Student s2=(Student)[Link]();
[Link]();
[Link]();
[Link]("hari");
[Link]();
[Link]();
[Link](s1);
[Link](s2);
}
}
class Studentdemo
{
public static void main(String[] args) throws MarksOutOfBoundsException
{
Student s1 = new Student(101,"ram",99);
Student s2 = new Student(102,"nikil",120);
// try
//{
[Link]();
[Link]();
//}
//catch(Exception e)
//{
//[Link](e);
// }
[Link]("out of findresult");
}
}
import [Link].*;
[Link]();
[Link]();
}
}
class syn2 implements Runnable
{
int x;
public static void main(String[] args)
{
syn2 s = new syn2();
[Link]();
[Link]();
}
public void run()
{
int hold;
[Link]("entered into run method");
[Link]([Link]().getName());
for(int i=0;i<10;i++)
{
synchronized(this)
{
[Link]("entered into syn block");
[Link]([Link]().getName());
hold=x+1;
try
{
[Link](1000);
}
catch(Exception e)
{
[Link](e);
}
x=hold;
[Link]([Link]().getName());
[Link]("syn completed");
}
}
}
}
public class TernaryOperatorsDemo {
public static void main(String args[]){
int x = 10, y = 12, z = 0;
z = x > y ? x : y;
[Link]("z : "+z);
}
}
class Test
{
public static void main(String args[])
{
int a=10;
int b=0;
int c=a/b;
[Link]("the c value i s:"+c);
}
}
import [Link];
class testExceptions
{
void method1() throws Throwable
{
throw new Throwable("Throwable Exception in method1");
}
void method2() throws Throwable
{
throw new IOException("Exception in method2");
try
{
method1();
}
catch(Throwable th)
{
throw th;
throw [Link]();
}
}
public static void main(String args[]) throws Throwable
{
new testExceptions().method2();
}
}
import [Link].*;
add(tf1);
add(tf2);
add(ta);
setSize(300,400);
show();
}
public static void main(String[] args)
{
new TextDemo();
}
}
class Third extends Thread
{
public void run()
{
for(int i=0;i<10;i++)
{
try
{
[Link](1000);
}
catch(Exception e)
{}
[Link]("i value is :"+i);
}
}
public static void main(String[] args)
{
Third t1 = new Third();
[Link]();
Third t2 = new Third();
[Link]();
Third t3 = new Third();
[Link]();
}
}
this keyword uses are
================
1. differentiating the local variables and
instance variables
2. constructor chaining(calling local
constructors)
3. function chaining
class simple
{
int a,b,c,d;
simple(int x,int y)
{
a=x;
b=y;
}
simple(int x,int y,int z)
{
this(x,y);
c=z;
}
simple(int p,int q,int r,int s)
{
this(p,q,r);
d=s;
}
}
=======================================
function chain
===================
class simple
{
int a,b;
class Treeset
{
public static void main(String[] args)
{
TreeSet t = new TreeSet();
[Link]("20");
[Link]("10");
[Link]("30");
[Link](null);
[Link](t);
}
}
import [Link].*;
class Emp
{}
class Student
{}
class Salary
{}
class VectorDemo
{
public static void main(String[] args)
{
Vector v = new Vector();
[Link]("capacity is :"+[Link]());
[Link]("10");
[Link]("30");
[Link]("20");
[Link]("40");
/*
Enumeration e =[Link]();
while([Link]())
{
Object o=[Link]();
[Link]("the object is :"+o);
}
Iterator i = [Link]();
while([Link]())
{
Object o = [Link]();
[Link]("the object is :"+o);
}
*/
ListIterator li = [Link]();
while([Link]())
{
Object o = [Link]();
[Link]("the object is :"+o);
}
while([Link]())
{
Object o1 = [Link]();
[Link]("athe object is :"+o1);
}
}
}
import [Link].*;
StudentExternal st = new
StudentExternal(sno,sname,m1,m2,m3);
[Link](st);
}
[Link]();
[Link]();
[Link]();
}
catch(Exception e)
{
[Link](e);
}
}
}
class Q
{
int n;
synchronized int get()
{
[Link]("got"+n);
return n;
}
synchronized void put(int n)
{
this.n=n;
[Link]("put"+n);
}
}
class producer implements Runnable
{
Q q;
producer(Q q)
{
this.q=q;
new Thread(this,"producer").start();
}
public void run()
{
int i=0;
while(true)
{
[Link](i++);
}
}
}
class consumer implements Runnable
{
Q q;
consumer(Q q)
{
this.q=q;
new Thread(this,"consumer").start();
}
public void run()
{
int i=0;
while(true)
{
[Link]();
}
}
}
class procon
{
public static void main(String[] args)
{
Q q = new Q();
new producer(q);
new consumer(q);
[Link]("press ctrl -c to stop");
}
}
=============================
modified version
=============================
class Q
{
int n;
boolean valueset=false;
synchronized int get()
{
if(!valueset)
try
{
wait();
}
catch(Exception e)
{
[Link]("InterruptedException");
}
[Link]("got"+n);
valueset=false;
notify();
return n;
}
synchronized void put(int n)
{
if(valueset)
try
{
wait();
}
catch(Exception e)
{
[Link]("InterruptedException");
}
this.n=n;
valueset=true;
[Link]("put"+n);
notify();
}
}
class producer implements Runnable
{
Q q;
producer(Q q)
{
this.q=q;
new Thread(this,"producer").start();
}
public void run()
{
int i=0;
while(true)
{
[Link](i++);
}
}
}
class consumer implements Runnable
{
Q q;
consumer(Q q)
{
this.q=q;
new Thread(this,"consumer").start();
}
public void run()
{
int i=0;
while(true)
{
[Link]();
}
}
}
class proconfixed
{
public static void main(String[] args)
{
Q q = new Q();
new producer(q);
new consumer(q);
[Link]("press ctrl -c to stop");
}
}
=============================
deadlockdemo
=============================
class DlDemo implements Runnable
{
DlDemo x;
public static void main(String[] args)
{
DlDemo dd1 = new DlDemo();
DlDemo dd2 = new DlDemo();
[Link](dd1);
[Link](dd2);
dd1.x=dd2;
[Link](dd1.x);
dd2.x=dd1;
[Link](dd2.x);
[Link]();
[Link]();
try
{
[Link]();
[Link]();
}
catch(Exception e)
{
[Link](0);
}
}
public synchronized void run()
{
try
{
[Link]([Link]().getName());
[Link](1000);
}
catch(InterruptedException e)
{
[Link](e);
}
[Link]();
}
public void synmethod()
{
try
{
[Link](1000);
}
catch(InterruptedException e)
{
[Link](e);
}
[Link]("in synmethod");
}
}
class yieldingthread extends Thread
{
int countdown=6;
static int threadcount=0;
yieldingthread()
{
super(""+ ++threadcount);
start();
}
public String toString()
{
return "#"+getName()+" :"+countdown;
}
public void run()
{
while(true)
{
[Link](this);
if(--countdown == 0)
return;
yield();
}
}
public static void main(String[] args)
{
for(int i=0;i<5;i++)
{
new yieldingthread();
}
}
}
innerclass
class WithInner
{
class Inner
{
Inner()
{
[Link]("i am inner class constructor");
}
}
}
class A
{
class B
{
private int i = 11;
public int value()
{
return i;
}
}
class C
{
private String label;
C(String x)
{
label = x;
}
String readLabel()
{
return label;
}
}
class A
{
class B
{
private int i = 11;
public int value()
{
return i;
}
}
class C
{
private String label;
C(String x)
{
label = x;
}
String readLabel()
{
return label;
}
}
public static void main(String[] args)
{
A a = new A();
// Must use instance of outer class
// to create an instances of the inner class:
A.B b = [Link] B();
A.C c = [Link] C("India");
String s=[Link]();
[Link](s);
}
} ///:~
/** Demonstrate inner-inner class. A named inner class
* is used to show that it can access non-local variables
* in the enclosing object.
*/
public class abc
{
static String msg = "Hello";
public static void main(String[] av)
{
class xyz
{
public void display()
{
// print member of enclosing class
[Link](msg);
}
}
xyz x = new xyz();
[Link]();
}
}
// can inner classes can be overriden
class override
{
private abc a;
public class abc
{
public abc()
{
[Link]("[Link]()");
}
}
public override()
{
[Link]("new override()");
a=new abc();
}
}
class overridedemo extends override
{
public class abc
{
public abc()
{
[Link]("[Link]()");
}
}
public static void main(String[] args)
{
new overridedemo();
}
}
class MyOuter2
{
private String x="outer2";
void doStuff()
{
String y="local variable";
class MyInner
{
public void seeOuter()
{
[Link]("Outer x is :"+x);
[Link]("string is :"+y);
}
}
MyInner mi = new MyInner();
[Link]();
}
public static void main(String[] args)
{
MyOuter2 my = new MyOuter2();
[Link]();
}
}
import [Link].*;
import [Link].*;
class MyDia extends Dialog implements ActionListener
{
Frame fra;
Button b1,b2;
public MyDia(Frame f,String s)
{
super(f,s);
f=new MenuTest();
fra=f;
[Link]("New Frame");
b1= new Button("OK");
b2=new Button("Cancel");
Panel p=new Panel();
[Link](b1);
[Link](b2);
[Link](p,"South");
[Link](200,200);
[Link](true);
[Link](this);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](false);
}
});
}
public void actionPerformed(ActionEvent a)
{
[Link](false);
}
}
public class MenuTest extends Frame implements ActionListener,ItemListener
{
CheckboxMenuItem cbi1,cbi2,cbi3;
static Frame f;
Color c;
public MenuTest()
{
MenuBar mb= new MenuBar();
setMenuBar(mb);
// is a method in Frame class
Menu m1=new Menu("File");
// creating menu option
MenuItem mi1=new MenuItem("Open",
new MenuShortcut(KeyEvent.VK_O));
//creating menu item
MenuItem mi2=new MenuItem("New",
new MenuShortcut(KeyEvent.VK_N));
MenuItem mi3=new MenuItem("Save",
new MenuShortcut(KeyEvent.VK_S));
MenuItem mi4=new MenuItem("Exit",
new MenuShortcut(KeyEvent.VK_X));
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
public void actionPerformed(ActionEvent a)
{
FileDialog d1=new FileDialog(this,
"Open",[Link]);
FileDialog d2=new FileDialog(this,
"Save",[Link]);
if ([Link]().equals("Open"))
{
[Link]();
}
if ([Link]().equals("New"))
{
Frame f2=new Frame();
new MyDia(f2,"New");
}
if ([Link]().equals("Save"))
{
[Link]();
}
if ([Link]().equals("Exit"))
{
[Link](0);
}
}
public void itemStateChanged(ItemEvent i)
{
if([Link]()==true)
{
c=new Color(255,0,0);
repaint();
}
if([Link]())
{
c=new Color(0,255,0);
repaint();
}
if([Link]())
{
c=new Color(0,0,255);
repaint();
}
}
public void paint(Graphics g)
{
[Link](c);
}
public static void main(String[] args)
{
f=new MenuTest();
[Link](400,400);
[Link](true);
}
}
import [Link].*;
import [Link].*;
class MenuTest1 extends Frame implements ActionListener
{
MenuBar mb = new MenuBar();
Menu m1 = new Menu("File");
Menu m2 = new Menu("Edit");
Menu sub = new Menu("Draw");
MenuItem mi1 = new MenuItem("New", new MenuShortcut(KeyEvent.VK_A));
MenuItem mi2 = new MenuItem("Open");
MenuItem mi3 = new MenuItem("Save");
MenuItem mi4 = new MenuItem("Save as");
MenuItem mi5 = new MenuItem("Exit");
MenuItem mi6 = new MenuItem("Copy");
MenuItem smi1 = new MenuItem("Line");
MenuItem smi2 = new MenuItem("Rect");
TextField tf = new TextField(20);
MenuTest1()
{
setSize(200,300);
[Link](mi1);
[Link](mi2);
[Link](mi3);
[Link](mi4);
[Link]();
[Link](mi5);
[Link](mi6);
[Link](sub);
[Link](smi1);
[Link](smi2);
[Link](m1);
[Link](m2);
setMenuBar(mb);
add(tf,"North");
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
setVisible(true);
}
public static void main(String args[])
{
new MenuTest();
}
public void actionPerformed(ActionEvent ae)
{
[Link]("u selected"+[Link]());
}
}
class MyOuter
{
class MyInner
{ }
}
class outer
{
int a=10;
class inner
{
int b=20;
}
}
class nonstaticouterdemo
{
public static void main(String[] args)
{
outer ou = new outer();
// [Link] in = new outer().new inner();
[Link] in =[Link] inner();
[Link]("outer class variable is "+ou.a);
[Link]("innerclass variable is :"+in.b);
}
}
import [Link].*;
import [Link].*;
[Link](mi1);
[Link](mi2);
[Link](mi3);
[Link](mi4);
add(pm);
addMouseListener(this);
setVisible(true);
setSize(200,200);
addWindowListener(new WindowAdapter()
[Link](0);
});
}
public void mouseEntered(MouseEvent me)
{}
public void mouseExited(MouseEvent me)
{}
public void mouseClicked(MouseEvent me)
{}
public void mouseReleased(MouseEvent me)
{}
public void mousePressed(MouseEvent me)
{
[Link]([Link](),[Link](),[Link]());
}
public static void main(String args[])
{
popupexample pp = new popupexample();
}
}
import [Link].*;
import [Link].*;
start.x=[Link]();
start.y = [Link]();
end.x = [Link]();
end.y = [Link]();
repaint();
}
});
addMouseMotionListener(new MouseMotionAdapter()
end.x = [Link]();
end.y = [Link]();
repaint();
);
setVisible(true);
}
public void paint(Graphics g)
{
[Link](start.x,start.y,end.x,end.y);
}
public static void main(String args[])
{
new RubberLine();
}
}
class outer
{
static int a=10;
static class inner
{
static int b=20;
int c=30;
}
}
class staticouterdemo
{
public static void main(String[] args)
{
outer ou = new outer();
[Link] in = new [Link]();
[Link]("outer class variable is "+outer.a);
[Link]("innerclass variable is :"+[Link].b);
[Link]("inner class variable is :"+in.c);
}
}
Packages
package pack1;
class Varprotection
{
int n=1;
private int pri=2;
protected int pro=3;
public int pub =4;
Varprotection()
{
[Link]("default value is :"+n);
[Link]("private value is :"+pri);
[Link]("protected value is :"+pro);
[Link]("public value is :"+pub);
}
}
package pack1;
class Samediff
{
Samediff()
{
Varprotection v = new Varprotection();
[Link]("default value is :"+v.n);
//[Link]("private value is :"+[Link]);
[Link]("protected value is :"+[Link]);
[Link]("public value is :"+[Link]);
}
}
package pack1;
class Samesub extends Varprotection
{
Samesub()
{
[Link]("default value is :"+n);
//[Link]("private value is :"+pri);
[Link]("protected value is :"+pro);
[Link]("public value is :"+pub);
}
}
package pack1;
class MainTest
{
public static void main(String[] args)
{
Varprotection v1 = new Varprotection();
Samesub s1 = new Samesub();
Samediff s2 = new Samediff();
}
}
pack2
package pack2;
import pack1.*;
class OtherDiff
{
OtherDiff()
{
Varprotection v2 = new Varprotection();
[Link]("default value is :"+v2.n);
[Link]("private value is :"+[Link]);
[Link]("protected value is :"+[Link]);
[Link]("public value is :"+[Link]);
}
}
package pack2;
import pack1.*;
package pack2;
import pack1.*;
class OtherMainTest
{
public static void main(String[] args)
{
OtherSub os = new OtherSub();
OtherDiff od = new OtherDiff();
}
}
Swing Programs
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
[Link](true);
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
public JMenuExample1( ) {
super("DinnerMenu ");
setSize(200, 200);
setLocation(200, 200);
myappli()
{
Container con = [Link]();
[Link](new FlowLayout());
JLabel l1 = new JLabel("first no");
b1 = new JTextField(10);
JLabel l2 = new JLabel("second no");
b2 = new JTextField(10);
JLabel l3 = new JLabel("value ");
b3 = new JTextField(10);
jb1 = new JButton("add");
[Link](this);
[Link](l1);
[Link](b1);
[Link](l2);
[Link](b2);
[Link](l3);
[Link](b3);
[Link](jb1);
setVisible(true);
// setSize(300,400);
pack();
}
public void actionPerformed(ActionEvent ae)
{
if([Link]().equals("add"))
{
String s1 = [Link]();
int x = [Link](s1);
String s2 = [Link]();
int y = [Link](s2);
int z= x+y;
[Link](s3);
}
}
mycolor()
{
Container con = getContentPane();
[Link](new FlowLayout());
jt1= new JTextField(10);
[Link](jt1);
[Link](b1);
[Link](b2);
[Link](b3);
[Link](this);
[Link](this);
[Link](this);
setSize(200,300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void itemStateChanged(ItemEvent i)
{
/*
ifb1==[Link]())
[Link]([Link]);
else
if(b2==[Link]())
[Link]([Link]);
else
if(b3==[Link]())
[Link]([Link]);
*/
String s = [Link]();
if([Link]("RED"))
[Link]([Link]);
}
public static void main(String[] args)
{
new mycolor();
}
}
// [Link]
// A test of the OverlayLayout manager allowing experimentation.
//
import [Link].*;
import [Link].*;
import [Link].*;
public OverlayTest() {
super("OverlayLayout Test");
setSize(500, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
[Link](b1);
[Link](b1);
[Link](b1);
[Link](b2);
[Link](b2);
[Link](b2);
[Link](b3);
[Link](b3);
[Link](b3);
[Link](jb1);
[Link](jb2);
[Link](jb3);
[Link](x1);
[Link](y1);
[Link](x2);
[Link](y2);
[Link](x3);
[Link](y3);
[Link] = 1;
JButton updateButton = new JButton("Update");
[Link](new ActionListener() {
public void actionPerformed(ActionEvent ae) {
[Link](
[Link]([Link]().trim()).floatValue());
[Link](
[Link]([Link]().trim()).floatValue());
[Link](
[Link]([Link]().trim()).floatValue());
[Link](
[Link]([Link]().trim()).floatValue());
[Link](
[Link]([Link]().trim()).floatValue());
[Link](
[Link]([Link]().trim()).floatValue());
[Link]();
}
});
[Link](updateButton, constraints);
[Link] = 0;
[Link] = 1;
[Link] = 2;
[Link](p2, constraints);
}
[Link]([Link]);
[Link](0,0,w-1,h-1);
[Link](w/2,0,w/2,h);
[Link](0,h/2,w,h/2);
}
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public OverlayTest1() {
super("OverlayLayout Test");
setSize(500, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container c = getContentPane();
[Link](new GridBagLayout());
/* [Link](b1);
[Link](b1);
[Link](b1);
[Link](b2);
[Link](b2);
[Link](b2);
[Link](b3);
[Link](b3);
[Link](b3);
[Link](b4);
[Link](b4);
[Link](b4);
*/
[Link](jb1);
[Link](jb2);
[Link](jb3);
[Link](jb4);
GridBagConstraints constraints = new GridBagConstraints();
[Link](p1, constraints);
}
}
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
/*
<applet code="[Link]" width=400 height=500>
</applet>
*/
[Link](new JMenuItem("cut"));
[Link](new JMenuItem("copy"));
[Link](new JMenuItem("paste"));
[Link](new MouseAdapter()
showPopup(me);
);
}
void showPopup(MouseEvent e)
{
if([Link]())
[Link]([Link](),[Link](),[Link]());
}
}
import [Link].*;
import [Link].*;
import [Link].*;
/*
<applet code="[Link]" width=400 height=400>
</applet>
*/
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
[Link](new JButton("button"+j));
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int
h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
[Link](true);
}
}
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public TabbedPaneExample()
{
/*
<applet code=TJTable width=500 height=600>
</applet>
*/
import [Link].*;
import [Link].*;
import [Link].*;
Object[][] rowdata = {
{"[Link]","149","09-11-07",new Boolean(false)},
{"real","dir","12-11-07",new Boolean(true)},
};
[Link](0);
}
});
[Link](new FlowLayout());
JButton b1 = new JButton("ok");
[Link](b1);
}
}
import [Link].*;
import [Link].*;
import [Link].*;
/*[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});*/
}
public swing2()
{ Icon i1=new ImageIcon("[Link]");
Icon i2=new ImageIcon("[Link]");
JButton b1=new JButton();
JButton b2=new JButton("second");
JButton b3=new JButton(i1);
JButton b4=new JButton("fourth",i2);
Container con=getContentPane();
FlowLayout fl=new FlowLayout([Link]);
//FlowLayout fl=new FlowLayout([Link]);
//[Link](fl);
[Link](new FlowLayout([Link]));
[Link](b1);
[Link](b2);
[Link](b3);
[Link](b4);
[Link]("first");
[Link]([Link]());
[Link]([Link]());
[Link]([Link]);
[Link]([Link]);
}
}
import [Link].*;
import [Link].*;
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
public swing4()
{
JButton b1=new JButton("red");
JButton b2=new JButton("blue");
JButton b3=new JButton("green");
JPanel p1=new JPanel();
[Link](b1);[Link](b2);[Link](b3);
//[Link]([Link]);
Container con=getContentPane();
[Link]("South",p1);
[Link]("North",p2);
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public class swing5 extends JFrame
{
public static void main(String args[])
{
swing5 f=new swing5();
[Link](700,500);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
public swing5()
{
Icon i1=new ImageIcon("[Link]");
JButton b1=new JButton("welcome",i1);
//[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
Container con=getContentPane();
[Link](new FlowLayout());
[Link](b1);
Dimension d1=[Link]();
[Link]([Link]+" "+[Link]);
import [Link].*;
import [Link].*;
import [Link].*;
public class swing6 extends JFrame
{
public static void main(String args[])
{
swing6 f=new swing6();
[Link](700,500);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
public swing6()
{
Icon i1=new ImageIcon("[Link]");
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class swing7 extends JFrame
{
public static void main(String args[])
{
swing7 f=new swing7();
[Link](700,500);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
public swing7()
{
Container con=getContentPane();
[Link](new FlowLayout());
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public class swing8 extends JFrame
{
public static void main(String args[])
{
[Link]("execution of main method..");
swing8 f=new swing8();
[Link](800,600);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
public void paint(Graphics g)
{
[Link]("execution of paint method..");
[Link]([Link]);
[Link](30,30,150,30);
[Link](30,50,100,50);
[Link](150,50,100,50,20,20);
g.fill3DRect(30,130,100,50,true);
g.fill3DRect(150,130,100,50,false);
[Link]([Link]);
[Link](30,220,100,100);
[Link](30,350,100,100,90,90);
Font f1=new Font("Arial",[Link]+[Link],30);
[Link](f1);
[Link]("java by rami reddy",300,50);
int x[]=new int[]{500,600,550,450,400};
int y[]=new int[]{200,250,300,300,250};
[Link]([Link]);
//[Link](x,y,3);
//[Link](x,y,3);
[Link](x,y,5);
}
}
import [Link].*;
import [Link].*;
import [Link].*;
/*
<applet code="swing8a" width=400 height=200>
</applet>
*/
/*
<applet code="[Link]" width=200 height=200>
</applet>
*/
public class swing9 extends Applet
{
public void init()
{
Button b1 = new Button("ok");
add(b1);
[Link]("init method..");
}
public void stop()
{
[Link]("stop method..");
}
public void start()
{
//Button b1 = new Button();
//add(b1);
[Link]("start method..");
}
public void destroy()
{
[Link]("destroy method..");
}
public void paint(Graphics g)
{
[Link]("paint method..");
[Link]("core java by rami reddy",70,80);
}
}
import [Link].*;
import [Link].*;
import [Link].*;
/*
<applet code="swing10" width=300 height=200>
</applet>
*/
Container con=getContentPane();
FlowLayout fl=new FlowLayout();
[Link](fl);
[Link](b1);[Link](b2);
[Link](this);
[Link](this);
}
public void actionPerformed(ActionEvent a)
{ JButton b=(JButton)[Link]();
if(b==b1)
[Link]("first button is clicked..");
else if(b==b2)
[Link]("second button is clicked...");
/*String str=[Link]();
if([Link]("first button"))
[Link]("first button is clicked..");
else if([Link]("second button"))
[Link]("second button is clicked...");
*/
}
}
import [Link].*;
import [Link].*;
import [Link].*;
/*
<applet code="swing11" width=300 height=200>
</applet>
*/
con=getContentPane();
[Link](new FlowLayout());
[Link](b1);[Link](b2);[Link](b3);[Link](b4);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
}
public void actionPerformed(ActionEvent a)
{
int r=(int)([Link]() * 255);
int g=(int)([Link]() * 255);
int b=(int)([Link]() * 255);
Color c1=new Color(r,g,b);
[Link](c1);
}
public void focusGained(FocusEvent f)
{
JButton b=(JButton)[Link]();
[Link]([Link]);
[Link]([Link]);
}
public void focusLost(FocusEvent f)
{
JButton b=(JButton)[Link]();
[Link]([Link]);
//[Link]([Link]);
}
}
import [Link].*;
import [Link].*;
/*
<applet code="swing12" width=300 height=200>
</applet>
*/
public class swing12 extends JApplet
{
public void init()
{
JTextField tf1=new JTextField();
JTextField tf2=new JTextField(30);
JTextField tf3=new JTextField("welcome");
JTextField tf4=new JTextField("welcome",20);
JPasswordField tf5=new JPasswordField(20);
[Link]('&');
Container con=getContentPane();
[Link](new FlowLayout());
[Link](tf1);[Link](tf2);[Link](tf3);
[Link](tf4);[Link](tf5);
}
}
import [Link].*;
import [Link].*;
import [Link].*;
[Link](0);
}
});
}
//JPasswordField tf1;
JTextField tf1,tf2,tf3;
public swing13()
{
tf1=new JTextField();
tf2=new JTextField();
tf3=new JTextField();
[Link](25,30,200,30);
[Link](25,80,200,30);
[Link](25,130,200,30);
Container con=getContentPane();
[Link](null);
[Link](tf1);[Link](tf2);[Link](tf3);
[Link](this);
}
public void actionPerformed(ActionEvent a)
{
String s1=[Link]();
String s2=[Link]();
int n1=[Link](s1);
int n2=[Link](s2);
int n3=n1 +n2;
String s3=[Link](n3);
[Link](s3);
// [Link]([Link]( [Link]([Link]()) +
[Link]([Link]())));
}
}
import [Link].*;
import [Link].*;
/*
<applet code="[Link]" width=200 height=300>
</applet>
*/
public class swing14 extends JApplet
{
public void init()
{
JButton b[]=new JButton[13];
Container con=getContentPane();
//GridLayout gl=new GridLayout(3,4);
GridLayout gl=new GridLayout(3,4,20,10);
[Link](gl);
for(int i=0;i<[Link];i++)
{
b[i]=new JButton("button"+i);
[Link](b[i]);
}
}
}
import [Link].*;
import [Link].*;
import [Link].*;
/*
<applet code="[Link]" width=200 height=300>
</applet>
*/
public class swing15 extends JApplet implements MouseListener, MouseMotionListener
{
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseEntered(MouseEvent m)
{
[Link](" mouse entered at :"+[Link]()+","+[Link]());
}
public void mouseExited(MouseEvent m)
{
[Link](" mouse exited at :"+[Link]()+","+[Link]());
}
public void mousePressed(MouseEvent m)
{
[Link](" mouse pressed at :"+[Link]()+","+[Link]());
}
public void mouseReleased(MouseEvent m)
{
[Link](" mouse released at :"+[Link]()+","+[Link]());
}
public void mouseClicked(MouseEvent m)
{
[Link](" mouse clicked at :"+[Link]()+","+[Link]());
}
public void mouseMoved(MouseEvent m)
{
[Link](" mouse moved at :"+[Link]()+","+[Link]());
}
public void mouseDragged(MouseEvent m)
{
[Link](" mouse dragged at :"+[Link]()+","+[Link]());
}
}
import [Link].*;
import [Link].*;
import [Link].*;
/*
<applet code=[Link] width=200 height=300>
</applet>
*/
[Link](i3);
[Link](i2);
[Link](i1);
[Link]("enable button");
[Link]("disable button");
[Link]('e');
[Link]('d');
Container con=getContentPane();
[Link](new FlowLayout());
[Link](b1);[Link](b2);[Link](b3);
[Link](this);
[Link](this);
}
public void actionPerformed(ActionEvent a)
{
JButton b=(JButton)[Link]();
if(b==b1)
{
[Link](true);
[Link](false);
[Link](true);
}
else if(b==b2)
{
[Link](false);
[Link](false);
[Link](true);
}
}
}
import [Link].*;
import [Link].*;
/*
<applet code="swing18" width=300 height=300>
</applet>
*/
public class swing18 extends JApplet
{
public void init()
{
JRadioButton r1=new JRadioButton("radio1");
JRadioButton r2=new JRadioButton("radio2");
JRadioButton r3=new JRadioButton("radio3");
Box h1=[Link]();
[Link](r1);[Link](r2);[Link](r3);
Box h2=[Link]();
[Link](c1);[Link](c2);[Link](c3);
Box h3=[Link]();
[Link](t1);[Link](t2);[Link](t3);
Box v1=[Link]();
[Link](h1);[Link](h2);[Link](h3);
Container con=getContentPane();
[Link](new FlowLayout());
[Link](v1);
ButtonGroup bg1=new ButtonGroup();
[Link](r1);[Link](r2);[Link](r3);
//ButtonGroup bg2=new ButtonGroup();
//[Link](c1);[Link](c2);[Link](c3);
//ButtonGroup bg3=new ButtonGroup();
//[Link](t1);[Link](t2);[Link](t3);
}
}
import [Link].*;
import [Link].*;
/*
<applet code="swing19" width=300 height=300>
</applet>
*/
public class swing19 extends JApplet
{
public void init()
{ Icon i1=new ImageIcon("[Link]");
Icon i2=new ImageIcon("[Link]");
JCheckBox c1=new JCheckBox();
JCheckBox c2=new JCheckBox("bold");
JCheckBox c3=new JCheckBox("bold",true);
JCheckBox c4=new JCheckBox(i1);
JCheckBox c5=new JCheckBox(i1,true);
JCheckBox c6=new JCheckBox("bold",i1);
JCheckBox c7=new JCheckBox("bold",i1,true);
[Link](i2);
[Link](i2);
[Link](i2);
Container con=getContentPane();
[Link](new FlowLayout());
[Link](c1);[Link](c2);[Link](c3);
[Link](c4);[Link](c5);[Link](c6);[Link](c7);
}
}
import [Link].*;
import [Link].*;
import [Link].*;
Box v1=[Link]();
[Link](r1);[Link](r2);[Link](r3);
//Container con = getContentPane();
//[Link](v1);
Box v2=[Link]();
[Link](r4);[Link](r5);[Link](r6);
//[Link](v2);
Box hb=[Link]();
[Link]([Link]());
[Link](v1);
[Link]([Link]());
[Link](v2);
[Link]([Link]());
Container con=getContentPane();
[Link]("North",hb);
[Link](l1);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
}
public void itemStateChanged(ItemEvent i)
{
String str="";
if( [Link]())
str+=[Link]()+" ";
if( [Link]())
str+=[Link]()+" ";
if( [Link]())
str+=[Link]()+" ";
if( [Link]())
str+=[Link]()+" ";
if( [Link]())
str+=[Link]()+" ";
if( [Link]())
str+=[Link]()+" ";
[Link](str);
}
}
import [Link].*;
import [Link].*;
public class swing21 extends JApplet
{
public void init()
{
JTextArea ta1=new JTextArea();
JTextArea ta2=new JTextArea(6,40);
JTextArea ta3=new JTextArea("welcome to satya");
JTextArea ta4=new JTextArea("java by rami reddy",6,40);
JScrollPane jsp=new JScrollPane(ta4);
Container con=getContentPane();
[Link](new FlowLayout());
[Link](ta1);[Link](ta2);
[Link](ta3);[Link](jsp);
}
}
/*
<applet code=swing21 width=800 height=600>
</applet>
*/
import [Link].*;
import [Link].*;
import [Link].*;
public class swing22 extends JFrame
implements ActionListener
{
public static void main(String args[])
{ swing22 f=new swing22();
[Link](700,500);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
JLabel l1,l2,l3;
JButton b1,b2,b3,b4,b5,b6,b7;
JTextField tf1,tf2,tf3;
JTextArea ta;
public swing22()
{
l1=new JLabel("String :");
l2=new JLabel("St. index :");
l3=new JLabel("End index :");
tf1=new JTextField(15);
tf2=new JTextField(4);
tf3=new JTextField(4);
JPanel p1=new JPanel();
[Link](l1);[Link](tf1);
[Link](l2);[Link](tf2);
[Link](l3);[Link](tf3);
ta=new JTextArea();
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
Font f1=new Font("Arial",[Link],20);
[Link](f1); [Link](f1);
[Link](f1); [Link](f1);
JScrollPane jsp=new
JScrollPane(ta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,[Link]
ONTAL_SCROLLBAR_ALWAYS);
b1=new JButton("insert");
b2=new JButton("replace");
b3=new JButton("append");
b4=new JButton("cut");
b5=new JButton("copy");
b6=new JButton("paste");
b7=new JButton("get info");
JPanel p2=new JPanel();
[Link](b1);[Link](b2);[Link](b3);
[Link](b4);[Link](b5);[Link](b6);[Link](b7);
Container con=getContentPane();
[Link]("North",p1);
[Link](jsp);
[Link]("South",p2);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
}
public void actionPerformed(ActionEvent a)
{
String str=[Link]();
if([Link]("insert"))
{
[Link]([Link](),[Link]());
}
else if([Link]("replace"))
{
[Link]([Link]());
[Link]([Link](),[Link]([Link]()),[Link](tf3.g
etText()));
}
else if([Link]("append"))
{
[Link]([Link]());
}
else if([Link]("cut"))
{
[Link]();
}
else if([Link]("copy"))
{
[Link]();
}
else if([Link]("paste"))
{
[Link]();
}
else if([Link]("get info"))
{
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link](true);
[Link](20);
[Link]([Link]);
}
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public class swing23 extends JFrame
implements ComponentListener,MouseListener
{
public static void main(String args[])
{ swing23 f=new swing23();
[Link](200,100,300,300);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
public swing23()
{
addComponentListener(this);
addMouseListener(this);
}
public void componentShown(ComponentEvent c)
{
[Link]("component shown...");
}
public void componentHidden(ComponentEvent c)
{
[Link]("component hidden...");
}
public void componentMoved(ComponentEvent c)
{
[Link]("component moved...");
}
public void componentResized(ComponentEvent c)
{
[Link]("component resized...");
}
public void mouseClicked(MouseEvent m)
{
setVisible(false);
try{
[Link](5000);
}catch(InterruptedException e){ [Link](e); }
setVisible(true);
}
public void mouseReleased(MouseEvent m){}
public void mousePressed(MouseEvent m){}
public void mouseExited(MouseEvent m){}
public void mouseEntered(MouseEvent m){}
}
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class swing24 extends JPanel implements ActionListener
{
public static void main(String args[])
{
JFrame f=new JFrame();
Container con=[Link]();
[Link](new swing24());
[Link](700,400);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
public swing24()
{
JButton b1=new JButton("show dialog..");
setBackground([Link]);
add(b1);
[Link](this);
}
public void actionPerformed(ActionEvent e)
{
String str="";
int r =[Link](this,"do you wish to display time
also?","confirmation",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MES
SAGE);
if(r == 0)
{
DateFormat
df=[Link]([Link],[Link]);
str=[Link](new Date());
}
else if(r==1)
{
DateFormat df=[Link]([Link]);
str=[Link](new Date());
}
[Link](this,str,"date &
time",JOptionPane.INFORMATION_MESSAGE);
}
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class swing25 extends JFrame
implements ActionListener
{
public static void main(String args[])
{
swing25 f=new swing25();
[Link](700,400);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
public swing25()
{
JButton b1=new JButton("show dialog..");
Container con=getContentPane();
[Link](new FlowLayout());
[Link](b1);
[Link](this);
}
public void actionPerformed(ActionEvent e)
{
String msg=(String)[Link](this,"enter your name :");
[Link](this,"hello "+msg);
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public class swing26 extends JFrame
implements ActionListener
{
public static void main(String args[])
{
swing26 f=new swing26();
[Link](700,400);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
Container con;
public swing26()
{
JButton b1=new JButton("show dialog..");
con=getContentPane();
[Link](new FlowLayout());
[Link](b1);
[Link](this);
}
public void actionPerformed(ActionEvent e)
{ String colors[]={"red","blue","green","yellow","magenta","pink"};
String msg=(String)[Link](this,"enter your name
:","colors",JOptionPane.WARNING_MESSAGE,null,colors,colors[2]);
if(msg !=null)
{
if([Link]("red"))
[Link]([Link]);
else if([Link]("blue"))
[Link]([Link]);
else if([Link]("green"))
[Link]([Link]);
else if([Link]("magenta"))
[Link]([Link]);
else if([Link]("yellow"))
[Link]([Link]);
else if([Link]("pink"))
[Link]([Link]);
}
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public class swing27 extends JFrame
implements ActionListener,ContainerListener
{
public static void main(String args[])
{
swing27 f=new swing27();
[Link](700,500);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
JButton b1,b2,b3;
Container con;
public swing27()
{
b1=new JButton("add");
b2=new JButton("remove");
b3=new JButton("welcome",new ImageIcon("[Link]"));
con=getContentPane();
[Link](new FlowLayout());
[Link](b1);[Link](b2);[Link](b3);
[Link](this);
[Link](this);
[Link](this);
}
public void actionPerformed(ActionEvent a)
{
String str=[Link]();
if([Link]("add"))
[Link](b3);
else
[Link](b3);
repaint();
}
public void componentAdded(ContainerEvent c)
{
[Link]([Link]);
}
public void componentRemoved(ContainerEvent c)
{
[Link]([Link]);
}
}
import [Link].*;
import [Link].*;
public class swing28 extends JApplet
implements KeyListener
{
public void init()
{
addKeyListener(this);
}
public void keyPressed(KeyEvent k)
{
[Link]("key pressed :"+[Link]());
}
public void keyReleased(KeyEvent k)
{
[Link]("key released..");
}
public void keyTyped(KeyEvent k)
{
[Link]("key typed :"+[Link]());
}
}
/*
<applet code=swing28 width=200 height=200>
</applet>
*/
import [Link].*;
import [Link].*;
import [Link].*;
public class swing29 extends JFrame
{
Box vb=[Link]();
[Link]([Link]());
[Link](s1);
[Link]([Link]());
[Link](s2);
[Link]([Link]());
tf=new JTextField();
[Link]([Link]);
[Link](new Font("Arial",[Link],20));
setLayout(new BorderLayout());
add(vb);
add("South",tf);
[Link](this);
}
public void stateChanged(ChangeEvent c)
{
[Link]([Link]([Link]()));
}
}
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class swing32 extends JPanel
implements ActionListener
{ public static void main(String args[])
{
JFrame f1=new JFrame();
[Link]().add(new swing32());
[Link](600,400);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
JButton b1,b2,b3;
JLabel l1;
[Link] t1;
public swing32()
{
l1=new JLabel(new Date().toString(),[Link]);
b1=new JButton("start");
b2=new JButton("stop");
b3=new JButton("restart");
JPanel p1=new JPanel();
[Link](b1);[Link](b2);[Link](b3);
setLayout(new BorderLayout());
add(l1);
add("South",p1);
setLayout(new BorderLayout());
add(tf1);
add("South",b1);
jc=new JColorChooser();
jd=[Link](this,"color dialog",
true,jc,this,this);
[Link](this);
}
public void actionPerformed(ActionEvent a)
{
String str=[Link]();
if([Link]("OK"))
{
[Link]([Link]());
[Link]();
}
else if([Link]("Cancel"))
{
[Link]();
}
else if([Link]("show color dialog.."))
{
[Link]();
}
}
}
import [Link].*;
import [Link].*;
public class swing34 extends JApplet
{
public void init()
{ swing24 p1=new swing24();
swing31 p2=new swing31();
swing32 p3=new swing32();
swing33 p4=new swing33();
//JTabbedPane jt=new JTabbedPane();
JTabbedPane jt=new JTabbedPane([Link]);
[Link]("dialogs",new ImageIcon("[Link]"),p1,"dialogs demo");
[Link]("sliders",null,p2,"sliders demo");
[Link]("timer",null,p3,"timer demo");
[Link]("colors",null,p4,"color chooser demo",1);
Container con=getContentPane();
[Link](jt);
}
}
/*
<applet code=swing34 width=600 height=400>
</applet>
*/
import [Link].*;
import [Link].*;
public class swing35 extends JApplet
{
public void init()
{ swing24 p1=new swing24();
swing31 p2=new swing31();
swing32 p3=new swing32();
JSplitPane jsp=new JSplitPane(JSplitPane.VERTICAL_SPLIT,p1,p2);
JSplitPane jsp1=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
[Link](p3);
[Link](jsp);
Container con=getContentPane();
[Link](jsp1);
}
}
/*
<applet code=swing35 width=600 height=400>
</applet>
*/
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class swing36 extends JFrame
implements ActionListener
{
public static void main(String args[])
{
swing36 f=new swing36();
[Link](800,550);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
JMenuItem m11,m12,m13,m14,m21,m22,m23;
JCheckBoxMenuItem m31,m32;
JRadioButtonMenuItem f1,f2,f3,b1,b2,b3;
JTextArea ta;
JFileChooser fc;
public swing36()
{
JMenu m1=new JMenu("File");
[Link](new ImageIcon("[Link]"));
[Link]('f');
m11=new JMenuItem("New");
m12=new JMenuItem("Open",new ImageIcon("[Link]"));
m13=new JMenuItem("Save",new ImageIcon("[Link]"));
m14=new JMenuItem("Exit",'e');
[Link](m11);
[Link]();
[Link](m12);[Link](m13);
[Link]();
[Link](m14);
ta=new JTextArea();
[Link](new Font("Arial",[Link],20));
[Link]([Link]);
JScrollPane jsp=new
JScrollPane(ta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,[Link]
ONTAL_SCROLLBAR_ALWAYS);
Container con=getContentPane();
[Link]("North",mb);
[Link](jsp);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
fc=new JFileChooser();
}
public void actionPerformed(ActionEvent a)
{ try{
JMenuItem m=(JMenuItem)[Link]();
if(m==m11)
[Link]("");
else if(m==m14)
[Link](0);
else if(m==m12)
{
int r=[Link](this);
if(r==JFileChooser.APPROVE_OPTION)
{
File f1=[Link]();
BufferedReader br=new BufferedReader(new FileReader(f1));
String str="";
while((str=[Link]())!= null)
{
[Link](str+"\n");
}
[Link]();
}
else if(r==JFileChooser.CANCEL_OPTION)
{
[Link](this,"cancel button is clicked..");
}
}
else if(m==m13)
{
int r=[Link](this);
if(r==JFileChooser.APPROVE_OPTION)
{
File f1=[Link]();
FileWriter fp=new FileWriter(f1);
[Link]([Link]());
[Link]();
[Link](this,"file saved");
}
else if(r==JFileChooser.CANCEL_OPTION)
{
[Link](this,"cancel button is clicked..");
}
}
}catch(IOException e)
{
[Link](e);
}
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public class swing37 extends JFrame
implements ActionListener
{
public static void main(String args[])
{
swing37 f=new swing37();
[Link](700,450);
[Link](true);
}
JButton b1,b2,b3;
JTextArea ta;
JMenuItem m1,m2,m3;
JPopupMenu pm;
public swing37()
{
addWindowListener(new mywindow());
ta=new JTextArea();
[Link](new Font("Arial",[Link],20));
[Link]([Link]);
JScrollPane jsp=new
JScrollPane(ta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,[Link]
ONTAL_SCROLLBAR_ALWAYS);
JToolBar jt=new JToolBar();
[Link](false);
[Link](b1=new JButton(new ImageIcon("[Link]")));
[Link](b2=new JButton(new ImageIcon("[Link]")));
[Link]();
[Link](b3=new JButton(new ImageIcon("[Link]")));
Container con=getContentPane();
[Link]("South",jt);
[Link](jsp);
pm=new JPopupMenu();
m1=new JMenuItem("cut");
m2=new JMenuItem("copy");
m3=new JMenuItem("paste");
[Link](m1);[Link](m2);[Link](m3);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](new mymouse());
}
public void actionPerformed(ActionEvent a)
{
Object obj=[Link]();
if( obj instanceof JButton)
{
JButton b=(JButton)obj;
if(b==b1)
[Link]();
else if(b==b2)
[Link]();
else if(b==b3)
[Link]();
}else if( obj instanceof JMenuItem)
{
JMenuItem m=(JMenuItem)obj;
if(m==m1)
[Link]();
else if(m==m2)
[Link]();
else if(m==m3)
[Link]();
}
}
public class mymouse extends MouseAdapter
{
public void mouseReleased(MouseEvent m)
{
if([Link]())
{
[Link]([Link](),[Link](),[Link]());
}
}
}
public class mywindow extends WindowAdapter
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public class swing38 extends JApplet
{ Canvas c1;
JButton b1;
public void init()
{
b1=new JButton("demo button");
c1=new Canvas();
[Link]([Link]);
[Link](300,300);
Container con=getContentPane();
[Link](new FlowLayout());
[Link](b1);[Link](c1);
}
}
/*
<applet code=swing38 width=600 height=400>
</applet>
*/
import [Link].*;
import [Link].*;
import [Link].*;
public class swing39 extends JApplet
implements AdjustmentListener
{ JScrollBar s1,s2;
JTextField tf;
public void init()
{
s1=new JScrollBar();
s2=new JScrollBar([Link],200,0,0,1000);
[Link](10);
[Link](50);
[Link](20,50,30,200);
[Link](50,20,200,30);
tf=new JTextField();
[Link](100,100,100,30);
Container con=getContentPane();
[Link](null);
[Link](s1);[Link](s2);[Link](tf);
[Link](this);
[Link](this);
}
public void adjustmentValueChanged(AdjustmentEvent a)
{
JScrollBar s=(JScrollBar)[Link]();
[Link]([Link]([Link]()));
}
}
/*
<applet code=swing39 width=500 height=400>
</applet>
*/
import [Link].*;
import [Link].*;
import [Link].*;
public class swing40 extends JApplet
{ JTable jt;
public void init()
{
String columns[]={"student number","student name","student courses"};
String data[][]={{"1001","ram","java,oracle"},
{"1002","sam","c,c++,java"},
{"1003","sita","j2ee,j2me"},
{"1004","raju","java,dba,d2k"}};
jt=new JTable(data,columns);
[Link]([Link]);
[Link]([Link]);
JScrollPane jsp=new JScrollPane(jt);
Container con=getContentPane();
[Link](jsp);
[Link](new mymouse());
}
public class mymouse extends MouseAdapter
{
public void mouseClicked(MouseEvent m)
{
int rows=[Link]();
int cols=[Link]();
int r=[Link]();
int c=[Link]();
[Link]("rows :"+rows);
[Link]("columns :"+cols);
[Link]("selected row :"+r);
[Link]("selected column :"+c);
[Link]("COLUMN NAMES :");
for(int i=0;i<cols;i++)
[Link]([Link](i));
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class swing41 extends JApplet
implements TreeSelectionListener
{ JTree jt;
JTextField tf;
public void init()
{
DefaultMutableTreeNode n=new DefaultMutableTreeNode("java topics");
DefaultMutableTreeNode n1=new DefaultMutableTreeNode("coretopics");
DefaultMutableTreeNode n2=new DefaultMutableTreeNode("[Link]");
DefaultMutableTreeNode n11=new DefaultMutableTreeNode("interfaces");
DefaultMutableTreeNode n12=new DefaultMutableTreeNode("packages");
DefaultMutableTreeNode n13=new DefaultMutableTreeNode("exceptions");
DefaultMutableTreeNode n14=new DefaultMutableTreeNode("iostreams");
DefaultMutableTreeNode n15=new DefaultMutableTreeNode("threads");
DefaultMutableTreeNode n21=new DefaultMutableTreeNode("swings");
DefaultMutableTreeNode n22=new DefaultMutableTreeNode("jdbc");
DefaultMutableTreeNode n23=new DefaultMutableTreeNode("servlets");
DefaultMutableTreeNode n24=new DefaultMutableTreeNode("jsp");
DefaultMutableTreeNode n25=new DefaultMutableTreeNode("rmi");
DefaultMutableTreeNode n26=new DefaultMutableTreeNode("sockets");
[Link](n11);[Link](n12);[Link](n13);[Link](n14);[Link](n15);
[Link](n21);[Link](n22);[Link](n23);[Link](n24);[Link](n25);[Link](n26);
[Link](n1);[Link](n2);
jt=new JTree(n);
JScrollPane jsp=new JScrollPane(jt);
//[Link](50);
//[Link](true);
DefaultTreeCellRenderer r=(DefaultTreeCellRenderer)[Link]();
[Link](new ImageIcon("[Link]"));
[Link](new ImageIcon("[Link]"));
[Link](new ImageIcon("[Link]"));
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
tf=new JTextField();
Container con=getContentPane();
[Link](jsp);
[Link]("South",tf);
[Link](this);
}
public void valueChanged(TreeSelectionEvent e)
{
TreePath tp=[Link]();
[Link]([Link]());
Object obj[]=[Link]();
for(int i=0;i<[Link];i++)
[Link](obj[i]);
}
}
/*
<applet code=swing41 width=500 height=400>
</applet>
*/
import [Link].*;
import [Link].*;
import [Link].*;
public class swing42 extends JApplet
implements ActionListener
{ JComboBox jc;
JButton b1;
public void init()
{ String weeks[]={"Sunday","Monday","Wednesday","Thursday","Friday"};
jc=new JComboBox(weeks);
[Link]("Saturday");
[Link]("Tuesday",2);
[Link](4);
b1=new JButton("remove");
Container con=getContentPane();
[Link](new FlowLayout());
[Link](jc);[Link](b1);
[Link](this);
[Link](this);
}
public void actionPerformed(ActionEvent a)
{
Object obj=[Link]();
if(obj instanceof JComboBox)
{
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link](4));
[Link]([Link]());
}
else if(obj instanceof JButton)
{
[Link]();
// [Link]("Tuesday");
// [Link](2);
}
}
}
/*
<applet code=swing42 width=500 height=400>
</applet>
*/
import [Link].*;
import [Link].*;
import [Link].*;
public class swing43 extends JApplet
{ JComboBox jc;
Icon icons[]={new ImageIcon("[Link]"),new ImageIcon("[Link]"),new
ImageIcon("[Link]"),new ImageIcon("[Link]"),new ImageIcon("[Link]"),new
ImageIcon("[Link]"),new ImageIcon("[Link]")};
public void init()
{ String
weeks[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
};
jc=new JComboBox(weeks);
[Link](4);
[Link](new Dimension(200,40));
Container con=getContentPane();
[Link](new FlowLayout());
[Link](jc);
[Link](new democlass());
}
public class democlass extends JLabel implements ListCellRenderer
{
public democlass()
{
setOpaque(true);
}
public Component getListCellRendererComponent(JList j1,Object value,int
index,boolean isSelected,boolean hasfocus)
{
if( value !=null)
setText((String)value);
if( index >= 0 && index <= [Link])
setIcon(icons[index]);
if(isSelected)
{
setBackground([Link]);
setForeground([Link]);
}
else
{
setBackground([Link]);
setForeground([Link]);
}
return this;
}
}
}
/*
<applet code=swing43 width=500 height=400>
</applet>
*/
import [Link].*;
import [Link].*;
import [Link].*;
public class swing44 extends JApplet
{ JList list1;
Icon icons[]={new ImageIcon("[Link]"),new ImageIcon("[Link]"),new
ImageIcon("[Link]"),new ImageIcon("[Link]"),new ImageIcon("[Link]"),new
ImageIcon("[Link]"),new ImageIcon("[Link]")};
public void init()
{ String
weeks[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
};
list1=new JList(weeks);
JScrollPane jsp=new JScrollPane(list1);
[Link](new Dimension(200,150));
Container con=getContentPane();
[Link](new FlowLayout());
[Link](jsp);
[Link](new democlass());
}
public class democlass extends JLabel implements ListCellRenderer
{
public democlass()
{
setOpaque(true);
}
public Component getListCellRendererComponent(JList j1,Object value,int
index,boolean isSelected,boolean hasfocus)
{
if( value !=null)
setText((String)value);
if( index >= 0 && index <= [Link])
setIcon(icons[index]);
if(isSelected)
{
setBackground([Link]);
setForeground([Link]);
}
else
{
setBackground([Link]);
setForeground([Link]);
}
return this;
}
}
}
/*
<applet code=swing44 width=500 height=400>
</applet>
*/
import [Link].*;
import [Link].*;
import [Link].*;
public class swing45 extends JApplet
{ JList list1; JCheckBox c1;
JButton b1;
public void init()
{
String
courses[]={"oracle","java","j2ee","j2me","dba","c++","vc++","d2k","[Link]","[Link]"};
list1=new JList(courses);
JScrollPane jsp=new JScrollPane(list1);
[Link](new Dimension(200,150));
[Link](new Font("Arial",[Link],20));
[Link]([Link]);
c1=new JCheckBox("multiple",true);
b1=new JButton("get item(s)");
Container con=getContentPane();
[Link](new FlowLayout());
[Link](jsp);[Link](c1);[Link](b1);
[Link](new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
if( [Link]())
{
Object items[]=[Link]();
int n[]=[Link]();
[Link]("MULTIPLE SELECTIONS..");
for(int i=0;i<[Link];i++)
[Link](n[i]+" : "+items[i]);
}
else
{
[Link]("SINGLE SELECTION...");
[Link]([Link]()+" :
"+[Link]());
}
}
});
[Link](new ItemListener()
{
public void itemStateChanged(ItemEvent i)
{
if([Link]())
{
[Link](ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
}
else
{
[Link](ListSelectionModel.SINGLE_SELECTION);
}
[Link]();
}
});
}
}
/*
<applet code=swing45 width=600 height=400>
</applet>
*/
import [Link].*;
import [Link].*;
import [Link].*;
public class swing46 extends JFrame
implements ActionListener
{
public static void main(String args[])
{
swing46 f=new swing46();
[Link](700,450);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
JButton b1,b2,b3,b4;
JComboBox c;
JPanel mp;
CardLayout cl;
public swing46()
{
b1=new JButton("first");
b2=new JButton("previous");
b3=new JButton("next");
b4=new JButton("last");
String items[]={"card1","card2","card3","card4"};
c=new JComboBox(items);
JPanel tp=new JPanel();
[Link](b1);[Link](b2);[Link](b3);[Link](b4);[Link](c);
mp=new JPanel();
cl=new CardLayout();
[Link](cl);
swing24 c1=new swing24();
swing31 c2=new swing31();
swing32 c3=new swing32();
swing33 c4=new swing33();
[Link](c1,"card1");
[Link](c2,"card2");
[Link](c3,"card3");
[Link](c4,"card4");
Container con=getContentPane();
[Link]("North",tp);
[Link](mp);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
}
public void actionPerformed(ActionEvent a)
{
Object obj=[Link]();
if(obj instanceof JButton)
{
JButton b=(JButton)obj;
if(b==b1)
[Link](mp);
else if(b==b2)
[Link](mp);
else if(b==b3)
[Link](mp);
else if(b==b4)
[Link](mp);
}
else
{
[Link](mp, (String)[Link]() );
}
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public class swing47 extends JFrame
implements ActionListener
{
public static void main(String args[])
{ swing47 f=new swing47();
[Link](220,150);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
JProgressBar p1;
JButton b1,b2;
public swing47()
{
p1=new JProgressBar();
b1=new JButton("start");
b2=new JButton("stop");
[Link](10,10,200,40);
[Link](10,70,90,30);
[Link](110,70,90,30);
Container con=getContentPane();
[Link](null);
[Link](p1);[Link](b1);[Link](b2);
[Link](this);
[Link](this);
}
demothread t1;
public void actionPerformed(ActionEvent a)
{
JButton b=(JButton)[Link]();
if(b==b1)
{
if( t1 ==null || ! [Link]())
{
t1=new demothread();
[Link]();
}
}
else if(b==b2)
{
[Link]=true;
}
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public class swing48 extends JFrame
implements ActionListener
{
public static void main(String args[])
{ swing48 f=new swing48();
[Link](220,150);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
JButton b1,b2;
Container con;
public swing48()
{
b1=new JButton("start");
b2=new JButton("stop");
[Link](10,70,90,30);
[Link](110,70,90,30);
con=getContentPane();
[Link](null);
[Link](b1);[Link](b2);
[Link](this);
[Link](this);
}
demothread t1;
public void actionPerformed(ActionEvent a)
{
JButton b=(JButton)[Link]();
if(b==b1)
{
if( t1 ==null || ! [Link]())
{
t1=new demothread();
[Link]();
}
}
else if(b==b2)
{
[Link]=true;
}
}
}
import [Link].*;
import [Link].*;
import [Link].*;
public class swing49 extends JFrame
implements ActionListener
{
public static void main(String args[])
{ swing49 f=new swing49();
[Link](700,550);
[Link](true);
[Link](new WindowAdapter()
{
public void windowClosing(WindowEvent w)
{
[Link](0);
}
});
}
JMenuItem m1,m2,m3,m4;
JInternalFrame f1;
JDesktopPane jd;
public swing49()
{
JMenu m=new JMenu("Demos");
[Link](m1=new JMenuItem("dialogs"));
[Link](m2=new JMenuItem("slider"));
[Link](m3=new JMenuItem("timer"));
[Link](m4=new JMenuItem("colos"));
jd=new JDesktopPane();
Container con=getContentPane();
[Link]("North",mb);
[Link](jd);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
}
JMenuItem m1,m2,m3;
public swing50()
{
JMenu m=new JMenu("Look & Feel");
[Link](m1=new JMenuItem("Windows"));
[Link](m2=new JMenuItem("Motif"));
[Link](m3=new JMenuItem("Metal"));
Container con=getContentPane();
[Link]("North",mb);
[Link](p1);
[Link](this);
[Link](this);
[Link](this);
[Link](new JMenuItem("New"));
[Link](new JMenuItem("Open"));
[Link]();
[Link](new JMenuItem("Save"));
[Link](new JMenuItem("Save as"));
[Link]();
[Link](new JMenuItem("New"));
[Link](new JMenuItem("Open"));
[Link]();
[Link](new JMenuItem("Save"));
[Link](new JMenuItem("Save as"));
[Link]();
Object[][] rowdata = {
{"[Link]","149","09-11-07",new Boolean(false)},
{"real","dir","12-11-07",new Boolean(true)},
};
[Link](col11);
[Link](col12);
[Link](col21);
[Link](col22);
[Link](col31);
[Link](col41);
[Link](col42);
[Link](col43);
jdk1.5
class argstest
{
public static void main(String[] args)
{
int x=[Link](args[0]);
[Link]("x value is :"+x);
int y=[Link](args[1]);
[Link]("x value is :"+y);
}
}
class autobox1
{
static int m(Integer v)
{
return v;
}
public static void main(String[] args)
{
int i=10;
Integer ival=m(100);
[Link](ival);
}
}
class autobox2
{
public static void main(String[] args)
{
Integer ival =100;
Double dval=98.5;
dval = dval+ival;
[Link]("dval value is!"+dval);
}
}
enum Apple
{
goldendel,reddel,cortland,kashmiri,london
}
class enumdemo
{
public static void main(String[] args)
{
Apple ap;
ap=[Link];
[Link]("value of ap is :"+ap);
ap=[Link];
if(ap==[Link])
[Link]("ap contains london ");
switch(ap)
{
case goldendel: [Link]("goldendel is yellow");
break;
import [Link].*;
class simple
{
public static void main(String[] args)
{
try
{
new class1().meth01();
}
catch(exp1 e)
{
[Link]("Cause is:\n" + [Link]());
[Link]("Print StackTrace"+[Link]());
}
}
}
//===================================//
//This is a new exception class
class exp1 extends Exception
{
public exp1() { }
public exp1(String message)
{
super(message);
}
public exp1(Throwable throwable)
{
super(throwable);
}
public exp1(String message,Throwable throwable)
{
super(message, throwable);
}
}//end exp1
//===================================//
class Class1
{
void meth01() throws exp1
{
try
{
meth02();
}
catch(exp2 e)
{
[Link]("Cause is:\n" + [Link]());
throw new exp1("Msg from meth01",e);
}
}
//---------------------------------//
void meth03()
{
try
{
int x = 3/0;
}
catch(ArithmeticException e)
{
IndexOutOfBoundsException ex = new IndexOutOfBoundsException("Msg from
metho03");
[Link](e);
throw ex;
}
}
}
import [Link].*;
class simple
{
public static void main(String[] args)
{
try
{
new Class1().meth01();
}
catch(exp1 e)
{
[Link]("Cause is:\n" + [Link]());
// [Link]();
}
}
}
//===================================//
class Class1
{
void meth01() throws exp1
{
try
{
meth02();
}
catch(exp2 e)
{
[Link]("Cause is:\n" + [Link]());
throw new exp1("Msg from meth01",e);
}
}
//---------------------------------//
void meth03()
{
try
{
int x = 3/0;
}
catch(ArithmeticException e)
{
IndexOutOfBoundsException ex = new IndexOutOfBoundsException("Msg from
metho03");
[Link](e);
throw ex;
}
}
}
port [Link].*;
class formatdemo
{
public static void main(String[] args)
{
int a=20,b=30;
Formatter fmt =new Formatter();
[Link]("formatting %s is easy %d %f ", "with java",10,98.6);
[Link](fmt);
}
}
class Gen<T>
{
T ob;
Gen( T o)
{
ob=o;
}
T getob()
{
return ob;
}
void showType()
{
[Link]("The type of T is "+[Link]().getName());
}
}
class Gendemo
{
public static void main(String[] args)
{
Gen<Integer> iob=new Gen<Integer>(66);
[Link]();
int v= [Link]();
[Link]("value is :"+v);
class Avgnum
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
int count =0;
double sum=0.0;
[Link]("enter numbers to find the average");
while([Link]())
{
if([Link]())
{
sum +=[Link]();
count++;
}
else
{
String str =[Link]();
if([Link]("done")) break;
else
{
[Link]("the data format error");
return;
}
}
}
[Link]("the average is :"+sum/count);
}
}
import static [Link].*;
class Test
{
public static void main(String[] args)
{
[Link]("Hello World!");
[Link]("hello this is core class");
[Link]("how r u ");
[Link]("hyd");
}
}
class passarray
{
static void vatest(int ... v)
{
[Link]("number of args:"+[Link]+"contents");
for(int x : v)
[Link](x+" ");
[Link]();
}
public static void main(String[] args)
{
//int n1[ ] = {10};
//int n2[ ] = {1,2,3};
//int n3[ ] ={ };
vatest(10);
vatest(10,20);
vatest();
}
}
class passarray2
{
static void vatest(int ... v)
{
[Link]("number of args:"+[Link]+"contents");
for(int x : v)
[Link](x+" ");
[Link]();
}
public static void main(String[] args)
{
vatest(10);
vatest(1,2,3);
vatest();
}
}
sliptest
class NFE
{
public static void main(String[] args)
{
String s="22";
try
{
s=[Link](".5");
double d = [Link](s);
s=[Link](d);
int x = (int)([Link](s).doubleValue());
[Link](x);
}
catch(NumberFormatException e)
{
[Link]("bad number");
}
}
}
/*
what is the result?
A. 22
B. 22.5
C. 23
D. bad number
E. Compilation fails
F. An uncaught exception is thrown at runtime.
*/
class C extends A
{
int getNum()
{
return num;
}
}
class B
{
public int name;
}
class A
{
B b = new B();
public int num;
}
class Over
{
int doStuff(int a,float b)
{
return 7;
}
}
class Over2 extends Over
{
// insert code here
}
/*
which two methods if inserted independently at line 10 will compile(choose two)
A. private int doStuff(int x,float y) { return 4;}
B. protected int doStuff(int x,float y) { return 4;}
C. Integer doStuff(int d,float e) { return 4;}
D. long doStuff(int x,float y) { return 4;}
E. int doStuff(float x,int y) { return 4;}
*/
class A
{
public void m1()
{
[Link]("ma");
}
}
class B extends A
{
public static void main(String args[])
{
A a = new B();
a.m1();
}
public void m1()
{
[Link]("mb");
}
}
/*
what is the result?
A. ma
B. mb
C. mamb
D. Compilation fails
E. An exception is thrown at runtime
*/
class test
{
public static void main(String args[])
{
char ch;
String test2 = "abcd";
String test = new String("abcd");
if([Link](test2))
{
if(test == test2)
ch=[Link](0);
else
ch=[Link](1);
}
else
{
if(test == test2)
ch=[Link](2);
else
ch=[Link](3);
}
[Link](ch);
}
}
class CommandArgs
{
public static void main(String args[])
{
//String [] argh;
int x;
x=[Link];
for(int y=0;y<=x;y++)
{
[Link](args[y]);
}
}
}
/*
class TestStr
{
public static void main(String args[])
{
String s1 ="1";
String s2 = "2";
String s3 = s1;
s1="3";
[Link](s1 + s2 + s3);
}
}
/*
what is the result?
A. 6
B. 123
C. 321
D. 323
E. compilation fails.
F. An exception is thrown at runtime.
*/
class test
{
public static void main(String args[])
{
int [] arr = {1,2,3,4};
call_array(arr[0],arr);
[Link](arr[0]+ ", "+arr[1]);
}
static void call_array(int i,int arr[])
{
arr[i]=6;
i=5;
}
}
A. 1,2
B. 5,2
C. 1,6
D. 5,6
class LoopTest
{
public static void main(String args[])
{
int a =1;
while(a++<=1)
while(a++<=2)
while(a++<=3);
[Link]("a value is :"+a);
}
}
class TestDogs
{
public static void main(String args[])
{
Dog [][][] theDogs = new Dog[3][2][];
[Link](theDogs[2][0][0].toString());
}
}
class Dog{ }
/*
what is the result
A. null
B. the dogs
C. Compilation fails
D. an exception is throwing a t run time;
*/
//what gets printed when the following code is compiled and run with the following
command
//java test 2
class test
{
public static void main(String args[])
{
Integer intObj = [Link](args[[Link]-1]);
int i = [Link]();
if([Link] >1)
[Link](i);
if([Link] >0)
[Link](i-1);
else
[Link](i-2);
}
}
/*
Select the correct answer
A. test
B. test -1
C. 0
D. 1
E. 2
*/