88 Week10

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Object Oriented Programming Lab

WEEK-10(Programs)

NAME: E.Praveen Reddy DATE :27.11.2024 HTNO :22R21A0488.

1) PROBLEM STATEMENT: Write a java program to implement


mouseEvent by using applets?

PROGRAM :
import java.awt.*; import

java.applet.Applet; import

java.awt.event.*;

/*<applet code="Mouseevents"width=200 height=100></applet>*/ public class Mouseevents

extends Applet implements MouseListener,MouseMotionListener { String msg=""; int x=0,y=0;

public void init() { addMouseListener(this); addMouseMotionListener(this); } public void

mouseClicked(MouseEvent me) { x=10; y=20; msg="mouse clicked"; repaint(); } public void

mouseEntered(MouseEvent me) { x=10; y=20; msg="mouse entered"; repaint(); } public void

mouseExited(MouseEvent me) { x=10;

y=20; msg="mouse Exited"; repaint(); } public

void mousePressed(MouseEvent me) {

x=me.getX(); y=me.getY(); msg="down";

repaint(); } public void mouseReleased(MouseEvent me) {

x=me.getX(); y=me.getY(); msg="up"; repaint(); } public void

mouseDragged(MouseEvent me) { x=me.getX(); y=me.getY();

msg="*"; showStatus("dragging mouse at"+x+","+y);

repaint(); } public void mouseMoved(MouseEvent me) {

showStatus("moving mouse at"+me.getX()+","+me.getY()); }

public void paint(Graphics g) {

g.drawString(msg,x,y); } }
2) PROBLEM STATEMENT: Write a java program to implement
KeyEvents PROGRAM
:
import java.awt.*; import java.awt.event.*; public class

KeyAdapterExample extends KeyAdapter {

Label I;

TextArea area;

Frame f;

KeyAdapterExample() { f=new

Frame("Key Adapter"); I=new

Label();

I.setBounds(20,50,200,20);

area=new TextArea();

area.setBounds(20,80,300,300);

area.addKeyListener(this);

f.add(I);

f.add(area);

f.setSize(400,400);

f.setLayout(null);

f.setVisible(true); } public void

keyReleased(KeyEvent e) {

String text=area.getText();

String words[]=text.split("\\s");
I.setText("words:"+words.length+ "characters:"+text.length()); }

public static void main (String args[]) { new KeyAdapterExample();

} }

3) PROBLEM STATEMENT: : Write a java program to implement


KeyEvents by using applets?
PROGRAM :
import java.applet.Applet;

import java.awt.*; import

java.awt.event.*;

/*<applet code = "KeyAdapterExample.class"width= "400" height="400"></applet>*/ public

class KeyAdapterExample extends applet {

Label l;

TextArea area;

public void init() {

setSize(400, 400); l

= new Label();

l.setBounds(20, 50, 360, 40);

l.setFont(new Font("Arial", Font.PLAIN, 24));

area = new TextArea(); area.setBounds(20,

80, 300, 300); area.addKeyListener(new

KeyAdapter() { public void

keyPressed(KeyEvent e)

l.setText("Typing"); } public void

keyReleased(KeyEvent e) {

String text = area.getText(); String

words[] = text.split("\\s+");
l.setText("Released - Words: " + words.length + " Characters: " + text.length()); } });

add(l); add(area); area.setFocusable(true); } }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy