BCA Slip4 Java

Java

Slip4

Q.1) 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. [Marks 30]

Solution

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

class Slip4 extends Frame
{
        TextField statusBar;
        public static void main(String []args)
        {
                new Slip4().show();
        }

        Slip4()
        {
                addMouseListener(new MouseAdapter()
                {
                        public void mouseClicked(MouseEvent e)
                        {
                                statusBar.setText("Clicked at (" + e.getX() + "," + e.getY() + ")");
                                repaint();
                        }
                public void mouseEntered(MouseEvent e)
                        {
                                statusBar.setText("Entered at (" + e.getX() + "," + e.getY() + ")");
                                repaint();
                        }
               }
);
                addWindowListener(new WindowAdapter()
                {
                        public void windowClosing(WindowEvent e)
                        {
                                System.exit(0);
                        }
                });
                setLayout(new FlowLayout());
                setSize(275,300);
                setTitle("Mouse Click Position");
                statusBar = new TextField(20);
                add(statusBar);
                setVisible(true);
        }
}
BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

Post a Comment

Previous Post Next Post

DBMS Practical Slips