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);
}
}

How to use Label in java applet?

Hello Friends, 

Today I will explain how can we use Label in java applet.
In this  program I used simple label name but you can write or put different labels in your java applet program.

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

/*


*/

public class sixth extends Applet
{
String msg="";
public void init()
{
Label one=new Label("one");
Label two=new Label("two");
Label three=new Label();

three.setText("three");

add(one);
add(two);
add(three);

msg=one.getText();
}
public void paint(Graphics g)
{
setBackground(Color.black);
setForeground(Color.white);

g.setFont(new Font("Corbel",Font.BOLD,30));
g.drawString(msg,20,80);
}
}

How to use keyPressed & keyReleased Method of KeyListener in java applet?

Hello Friends, 

Today I will explain how can we write the keylistener program in java applet.
In this  program I used keyPressed & keyReleased methods of KeyListener.

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

/*


*/

public class fifth extends Applet implements KeyListener
{
String msg="";
public void init()
{
addKeyListener(this);
}
public void keyPressed(KeyEvent ke)
{
showStatus("Key Down");
}
public void keyReleased(KeyEvent ke)
{
showStatus("Key Up");
}
public void keyTyped(KeyEvent ke)
{
msg +=ke.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
setBackground(Color.black);
setForeground(Color.blue);

g.setFont(new Font("Lucida Sans Typewriter",Font.BOLD,25));
g.drawString(msg,20,50);
}
}

How to change Font size,style & type in java applet?

Hello Friends, 

Today I will explain how can we change font size,style,type in java applet.
In this  program I have change font size,style,type.

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

/*


*/

public class fourth extends Applet
{
String msg="";
public void init()
{
msg="hay....";
setBackground(Color.pink);
setForeground(Color.black);

msg +="whts up???";
}
public void paint(Graphics g)
{
g.setFont(new Font("Comic Sans MS",Font.BOLD,30));
g.drawString(msg,50,70);
}
}

How to print color text in java applet?

Hello Friends, 


Today I will explain how can we print color text in java applet.
In this  program I have used different methods to print text in java applet.
for example in Strings, with veriables etc.


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


*/

public class third extends Applet
{
String msg="";

public void init()
{
setBackground(Color.blue);
setForeground(Color.red);

msg="hi...";
System.out.print("nt"+msg);
}
public void start()
{
msg=msg+"whts up????";
}
public void paint(Graphics g)
{
msg=msg+"i hope u r enjoying an applet...";
g.drawString(msg,25,25);
}
}

how to write Java Applet lifecycle program (init,start,stop,distroy).

Hello Friends, 


Today I will explain how can we write Java Applet lifecycle program.
In this  program I have print init,start,stop & distroy method.


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


*/

public class second extends Applet
{
String str1="";

public void init()
{
str1 +="init::";
System.out.println("nt "+str1);
}
public void start()
{
str1 +="start::";
System.out.println("nt "+str1);
}
public void stop()
{
str1 +="stop::";
System.out.println("nt "+str1);
}
public void destroy()
{
str1 +="destroy.";
System.out.println("nt "+str1);
}

public void paint(Graphics g)
{
g.drawString(str1,10,25);
}
}

How to print Text in Java Applet?

Hello Friends, 


Today I will explain how can we print “HELLO” or Any text in Java Applet.
In this  program I have print only “HELLO” but you can choose any text you like.

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


*/

public class first extends Applet
{
public void paint(Graphics g)
{
g.drawString("first applet..........",100,200);
}
}