Showing posts with label Frame java pogram. Show all posts
Showing posts with label Frame java pogram. Show all posts

Java Frame to build a Student Registration Form


/* student registration form using  frame  and  interface 
  actionlistener , itemlistener*/ 

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

class studentform extends Frame implements ActionListener,ItemListener
{
 
 Panel p,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,a;
 Label l,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15,l16,l17,l18,a1,a2;
 TextField tf1,tf2,tf3,tf5,tf6,tf7,tf8,tf9,tf10,tf11,tf12,tf13,tf14,tf15,tf16,tf17,tf18;
 Checkbox c1,c2,c3,c4,male,female,BE,ME,BCA,MCA;
 CheckboxGroup cbg,cbg1;
 List lst;
 Choice ch1,ch2,ch3;
 TextArea ta,ta1;
 Button b1,b2,b3;
 Font f1;
 String st1,st2,st3,st4,st5,st6,st7,st8,st9,sd1,sd2,sd3,sc1,sc2,sc3,sc4,sb,sb1,sl;

 studentform()
 {
  setTitle("Student Registration Form..");
  setSize(500,500);
  setVisible(true);
 
  GridLayout gr=new GridLayout(19,1);
  setLayout(gr);
 
  f1=new Font("courier New",Font.BOLD,25);
 
  p=new Panel();
  l=new Label("Student Registration Form");
  p.setFont(f1);
  p.add(l);
  add(p);
 
  p1=new Panel();
  l1=new Label("First name    ");
  tf1=new TextField(10);
  p1.setLayout(new FlowLayout(FlowLayout.LEFT));
 
  p1.add(l1);
  p1.add(tf1);
  add(p1);
 
  p2=new Panel();
  l2=new Label("Middle name");
  tf2=new TextField(10);
  p2.setLayout(new FlowLayout(FlowLayout.LEFT));
  p2.add(l2);
  p2.add(tf2);
  add(p2);
 
  p3=new Panel();
  l3=new Label("Last name    ");
  tf3=new TextField(10);
  p3.setLayout(new FlowLayout(FlowLayout.LEFT));
  p3.add(l3);
  p3.add(tf3);
  add(p3);
 
  p4=new Panel();
  l4=new Label("Date of Birth");
  ch1=new Choice();
  ch2=new Choice();
  ch3=new Choice();
 
  ch1.add("Day");
  ch1.add("1");
  ch1.add("2");
  ch1.add("3");
  ch1.add("4");
  ch1.add("5");
  ch1.add("6");
  ch1.add("7");
  ch1.add("8");
  ch1.add("9");
  ch1.add("10");
  ch1.add("11");
  ch1.add("12");
  ch1.add("13");
  ch1.add("14");
  ch1.add("15");
  ch1.add("16");
  ch1.add("17");
  ch1.add("18");
  ch1.add("19");
  ch1.add("20");
  ch1.add("21");
  ch1.add("22");
  ch1.add("23");
  ch1.add("24");
  ch1.add("25");
  ch1.add("26");
  ch1.add("27");
  ch1.add("28");
  ch1.add("29");
  ch1.add("30");
  ch1.add("31");
 
  ch2.add("Month");
  ch2.add("1");
  ch2.add("2");
  ch2.add("3");
  ch2.add("4");
  ch2.add("5");
  ch2.add("6");
  ch2.add("7");
  ch2.add("8");
  ch2.add("9");
  ch2.add("10");
  ch2.add("11");
  ch2.add("12");
 
  ch3.add("Year");
  ch3.add("1990");
  ch3.add("1991");
  ch3.add("1992");
  ch3.add("1993");
  ch3.add("1994");
  ch3.add("1995");
  ch3.add("1996");
  ch3.add("1997");
  ch3.add("1998");
  ch3.add("1999");
  ch3.add("2000");
  ch3.add("2001");
  p4.setLayout(new FlowLayout(FlowLayout.LEFT));
  p4.add(l4);
  p4.add(ch1);
  p4.add(ch2);
  p4.add(ch3);
   add(p4);
 
  p5=new Panel();
  l5=new Label("Email Id       ");
  tf5=new TextField(10);
  p5.setLayout(new FlowLayout(FlowLayout.LEFT));
  p5.add(l5);
  p5.add(tf5);
  add(p5);
 
  p6=new Panel();
  l6=new Label("Mobile no     ");
  tf6=new TextField(10);
  p6.setLayout(new FlowLayout(FlowLayout.LEFT));
  p6.add(l6);
  p6.add(tf6);
  add(p6);
 
  p7=new Panel();
  cbg=new CheckboxGroup();
  male=new Checkbox("Male",cbg,true);
  female=new Checkbox("Feale",cbg,false);
  p7.setLayout(new FlowLayout(FlowLayout.LEFT));
  p7.add(male);
  p7.add(female);
  add(p7);
 
   
  p8=new Panel();
 
  lst=new List(5);
  lst.add("ghatlodiya");
  lst.add("ranip");
  lst.add("bopal");
  l8=new Label("Address");
  p8.setLayout(new FlowLayout(FlowLayout.LEFT));
  p8.add(l8);
  p8.add(lst);
  add(p8);
 
  p9=new Panel();
  l9=new Label("City                ");
  tf9=new TextField(10);
  p9.setLayout(new FlowLayout(FlowLayout.LEFT));
  p9.add(l9);
  p9.add(tf9);
  add(p9);
 
  p10=new Panel();
  l10=new Label("Pin Code      ");  
  tf10=new TextField(10);
  p10.setLayout(new FlowLayout(FlowLayout.LEFT));
  p10.add(l10);
  p10.add(tf10);
  add(p10);
 
  p11=new Panel();
  l11=new Label("State             ");
  tf11=new TextField(10);
  p11.setLayout(new FlowLayout(FlowLayout.LEFT));
  p11.add(l11);
  p11.add(tf11);
  add(p11);
 
  p12=new Panel();
  l12=new Label("Country         ");
  tf12=new TextField(10);
  p12.setLayout(new FlowLayout(FlowLayout.LEFT));
  p12.add(l12);
  p12.add(tf12);
  add(p12);
 
  p13=new Panel();
  l13=new Label("Hobbies    ");
  c1=new Checkbox("reading");
  c2=new Checkbox("blogging");
  c3=new Checkbox("photography");
  c4=new Checkbox("other");
  p13.setLayout(new FlowLayout(FlowLayout.LEFT));
  p13.add(l13);
  p13.add(c1);
  p13.add(c2);
  p13.add(c3);
  p13.add(c4);
  add(p13);
 
  p14=new Panel();
  l14=new Label("Courses   ");
  p14.setLayout(new FlowLayout(FlowLayout.LEFT));
  p14.add(l14);
  add(p14);
 
   p15=new Panel();
  l15=new Label("Applies For  ");
  p15.setLayout(new FlowLayout(FlowLayout.LEFT));
  p15.add(l15);
  add(p15);
 
  p16=new Panel();
  cbg1=new CheckboxGroup();
  BE=new Checkbox(" BE",cbg,true);
  ME=new Checkbox(" ME",cbg,false);
  BCA=new Checkbox(" BCA",cbg,false);
  MCA=new Checkbox(" MCA",cbg,false);
  p16.setLayout(new FlowLayout(FlowLayout.LEFT));
  p16.add(BE);
  p16.add(ME);
  p16.add(BCA);
  p16.add(MCA);
  add(p16);
 
  p17=new Panel();
  b1=new Button("Submit");
  b2=new Button("Reset");
  b3=new Button("Close");
  p17.add(b1);
  p17.add(b2);
  p17.add(b3);
  add(p17);
 
  a=new Panel();
  a.setLayout(new FlowLayout(FlowLayout.CENTER));
  a2=new Label("Form");
  ta1=new TextArea(2,30);
  a.add(a2);
  a.add(ta1);
  add(a);

 
  b1.addActionListener(this);
  b2.addActionListener(this);
  b3.addActionListener(this);
 
  ch1.addItemListener(this);
  ch2.addItemListener(this);
  ch3.addItemListener(this);
 
  male.addItemListener(this);
  female.addItemListener(this);
  BE.addItemListener(this);
  ME.addItemListener(this);
  BCA.addItemListener(this);
  MCA.addItemListener(this);
 
  c1.addItemListener(this);
  c2.addItemListener(this);
  c3.addItemListener(this);
  c4.addItemListener(this);
  lst.addItemListener(this);
 
  addWindowListener(new studentform.MyWindowAdapter());
 
 
 }
  public void itemStateChanged(ItemEvent ie)
  {
   sd1=ch1.getSelectedItem();
   sd2=ch2.getSelectedItem();
   sd3=ch3.getSelectedItem();
   sl=lst.getSelectedItem();
   if(ie.getSource()==male)
   {
    sb="male";
   }
   else
   {
    sb="female";  
   }
 
   if(ie.getSource()==BE)
   {
    sb1="BE";
   }
   else if(ie.getSource()==ME)
   {
    sb1="ME";  
   }  
   else if(ie.getSource()==BCA)
   {
    sb1="BCA";  
   }
   else if(ie.getSource()==MCA)
   {
    sb1="MCA";  
   }
 
 
   if(ie.getSource()==c1)
   {
    sc1="reading";
   }
   if(ie.getSource()==c2)
   {
    sc2="blogging";  
   }
   if(ie.getSource()==c3)
   {
    sc3="photography";  
   }
   if(ie.getSource()==c4)
   {
    sc4="other";  
   }
  }
 
 
  public void actionPerformed(ActionEvent ae)
  {
     
      st1=tf1.getText();
      st2=tf2.getText();
      st3=tf3.getText();
      st4=tf5.getText();
      st5=tf6.getText();
      st6=tf9.getText();
      st7=tf10.getText();
      st8=tf11.getText();
      st9=tf12.getText();
   
 
     
   if(ae.getSource()==b1)
   {
     ta1.setText(
                 "\nFull Name: "+st1 +" "+st2 +" "+st3
                +"\ndob:"+sd1 +"/"+sd2 +"/"+sd3          
                +"\nEmail: "+st4
                +"\nMobile no: "+st5
                +"\ngenger:"+sb
                +"\narea:"+sl
                +"\nCity: "+st6
                +"\nPin Code: "+st7
                +"\nState: "+st8
                +"\nCountry: "+st9
                +"\nHobbies:"+sc1 +","+sc2 +","+sc3 +","+sc4
                +"\nCourse:"+sb1
            );
   }
   if(ae.getSource()==b2)
   {
    tf1.setText("");
    tf2.setText("");
    tf3.setText("");
    tf5.setText("");
    tf6.setText("");
    tf9.setText("");
    tf10.setText("");
    tf11.setText("");
    tf12.setText("");
   

   
   
 
   }  
 
   if(ae.getSource()==b3)
    {
        System.exit(0);
    }
 
  }
 
 

  public static void main(String[] args)
  {
   new studentform();
  }
 
  class MyWindowAdapter extends WindowAdapter
  {
   public void windowClosing(WindowEvent we)
   {
    System.exit(0);
   }
  }

}

Listener_Demo (how to handle mouse clicks on taxtarea using an item listener)


//how to handle mouse clicks on taxtarea using an item listener

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

class Listenerdemo extends Frame implements MouseListener,MouseMotionListener,KeyListener
{
    String msg;
    TextArea ta;
   
    Listenerdemo()
    {
        setTitle("Listener Demo");
        setSize(300,400);
        setVisible(true);
       
        FlowLayout fl=new FlowLayout(FlowLayout.CENTER);
        setLayout(fl);
        ta=new TextArea(5,50);      
        add(ta);
       
        addMouseListener(this);
        addMouseMotionListener(this);      
        addKeyListener(this);
        ta.addKeyListener(this);
       
        addWindowListener(new Listenerdemo.MyWindowAdapter());
       
    }
    public void mouseClicked(MouseEvent me)
    {
        System.out.println("Mouse Clicked Here:");
        ta.setText("Mouse Clicked Here:");      
    }
    public void mouseEntered(MouseEvent me)
    {
        System.out.println("Mouse Entered Here:");
        ta.setText("Mouse Entered Here:");      
    }
    public void mouseReleased(MouseEvent me)
    {
        System.out.println("Mouse Released Here:");
        ta.setText("Mouse Released Here:");      
    }
    public void mousePressed(MouseEvent me)
    {
        System.out.println("Mouse Pressed Here:");
        ta.setText("Mouse Pressed Here:");      
    }
    public void mouseExited(MouseEvent me)
    {
        System.out.println("Mouse Exited Here:");
        ta.setText("Mouse Exited Here:");      
    }
    public void mouseDragged(MouseEvent me)
    {
        System.out.println("Mouse Dragged Here:");
        ta.setText("Mouse Dragged Here:");      
    }
    public void mouseMoved(MouseEvent me)
    {
        System.out.println("Mouse Moved Here:");
        ta.setText("Mouse Moved Here:");      
    }
 
    public void keyTyped(KeyEvent ke)
    {
        System.out.println("Key Typed Here:");
        ta.setText("Key Typed Here:");      
    }
    public void keyPressed(KeyEvent ke)
    {
        System.out.println("Key Pressed Here:");
        ta.setText("Key Pressed Here:");      
    }
    public void keyReleased(KeyEvent ke)
    {
        System.out.println("Key Released Here:");
        ta.setText("Key Released Here:");      
    }
    public static void main(String[] args)
    {
            Listenerdemo ld=new Listenerdemo();
    }  
   
    class MyWindowAdapter extends WindowAdapter
  {
   public void windowClosing(WindowEvent we)
   {
    System.exit(0);
   }
  }
}

How to Use CardLayout


/*Simple  card layout program
 in java frame*/

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

class Card extends Frame implements ActionListener
{
  Button b1,b2,b3,b4;
  Panel mainpanel,subpanel,p,pro,p1,p2,p3,cus,c1,c2,c3,back;
  Label l1,l2,l3,m1,m2,m3;
  TextField tf1,tf2,tf3,t1,t2,t3;
  CardLayout card;

  Card()
  {    
   card=new CardLayout();
   mainpanel=new Panel();
   mainpanel.setLayout(card);
   setTitle("CardLayout");
   setSize(500,500);
   setVisible(true);
 
     
   GridLayout g=new GridLayout(5,1);
   setLayout(g);
 
 
 
   pro=new Panel();
   pro.setLayout(new FlowLayout(FlowLayout.LEFT));
   l1=new Label("Product no.");
   tf1=new TextField(10);
   l2=new Label("Product name.");
   tf2=new TextField(10);
   l3=new Label("Product rate.");
   tf3=new TextField(10);
   b3=new Button("pback");
   pro.add(l1);
   pro.add(tf1);
   pro.add(l2);
   pro.add(tf2);
   pro.add(l3);
   pro.add(tf3);
   pro.add(b3);
   add(pro);
 
   cus=new Panel();
   cus.setLayout(new FlowLayout(FlowLayout.LEFT));
   m1=new Label("Customer no.");
   t1=new TextField(10);
   m2=new Label("Customer name.");
   t2=new TextField(10);
   m3=new Label("Customer address.");
   t3=new TextField(10);
   b4=new Button("cback");
   cus.add(m1);
   cus.add(t1);
   cus.add(m2);
   cus.add(t2);
   cus.add(m3);
   cus.add(t3);
   cus.add(b4);
   add(cus);

 
   p=new Panel();
   b1=new Button("Product");
   b2=new Button("Client");
   p.add(b1);
   p.add(b2);
   add(p);      
 
 
   subpanel=new Panel();
   subpanel.add(b1,"sub");
   subpanel.add(b2,"sub");
   add(subpanel);
       
   mainpanel.add(subpanel,"sub");  
   mainpanel.add(pro,"pro");
   mainpanel.add(cus,"cus");
 
   add(mainpanel);        
     
   b1.addActionListener(this);
   b2.addActionListener(this);
   b3.addActionListener(this);
   b4.addActionListener(this);
 

 
   addWindowListener(new MywindowAdapter());
  }
   
  public void actionPerformed(ActionEvent ae)
  {
      if(ae.getSource()==b1)
      {
          card.show(mainpanel,"pro");
      }
      if(ae.getSource()==b2)
      {
          card.show(mainpanel,"cus");      
      }
      if(ae.getSource()==b3)
      {
          card.show(mainpanel,"sub");      
      }
      if(ae.getSource()==b4)
      {
          card.show(mainpanel,"sub");      
      }
   
  }
 
  public static void main(String cd[])
  {
   new Card();
  }
 
 
  class MywindowAdapter extends WindowAdapter
  {
   public void windowClosing(WindowEvent we)
   {
     System.exit(0);
   }
  }
 
}

Notepad using Frame


Desktop Application

//this is a  Desktop Application Notepad  using  Frame


import java.awt.*;
import java.awt.event.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

class notepad extends Frame implements ActionListener
{
 MenuBar mbar;
 Menu file,color,send,font,edit;
 MenuItem nw,op,sv,ds,ex,pk,yl,email,excel,sd,fn1,fn2,cpy,pst;