|
|
Java Examples
OOPS |
Exception |
RMI |
String |
Thread |
io |
Util |
Net |
AWT |
JDBC |
|
|
| AWT PROGRAM: |
| 1.KeyEvent Program |
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="keyevnt" width=500 height=400>
</applet>
*/
public class keyevnt extends Applet implements KeyListener,MouseMotionListener,MouseListener {
String str="";
int cd;
static int n=4;
public void init() {
addKeyListener(this);
addMouseListener(this);
addMouseMotionListener(this);
setBackground(Color.cyan);
setForeground(Color.red);
}
public void paint(Graphics g) {
g.drawString(str,10,10);
}
public void keyPressed(KeyEvent ke) {
showStatus("Key Down ");
}
public void keyReleased(KeyEvent ke) {
showStatus("Key Up ");
}
public void keyTyped(KeyEvent ke) {
str += ke.getKeyChar();
repaint();
cd = ke.getKeyCode();
repaint();
}
public void mouseDragged(MouseEvent me) {
showStatus("Mouse Dragged ");
}
public void mouseMoved(MouseEvent me) {
showStatus("Mouse Moved ");
}
public void mouseClicked(MouseEvent me) {
int ch = me.getClickCount();
showStatus("Mouse Clicked "+ch);
}
public void mousePressed(MouseEvent me) {
showStatus("Mouse Pressed ");
}
public void mouseReleased(MouseEvent me) {
showStatus("Mouse Released ");
}
public void mouseEntered(MouseEvent me) {
showStatus("Mouse Entered ");
}
public void mouseExited(MouseEvent me) {
showStatus("Mouse Exited ");
}
}
|
| 2.Applet Registration Program |
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="reg" width=500 height=500>
</applet>
*/
public class reg extends Applet implements ActionListener {
String msg;
Label lempid,lname,lqual,lskill,ldesg,ldoj,ldor,lcsal,lphno,laddr;
TextField empid,name,qual,skill,desg,doj,dor,csal,phno;
TextArea addr;
Button add,rest,exit;
public void init() {
setBackground(Color.lightGray);
lempid = new Label("EmpId");
empid = new TextField(8);
lname = new Label("Name");
name = new TextField(16);
lqual = new Label("Qualification");
qual = new TextField(15);
lskill= new Label("Specialization");
skill = new TextField(25);
ldesg = new Label("Designation");
desg = new TextField(15);
ldoj = new Label("Date of Joining");
doj = new TextField(10);
ldor = new Label("Dtae of Releaving");
dor = new TextField(10);
lcsal = new Label("Current Sal");
csal = new TextField(10);
lphno = new Label("Phone No");
phno = new TextField(12);
laddr = new Label("Address");
addr = new TextArea(4,15);
add = new Button("Add");
rest = new Button("Reset");
exit = new Button("Exit");
setLayout(null);
add(lempid);
lempid.setBounds(0,10,40,25) ;
add(empid);
empid.setBounds(125,10,60,20) ;
add(lname);
lname.setBounds(0,40,60,25) ;
add(name);
name.setBounds(125,40,140,20) ;
add(lqual);
lqual.setBounds(0,70,85,25) ;
add(qual);
qual.setBounds(125,70,150,20) ;
add(lskill);
lskill.setBounds(0,100,100,25) ;
add(skill);
skill.setBounds(125,100,120,20) ;
add(ldesg);
ldesg.setBounds(0,130,70,25) ;
add(desg);
desg.setBounds(125,130,150,20) ;
add(ldoj);
ldoj.setBounds(0,160,100,25) ;
add(doj);
doj.setBounds(125,160,85,20) ;
add(ldor);
ldor.setBounds(0,190,100,25) ;
add(dor);
dor.setBounds(125,190,85,20) ;
add(lcsal);
lcsal.setBounds(0,220,100,30) ;
add(csal);
csal.setBounds(125,220,100,20) ;
add(lphno);
lphno.setBounds(0,250,80,25) ;
add(phno);
phno.setBounds(125,250,90,20) ;
add(laddr);
laddr.setBounds(0,280,80,25) ;
add(addr);
addr.setBounds(125,280,170,80) ;
add(add);
add.setBounds(200,400,45,20) ;
add(rest);
rest.setBounds(290,400,60,20) ;
add(exit);
exit.setBounds(370,400,50,20) ;
.addActionListener(this);
name.addActionListener(this);
qual.addActionListener(this);
skill.addActionListener(this);
desg.addActionListener(this);
doj.addActionListener(this);
dor.addActionListener(this);
csal.addActionListener(this);
phno.addActionListener(this);
add.addActionListener(this);
rest.addActionListener(this);
exit.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
String str= ae.getActionCommand();
if(str == "Add") {
msg = " Employee details added to the DataBase :";
repaint();
}
if(str == "Reset") {
empid.setText(" ");
name.setText(" ");
qual.setText(" ");
skill.setText(" ");
desg.setText(" ");
doj.setText(" ");
dor.setText(" ");
csal.setText(" ");
phno.setText(" ");
addr.setText(" ");
msg = " : ";
repaint();
}
if(str == "Exit") {
stop();
}
}
public void paint(Graphics g) {
showStatus(msg);
}
}
|
| 3.Applet Banner Program |
import java.awt.*;
import java.applet.*;
/*
<applet code="ban" width=500 height=300>
</applet>
*/
public class ban extends Applet implements Runnable {
String str="<< Hai , Have a Nice Day >>";
Thread thd;
int state;
boolean stop;
public void init() {
setBackground(Color.cyan);
setForeground(Color.red);
}
public void start() {
thd = new Thread(this);
stop=false;
thd.start();
}
public void run() {
char ch;
for(;;) {
try {
repaint();
Thread.sleep(500);
ch=str.charAt(0);
str= str.substring(1);
str+=ch;
if(stop) break;
}catch(InterruptedException ex) {}
}
}
public void stop()
{ stop= true; thd = null;}
public void paint(Graphics g) {
g.drawString(str,70,10);
}
}
|
| 4.Frame Program |
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="FrameDemo" width=500 height=500>
</applet>
*/
class Mywindowadapter extends WindowAdapter {
public void WindowClosing(WindowEvent we) {
System.exit(0);
}
}
public class FrameDemo extends Frame implements ActionListener {
FrameDemo(String tittle) {
super(tittle);
Mywindowadapter adpt= new Mywindowadapter();
addWindowListener(adpt);
String msg ="hai this is not applet window :";
Label lempid,lname,lqual,lskill,ldesg,ldoj,ldor,lcsal,lphno,laddr;
TextField empid,name,qual,skill,desg,doj,dor,csal,phno;
TextArea addr;
Button add,rest;
setBackground(Color.lightGray);
lempid = new Label("EmpId");
empid = new TextField(8);
lname = new Label("Name");
name = new TextField(16);
lqual = new Label("Qualification");
qual = new TextField(15);
lskill= new Label("Specialization");
skill = new TextField(25);
ldesg = new Label("Designation");
desg = new TextField(15);
ldoj = new Label("Date of Joining");
doj = new TextField(10);
ldor = new Label("Dtae of Releaving");
dor = new TextField(10);
lcsal = new Label("Current Sal");
csal = new TextField(10);
lphno = new Label("Phone No");
phno = new TextField(12);
laddr = new Label("Address");
addr = new TextArea(4,15);
add = new Button("Add");
rest = new Button("Reset");
setLayout(null);
add(lempid);
lempid.setBounds(30,50,40,25) ;
add(empid);
empid.setBounds(125,50,60,20) ;
add(lname);
lname.setBounds(30,80,60,25) ;
add(name);
name.setBounds(125,80,140,20) ;
add(lqual);
lqual.setBounds(30,110,85,25) ;
add(qual);
qual.setBounds(125,110,150,20) ;
add(lskill);
lskill.setBounds(30,140,100,25) ;
add(skill);
skill.setBounds(125,140,120,20) ;
add(ldesg);
ldesg.setBounds(30,170,70,25) ;
add(desg);
desg.setBounds(125,170,150,20) ;
add(ldoj);
ldoj.setBounds(30,200,100,25) ;
add(doj);
doj.setBounds(125,200,85,20) ;
add(ldor);
ldor.setBounds(30,230,100,25) ;
add(dor);
dor.setBounds(125,230,85,20) ;
add(lcsal);
lcsal.setBounds(30,260,100,30) ;
add(csal);
csal.setBounds(125,260,100,20) ;
add(lphno);
lphno.setBounds(30,290,80,25) ;
add(phno);
phno.setBounds(125,290,90,20) ;
add(laddr);
laddr.setBounds(30,320,80,25) ;
add(addr);
addr.setBounds(125,320,170,80) ;
add(add);
add.setBounds(200,400,45,20) ;
add(rest);
rest.setBounds(290,400,60,20) ;
add.addActionListener(this);
rest.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
}
public static void main(String args[]) {
FrameDemo frame= new FrameDemo(" My Frame ");
frame.setSize(600,650);
frame.setVisible(true);
}
}
|
|
Back to Top |
|