Manu

Saturday, November 19, 2016

Write a program using different AWT(Abstract Window Toolkit) Contoll.

Input :

\package javaapplication2;
import java.awt.*;
import java.applet.*;
public class MyControl_1 extends Applet
{
    @Override
    public void init()
    {
      setLayout(null);
      Button b1= new Button("Ok");
      b1.setBounds(10,20,50,20);
      Button b2= new Button("Cancel");
      b2.setBounds(70,20,50,20);
      Button b3= new Button("Reset");
      b3.setBounds(130,20,50,20);
      add(b1);
      add(b2);
      add(b3);
      TextField t1=new TextField(15);
      t1.setBounds(40,60,50,20);
      add(t1);
      Checkbox c1=new Checkbox("Hindi");
       c1.setBounds(10,90,50,20);
      Checkbox c2=new Checkbox("Gujrati");
       c2.setBounds(70,90,50,20);
      Checkbox c3=new Checkbox("English");
       c3.setBounds(130,90,50,20);
      add(c1);
      add(c2);
      add(c3);
      CheckboxGroup cbg=new CheckboxGroup();
       Checkbox cg1=new Checkbox("Male",cbg,true);
        cg1.setBounds(10,120,50,20);
       Checkbox cg2=new Checkbox("Female",cbg,false);
        cg2.setBounds(60,120,50,20);
       add(cg1);
       add(cg2);
    }
}

Output : 
 

Write a program to working with Graphics Class.

Input :

package javaapplication2;
import java.applet.Applet;
import java.awt.Graphics;
public class StringApplet extends Applet {
      public void paint(Graphics g)
       {
  g.drawString("hello friends", 50, 50);
         g.drawLine(35, 50, 75, 95);
         g.drawRect(100, 100, 100, 100);
         g.drawRoundRect(210,100,  100,100, 10, 10);
         g.drawOval(340,100,100, 100);
         g.drawArc(450, 100, 75, 95, 0, 180);
  int []x = {60,35,50,65,80,95};
  int []y = {60,105,105,110,95,95};
 g.drawPolygon(x, y, 6);             
    }
}

Output :


Write a java program to input two values and perform arithmetic operation using button

importjava.applet.Applet;
importjava.awt.Button;
importjava.awt.TextField;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
public class OperatorApplet extends Applet implements ActionListener
{
TextField t1,t2,t3;
    Button b1,b2,b3,b4;
public void init()
    {
setLayout(null);
    t1 = new TextField(15);
t1.setBounds(100,100,50,20);
    t2 = new TextField(15);
t2.setBounds(100,125,50,20);
    t3 = new TextField(15);
t3.setBounds(100,150,50,20);
    b1 = new Button("ADD");
b1.setBounds(50,180,40,20);
    b2 = new Button("DIV");
b2.setBounds(100,180,40,20);

    b3 = new Button("MUL");
b3.setBounds(150,180,40,20);
    b4 = new Button("Sub");
b4.setBounds(200,180,40,20);
add(t1);
add(t2);
add(t3);          
add(b1);
add(b2);
add(b3);
add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
    }
public void actionPerformed(ActionEvent e)
    {
inti,j;
        i=Integer.parseInt(t1.getText());
        j=Integer.parseInt(t2.getText());
if(e.getSource()==b1)
t3.setText(""+(i+j));
else if(e.getSource()==b2)
t3.setText(""+(i/j));
else if(e.getSource()==b3)
t3.setText(""+(i*j));
else
t3.setText(""+(i-j));
    }
}

Output :

Develop an applet for input three numeric values and display the largest value

importjava.applet.*;
importjava.awt.*;
importjava.awt.event.*;
public class largenumber extends Applet implements ActionListener
{
TextField t1,t2,t3,t4;
    Button b1;
public void init()
    {
setLayout(null);
    t1 = new TextField(15);
t1.setBounds(100,25,50,20);
    t2 = new TextField(15);
t2.setBounds(100,50,50,20);
    t3 = new TextField(15);
t3.setBounds(100,75,50,20);
    t4 = new TextField("Ans");
t4.setBounds(175,40,50,20);
    b1 = new Button("Find");
b1.setBounds(175,65,50,30);
add(t1);
add(t2);
add(t3);
add(t4);
add(b1);
b1.addActionListener(this);
    }
public void actionPerformed(ActionEvent e)
    {
inti,j,k;
         i = Integer.parseInt(t1.getText());
         j=Integer.parseInt(t2.getText());
         k=Integer.parseInt(t3.getText());
if(i<j)
         {
if(j<k)
t4.setText(""+k);
else
t4.setText(""+j);
         }
else
t4.setText(""+i);
   }
}



Output :


Develop and applet that receive one string and display in reverse fashion

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class revst extends Applet implements MouseMotionListener
{
            TextField t,t1;
            public void init()
            {
                        t=new TextField(25);
                        add(t);
                        t1=new TextField(25);
                        add(t1);
                        t1.addMouseMotionListener(this);
            }
            public void mouseMoved(MouseEvent m) {
                        StringBuffer st=new StringBuffer(t.getText());
                        st.reverse();
                        t1.setText(""+st);
            }
            public void mouseDragged(MouseEvent m){}
}

Output :


Write a simple program for mouselistener

import java.applet.*;
import java.awt.*;
import java.awt.event.*;       
public class Mous extends Applet implements MouseListener
{
public void init()
{
addMouseListener(this);        
}
public void mouseClicked(MouseEvent e)
{
            setBackground(Color.green);
           
}
public void mouseEntered(MouseEvent e)
{
            setBackground(Color.blue);
}
public void mouseExited(MouseEvent e)
{
            setBackground(Color.yellow);
}
public void mouseReleased(MouseEvent e)
{
            setBackground(Color.pink);
}

}

Output :


Write a simple program for Menu and Menu bar.

importjava.applet.Applet;
importjava.awt.Color;
importjava.awt.Frame;
importjava.awt.Menu;
importjava.awt.MenuBar;
importjava.awt.MenuItem;
public class Menuapplet extends Applet
 {
MenuBar mbar;
    Frame frm;
public void init()
    {
frm = new Frame();
frm.setSize(300,400);
frm.setBackground(Color.LIGHT_GRAY);
frm.setVisible(true);
mbar = new MenuBar();
        Menu m = new Menu("File");
m.add(new MenuItem("New"));
m.add(new MenuItem("Open"));
m.add(new MenuItem("Save"));
m.add(new MenuItem("Save as"));
m.add(new MenuItem("Print"));
m.addSeparator();
m.add(new MenuItem("Quit"));
mbar.add(m);
        m = new Menu("Help");
mbar.add(m);
m.add(new MenuItem("Help!!!!"));
m.addSeparator();
m.add(new MenuItem("About!!!!"));
mbar.add(m);       
frm.setMenuBar(mbar);
      }
}

Output :