Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Thursday, 23 February 2017

java program to change window color on click

package com.evenhandling;

import java.awt.*;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.awt.event.MouseMotionListener;

public class MouseDemo extends Frame implements MouseListener,MouseMotionListener{

 MouseDemo() {

  setSize(500,500);

  setVisible(true);

  addMouseListener(this);

     addMouseMotionListener(this);

 }

 public void mouseClicked(MouseEvent d) {

  setBackground(Color.GREEN);

 }

 public void mouseEntered(MouseEvent arg0) {

  setBackground(Color.white);

 }

 public void mouseExited(MouseEvent arg0) {

  setBackground(Color.black);

}

 public void mousePressed(MouseEvent arg0) {

  setBackground(Color.gray);

 }

 public void mouseReleased(MouseEvent arg0) {

  setBackground(Color.blue);

}

 public void mouseDragged(MouseEvent arg0) {

    setBackground(Color.MAGENTA);

}

 public void mouseMoved(MouseEvent arg0) {

  setBackground(Color.red);

}

 public static void main(String[]  args) {

  MouseDemo d=new MouseDemo();

 }

}


No comments:

Post a Comment