Draw Polygons in java applet

Hello Friends, 

Today I will explain how can we draw Polygon in java applet.
In this  program I have print simple Polygon but you can draw different shapes with different size.

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

/*


*/

public class polydemo extends Applet
{
public void paint(Graphics g)
{
int xpt[]={60,30,30,30,120};
int ypt[]={90,40,180,180,30};

int num=5;
g.drawPolygon(xpt,ypt,num);
g.setColor(Color.green);
g.fillPolygon(xpt,ypt,num);
g.setColor(Color.blue);
}
}

Draw Arc in java applet

Hello Friends, 

Today I will explain how can we draw Arc in java applet.
In this  program I have print simple Arc but you can draw different shapes with different size.
    import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/*


*/

public class Arcdemo extends Applet
{
public void paint(Graphics g)
{
g.drawArc(150,60,100,100,0,90);
g.setColor(Color.blue);
g.fillArc(100,60,45,60,0,90);
}
}

Draw Oval in java applet

Hello Friends, 

Today I will explain how can we draw Oval in java applet.
In this  program I have print simple Oval but you can draw different shapes with different size.
   import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/*


*/

public class oval extends Applet
{
public void paint(Graphics g)
{
g.drawOval(10,10,50,50);
g.fillOval(200,30,60,100);
g.drawString("This is circle & oval.",40,90);
}
}

Draw Round corner Rectangle in java applet

Hello Friends, 

Today I will explain how can we draw Round Rectangle in java applet.
In this  program I have print simple Round Rectangle but you can draw different shapes with different size.


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

/*


*/

public class twelve extends Applet
{
public void paint(Graphics g)
{

g.drawRoundRect(190,80,60,50,30,30);

g.fillRoundRect(290,20,90,70,30,30);
}
}

Draw Rectangle in java Applet

Hello Friends, 

Today I will explain how can we draw Rectangle in java applet.
In this  program I have print simple Rectangle but you can draw different shapes with different size.
    import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/*


*/

public class twelve extends Applet
{
public void paint(Graphics g)
{
g.drawRect(20,200,60,50);

setForeground(Color.red);
g.fillRect(70,400,80,30);

}
}

How to draw Line in java applet?

Hello Friends, 

Today I will explain how can we draw Line in java applet.
In this  program I have print simple lines but you can draw different lines with different size.

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

/*


*/

public class twelve extends Applet
{
public void paint(Graphics g)
{
g.drawLine(10,100,10,100);
g.drawLine(20,20,20,100);
g.drawLine(30,30,30,100);
g.drawLine(40,40,40,100);
g.drawLine(50,50,50,100);


}
}

How to use Text box in java applet?

Hello Friends, 

Today I will explain how can we use Text box in java applet.
In this  program I have print simple user name & password text box…but you can create your own text box.

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

/*


*/

public class ten extends Applet implements ActionListener
{
TextField name,pass;
public void init()
{
Label namep=new Label("NAME:",Label.LEFT);
name=new TextField(15);
System.out.println("vivek");
Label passp=new Label("PASSWORD:",Label.RIGHT);
pass=new TextField(15);

pass.setEchoChar('*');

add(name);
add(pass);
add(namep);
add(passp);

name.addActionListener(this);
pass.addActionListener(this);
}

public void actionPerformed(ActionEvent ae)
{
repaint();
}

public void paint(Graphics g)
{
g.drawString("Name:"+name.getText(),6,60);
g.drawString("Selected Text Name:"+pass.getSelectedText(),6,80);
g.drawString("Password:"+pass.getText(),6,100);
}
}

How to Add Button in java applet?

Hello Friends, 

Today I will explain how can we use Button in java applet.
In this  program I have simply changed background color when button pushed.

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

/*


*/

public class nineA extends Applet
{
Button a=new Button("Click to change the color");

boolean flag=true;

public void init()
{
add(a);
}

public void paint(Graphics g)
{
if(flag)
setBackground(Color.blue);
else
setBackground(Color.red);
}

public boolean action(Event e,Object o)
{
if(e.target==a)
{
flag =! flag;
repaint();

return true;
}
return false;
}
}

How to use Button in java applet with the use of ActionListener?

Hello Friends, 

Today I will explain how can we use Button in java applet.
In this  program I used simple Button name but you can write or put different Buttons in your java applet program.
In this program i used ActionListener event hendling class.

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

/*


*/

public class nine extends Applet implements ActionListener
{
String msg="";
Button yes,no,maybe;
public void init()
{
yes=new Button("Yes");
no=new Button("No");
maybe=new Button("MayBe");

add(yes);
add(no);
add(maybe);

yes.addActionListener(this);
no.addActionListener(this);
maybe.addActionListener(this);
}

public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();

if(str.equals("Yes"))
msg="You press Yes....";
else if(str.equals("No"))
msg="You press No....";
else
msg="You press Maybe....";

repaint();
}

public void paint(Graphics g)
{
g.drawString(msg,6,100);
}
}