Monday, 4 July 2016

Write a Java program to create an Applet to generate table of 10

import java.applet.Applet;
import java.awt.*;
public class tableof10 extends Applet {
      int count,i;
 
   public void init(){
      this.count=10;
    }

    public void paint(Graphics g) {
        for(i=1;i<=10;i++)
        {
            g.drawString(i+ "* 10 =" +i*10,150,count);
            count=count+20;
        }
   
    }

}

Applet code:

<html>
     <head>
          <title>table of 10</title>
     </head>
     <body>
          <applet code="tableof10.class" height="500" width="500"></applet>
     </body>
</html>

OUTPUT:

Sunday, 3 July 2016

Write a program using JAVA to create an Applet that takes radius of a circle as input and draws the circle in Blue color

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class NewApplet extends Applet implements ActionListener{

    TextField t1;
    Button b1;
    Label l1;
    int r=0;

    public void init() {
        l1 = new Label("Enter radius of circle:");
        t1 = new TextField(5);
        b1 = new Button("Draw Circle");
        add(l1);
        add(t1);
        add(b1);
    b1.addActionListener(this);
    }

   public void paint(Graphics g)
{
    g.drawOval(50, 50, r*2, r*2);
    g.setColor(Color.blue);
    g.fillOval(50, 50, r*2, r*2);
}

public void actionPerformed(ActionEvent e)
{
r= Integer.parseInt(t1.getText());
repaint();
}
}

Applet code:

<html>
     <head>
          <title>circle in Blue color</title>
     </head>
     <body>
          <applet code="NewApplet.class" width="800" height="800"></applet>
     </body>
</html>

OUTPUT:

Print Friendly and PDF

Write a Java program to create two threads T1 and T2. Thread T1 is having priority six and thread T2 is having default priority assigned to it. Implement threads T1 and T2 in such a way that T1 prints table of 2 and T2 prints table of 5

class T1 extends Thread{

public void run(){
        int i;
        for(i=1;i<=10;i++)
        System.out.println(i+"*"+"2"+"="+i*2);
}
}

class T2 extends Thread{

public void run(){
        int i;
        for(i=1;i<=10;i++)
        System.out.println(i+"*"+"5"+"="+i*5);
}
}


public class T3 {
 
    public static void main(String[] args){
 
    T1 t1=new T1();
    T2 t2=new T2();
    t1.setPriority(6);
    t1.start();
    t2.start();
    }
 
}

OUTPUT:

1*2=2
2*2=4
3*2=6
4*2=8
5*2=10
6*2=12
7*2=14
8*2=16
9*2=18
10*2=20
1*5=5
2*5=10
3*5=15
4*5=20
5*5=25
6*5=30
7*5=35
8*5=40
9*5=45
10*5=50

Popular Posts