Posts

Showing posts from 2016

VOWELS

/* <applet code=vowels width=300 height=300> </applet> */ import java.applet.*; import java.awt.*; import java.awt.event.*; public class vowels extends Applet implements ActionListener { TextField disp; TextArea area; Button chk; public void init() { chk=new Button("  CHECK  "); area=new TextArea(10,20); disp=new TextField(15); add(area); add(disp); add(chk); chk.addActionListener(this); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==chk) { String s=new String(); s=area.getText(); int cnt=0; char ch; for(int i=0;i<s.length();i++) { ch=s.charAt(i); if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U') { cnt++; } } disp.setText(Integer.toString(cnt)); } } }

CREATE A LOGIN PAGE

//    Lable and Buttons using Applet /* <applet code=login width=280 height=300> </applet> */ import java.applet.*; import java.awt.*; public class login extends Applet { TextField user_txt,pwd_txt; Label user,pwd; Button submit,cancel; public void init() {   user=new Label(" User name ");   pwd=new Label(" Password "); user_txt=new TextField(15);   pwd_txt=new TextField(15); submit=new Button("  submit  "); cancel=new Button("  cancel  "); add(user); add(user_txt); add(pwd); add(pwd_txt); add(submit); add(cancel); } }

FACTORIAL

Image
/* <applet code=factorial width=300 height=300> </applet> */ import java.applet.*; import java.awt.*; import java.awt.event.*; public class factorial extends Applet implements ActionListener { TextField tf,res; Button chk; public void init() { chk=new Button("  CLICK  "); tf=new TextField(20); res=new TextField(20); add(tf); add(res); add(chk); chk.addActionListener(this); } public void actionPerformed(ActionEvent ae) { int fact=1; if(ae.getSource()==chk) { int no=Integer.parseInt(tf.getText()); for(int i=1;i<=no;i++) { fact=fact*i; } res.setText(Integer.toString(fact)); } }//action per }//class OUTPUT:

CHANGING BACKGROUND COLOR

Image
/* <applet code=color_change width=300 height=300> </applet> */ import java.applet.*; import java.awt.*; import java.awt.event.*; public class color_change extends Applet implements ActionListener { Button R,G,B; public void init() { R=new Button("  RED  "); G=new Button("  GREEN  "); B=new Button("  BLUE  "); add(R); add(G); add(B); R.addActionListener(this); G.addActionListener(this); B.addActionListener(this); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==R) setBackground(Color.red); if(ae.getSource()==G) setBackground(Color.green); if(ae.getSource()==B) setBackground(Color.blue); /* if(ae.getActionCommand()=="  RED  ")     setBackground(Color.red); if(ae.getActionCommand()==G.getLabel()) setBackground(Color.green); */ } } OUTPUT:

BASIC CALCULATOR

 calculation using buttons  /*  <applet code=calculate width=300 height=300> </applet> */ import java.applet.*; import java.awt.*; import java.awt.event.*; public class calculate extends Applet implements ActionListener { TextField t1,t2,t3; Button Add,sub,mul,div; public void init() { setBackground(Color.gray); t1=new TextField(15); t2=new TextField(15); t3=new TextField(15); Add=new Button("  ADD  "); sub=new Button("  SUB  "); mul=new Button("  MUL  "); div=new Button("  DIV  "); add(t1); add(t2); add(Add); add(sub); add(mul); add(div); add(t3); Add.addActionListener(this); sub.addActionListener(this); mul.addActionListener(this); div.addActionListener(this); } public void actionPerformed(ActionEvent ae) { int a,b,c=0; a=Integer.parseInt(t1.getText()); b=Integer.parseInt(t2.getText()); if(ae.getSource()==Add) { c=a+b; //t3.setText(Integer.toString(c)); } if(ae.getSource()...

HOW TO CREATE A BUTTON

This is the simplest program to understand how to apply button to the applet. Save the program by button_click.java  To compile the program in ubuntu type: javac button_click.java To run the program type java button_click import java.applet.*; import java.awt.event.*; import java.awt.*; public class button_click extends Applet implements ActionListener { int state; Checkbox xp,linux,obj; Button ok; TextField disp; public void init() {  xp=new Checkbox("  Windows XP");  linux=new Checkbox(" Linux"); ok=new Button("   OK   "); disp=new TextField(25); add(xp); add(linux); add(ok); add(disp); ok.addActionListener(this); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==ok)  { if(xp.getState()==true)   disp.setText(xp.getLabel()); else   if(linux.getState()==true)   disp.setText(linux.getLabel()); } } } /*<applet code=button_click.class width=225 height=200> </applet> ...

HOW TO APPLY BORDER LAYOUT.

This is the basic program to start with. Save the programs by the class name only,then only it will work out. import java.applet.*; import java.awt.*; import java.awt.event.*; /*<applet code=border_layout width=500 height=500></applet>*/ public class border_layout extends Applet { BorderLayout bl; Button b; Label p,q,r,s; public void init() { b=new Button("CLICK HERE "); p=new Label("EAST"); q=new Label("WEST"); r=new Label("NORTH"); s=new Label("SOUTH"); bl=new BorderLayout(); setLayout(bl); add(p,BorderLayout.EAST); add(q,BorderLayout.WEST); add(r,BorderLayout.NORTH); add(s,BorderLayout.SOUTH); add(b,BorderLayout.CENTER); } }