Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Wednesday, 13 May 2015

simple java applet example of adding components

import java.awt.*;
import java.applet.*;
public class Applet3 extends Applet
{
Label l1,l2,l3;
Choice c1,c2;
List lst;
int i;
public void init()
{
l1=new Label("Select Train Name");
l2=new Label("Select Seats             ");
l3=new Label("Cause Of Visit       ");
c1=new Choice();
c1.addItem("Rajdhani Express");
c1.addItem("GT Express");
c1.addItem("Link Express");
c1.addItem("Mussoorie Express");
c1.addItem("Shatabdi Express");
c2=new Choice();
for(i=1;i<=50;i++)
c2.addItem(String.valueOf(i));
lst=new List(6);
lst.addItem("Official");
lst.addItem("Personal");
lst.addItem("Educational");
lst.addItem("Tourism");
lst.addItem("Research");
lst.addItem("WildLife");
setBackground(Color.cyan);
add(l1);
add(c1);
add(l2);
add(c2);
add(l3);
add(lst);
}
}
/*
<applet code=Applet3 height=250 width=270></applet>
*/

mutithreding in java :create thread using Runnable


class RunnableThread implements Runnable{

 Thread runner;
 public RunnableThread() {
 }

 public RunnableThread(String threadName) {
        runner = new Thread(this, threadName);   // (1) Create a new thread.
        System.out.println(runner.getName());
        runner.start();                          // (2) Start the thread.
 }

 public void run(){
  //Display info about this particular thread
  System.out.println(Thread.currentThread());
 }


}
public class RunnableExample{
 
 public static void main(String[] args){
     Thread thread1 =  new Thread(new RunnableThread(),"thread1");
     Thread thread2 =  new Thread(new RunnableThread(),"thread2");
     RunnableThread thread3 = new RunnableThread("thread3");

//Start the threads
     thread1.start();
     thread2.start();
     try{
       //delay for one second
       Thread.currentThread().sleep(1000);
     }catch(InterruptedException e){}

     //Display info about the main thread   
     System.out.println(Thread.currentThread());       
 }
}

java applet example of drawing diffrent shapes using Graphics



import java.applet.*;
import java.awt.*;
public class  fillColor extends Applet{
   public void paint(Graphics g){
      g.drawRect(300,150,200,100);
      g.setColor(Color.yellow);  
      g.fillRect( 300,150, 200, 100 );
      g.setColor(Color.magenta);
      g.drawString("Rectangle",500,150);
   }
}
 

java applet example of changing background color on button click event

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class ColorApplet extends Applet implements ActionListener
{
 Button b1,b2,b3;

 public void init()
 {
  b1 = new Button("Red");
  b2 = new Button("Green");
  b3 = new Button("Blue");
 
  add(b1);add(b2);add(b3);
   
  b1.addActionListener(this);
  b2.addActionListener(this);
  b3.addActionListener(this);
  setBackground(Color.yellow);
 }

 public void actionPerformed(ActionEvent ae)
 {
  if(ae.getSource()==b1)
   setBackground(Color.red);
  if(ae.getSource()==b2)
   setBackground(Color.green);
  if(ae.getSource()==b3)
   setBackground(Color.blue);
 }
}


/*<applet code=ColorApplet height=300 width=300></applet>*/







 

java Applet ItemListener example

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class ItemLis extends Applet implements ItemListener
{
Label l1,l2,l3,l4,l5,l6;
TextField t1,t2,t3,t4;
Choice ch1,ch2;
int i,qty;
float pri;
public void init()
{
l1=new Label("Item Name");
l2=new Label("Quantity    ");
l3=new Label("Price           ");
l4=new Label("Amount      ");
l5=new Label("Tax              ");
l6=new Label("With Tax     ");
t1=new TextField(15);
t2=new TextField(15);
t3=new TextField(15);
t4=new TextField(15);
ch1=new Choice();
ch1.addItem("Burger");
ch1.addItem("Pizza");
ch2=new Choice();
for(i=1;i<10;i++)
ch2.addItem(String.valueOf(i));
setBackground(Color.green);
t3.setText("12.24%");
add(l1);
add(ch1);
add(l2);
add(ch2);
add(l3);
add(t1);
add(l4);
add(t2);
add(l5);
add(t3);
add(l6);
add(t4);
ch1.addItemListener(this);
ch2.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource()==ch1)
{
String inm=String.valueOf(ie.getItem());
if(inm.equals("Burger"))
{
t1.setText("Rs.75.00");
pri=75.0f;
}
else if(inm.equals("Pizza"))
{
t1.setText("Rs.125.00");
pri=125.0f;
}
}
if(ie.getSource()==ch2)
{
qty=Integer.parseInt(String.valueOf(ie.getItem()));
float amt=pri*qty;
t2.setText(String.valueOf(amt));
float tamt=amt+.1224f*amt;
t4.setText(String.valueOf(tamt));
}
}
}
/*
<applet code=ItemLis height=300 width=250></applet>
*/

java Applet LayoutExample



import java.awt.*;
import java.applet.*;
public class LayoutExample extends Applet 
    {
     Button okButton1;
     Button okButton2;
     Button okButton3;
     Button okButton4;
     Button okButton5;
     public void init()
     {
  // sets the LayoutManager to BorderLayout
        setLayout(new BorderLayout());
        okButton1 = new Button("Centered Button");
          okButton2 = new Button("Cold North");
          okButton3 = new Button("Go West");
          okButton4 = new Button("At East");
          okButton5 = new Button("Hot South");
  // always says where the component should be placed when adding
  // Options are center,East,West,Nort and South
        add(okButton1,"Center");
          add(okButton2,"North");
          add(okButton3,"West");
          add(okButton4,"East");
          add(okButton5,"South");
        }
    }
/*<applet code="LayoutExample.java" height=200 width=300></applet>*/

java Applet example of EventListeners,ActionListener(Addition ,Subtract,Multiply,Divide)

import java.applet.*;
import java.awt.event.*;
import java.awt.*;
 
public class EventListeners extends Applet implements ActionListener{
   TextArea txtArea;
   String Add, Subtract,Multiply,Divide;
   int i = 10, j = 20, sum =0,Sub=0,Mul = 0,Div = 0;
   public void init(){
   txtArea = new TextArea(10,20);
   txtArea.setEditable(false);
   add(txtArea,"center");
   Button b = new Button("Add");
   Button c = new Button("Subtract");
   Button d = new Button("Multiply");
   Button e = new Button("Divide");
   b.addActionListener(this);
   c.addActionListener(this);
   d.addActionListener(this);
   e.addActionListener(this);
   add(b);
   add(c);
   add(d);
   add(e);
   }

   public void actionPerformed(ActionEvent e){
   sum = i + j;
   txtArea.setText("");
   txtArea.append("i = "+ i + "\t" + "j = " + j + "\n");
   Button source = (Button)e.getSource();
   if(source.getLabel() == "Add"){
   txtArea.append("Sum : " + sum + "\n");
   }
  
   if(i >j){
   Sub = i - j;
   }
   else{
   Sub = j - i;
   }
   if(source.getLabel() == "Subtract"){
   txtArea.append("Sub : " + Sub + "\n");
   }
   Mul = i*j;
   if(source.getLabel() == "Multiply"){
   txtArea.append("Mul = " + Mul + "\n");
   }
   if(i > j){
   Div = i / j;
   }
   else{
   Div = j / i;
   }
   if(source.getLabel() == "Divide"){
   txtArea.append("Divide = " + Div);
   }
   }
 }