Pune University BCA Java Solved Examples

Pune University B. C. A. ( Semester -VI ) Examination - 2010
JAVA (2005 Pattern)

American Greetings
sponsored ad

Q1) Design a screen in Java which contains a text box. If the left
mouse button is clicked, convert text in upper case and if the
right button is clicked, convert it to lower case.




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


public class ClickDemo extends Frame implements MouseListener
  {
TextField t1;


public ClickDemo(String name)
  {
    super(name);
    t1=new TextField("Example by Kashid");
addMouseListener(this);   
   sponsored ad
    add(t1);iPhone Accessories - WirelessEmporium.com
  }


public void mousePressed(MouseEvent me)
      {  
        switch(me.getModifiers())
        {
           case InputEvent.BUTTON1_MASK: 
            {
              t1.setText(t1.getText().toUpperCase());    
              break;
             }
          case InputEvent.BUTTON2_MASK: 
             {
              System.out.println("You pressed Middle button");     
             break;
            }
      case InputEvent.BUTTON3_MASK: 
         {
         t1.setText(t1.getText().toLowerCase());;     
        break;
        }
     } 
              
      }


      public void mouseReleased(MouseEvent event) {}
       public void mouseExited(MouseEvent event) {}
       public void mouseEntered(MouseEvent event) {}
       public void mouseClicked(MouseEvent event) {}


      public static void main(String[]args)
      {
        ClickDemo a=new ClickDemo("Click Demo");
         a.setSize(150,150);
         a.setLayout(new FlowLayout());
        a.setVisible(true);
       }
  }

No comments:

Post a Comment

Thanks for visiting my Blog!

Have a Question ? Need Help in College Assignments, Need Code that is not available here? Just leave a comment & get your code instantly.

Tips to Enhance Your Blog