Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Core Java Practical Slip 2 Answers

 Write a ‘java’ program to display

Slip 2 A) Write a java program to display all the vowels from a given string.

Answer :

import java.io.DataInputStream;

class Slip2A {

    public static void main(String args[]){

        DataInputStream dr  = new DataInputStream(System.in);

        try {

            System.out.print("Enter String : ");

            String str = dr.readLine().toLowerCase();

            for(int i=0; i<str.length(); i++){

                if(str.charAt(i)=='a' || str.charAt(i)=='e' || str.charAt(i)=='i' || str.charAt(i)=='o'  || str.charAt(i)=='u' ){

                    System.out.print(str.charAt(i));

                }

            }

        } catch (Exception e) {}

    }

}

Output :



Slip 2 B) Design a screen in Java to handle the Mouse Events such as MOUSE_MOVED and MOUSE_CLICK and display the position of the Mouse_Click in a TextField.

Answer :

import java.awt.*;

import java.awt.event.*;

class MyFrame extends Frame

{

                TextField t,t1;

                Label l,l1;

                int x,y;

                Panel p;

                MyFrame(String title)

                {

                                super(title);

                                setLayout(new FlowLayout());

                               

                                p=new Panel();

                                p.setLayout(new GridLayout(2,2,5,5));

                                t=new TextField(20);

                                l= new Label("Mouse clicking");

                                l1= new Label("Mouse Movement");

                                t1=new TextField(20);

                                p.add(l);

                                p.add(t);

                                p.add(l1);

                                p.add(t1);

                                add(p);

                                addMouseListener(new MyClick());

                                addMouseMotionListener(new MyMove());

                                setSize(500,500);

                                setVisible(true);

                }

                class MyClick extends MouseAdapter

                {

                                public void mouseClicked(MouseEvent me)

                                {

                                                x=me.getX();

                                                y=me.getY();

                                                t.setText("X="+x+" Y="+y);

                                }

                }

                class MyMove extends MouseMotionAdapter

                {

                                public void mouseMoved(MouseEvent me)

                                {

                                                x=me.getX();

                                                y=me.getY();

                                                t1.setText("X="+ x +" Y="+y);

                                }

                }

}

class Slip2B

{

                public static void main(String args[])

                {

                                MyFrame f = new MyFrame("Slip Number 4");

                }

}

Output :

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Core Java Practical Slip 2 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Core Java Practical Slip 2 Answers Reviewed by technical_saurabh on December 29, 2021 Rating: 5

No comments:

Powered by Blogger.