Question

q2: Write a public class named MythMouseListener that implements the Mouselistener interface. This class will have a public constructor that takes a JTextArea and a JLabel as parameters and stores these in instance variables. Override the mouseEntered method to . display the text from the JTextArea on the JLabel in all upper case letters. Then, override the mouseReleased method to display the text from the JTextArea on the JLabel in all lower case letters. The other three methods from the MouseListener interface can be .left empty q3: Create a public class named Servant with private instance variables ill, after and worldwide each of type int. You may add any other methods and variables youd like to this class. Outside of Servant Cin the Problem Set class) write a public static method named sortServant that takes an ArrayList of Servants as a parameter and returns void. This method will sort the input by the variable worldwide in decreasing order
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hello.....

I have a solution for you...

As per the check rules I can solve your first question ....

MythMouseListener.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MythMouseListener extends JFrame implements MouseListener
{
JTextArea t1;
JLabel l1;
String s;
public MythMouseListener() // constructor method
{
setTitle("My Mouse Listener"); // setting title to the frame
setSize(420,220); // setting size of the frame
getContentPane().setBackground(Color.CYAN); // setting backgroung color
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null); // set no layout
// creating controls
t1=new JTextArea("Hello...How are you...?");  
l1=new JLabel("");
// setting bounds to the controls
l1.setBounds(20,20,300,50);
t1.setBounds(20,80,360,80);
// adding controls
add(l1);
add(t1);
// adding mouse listener on JTextArea
t1.addMouseListener(this);
setVisible(true); // make frame visible
}
// overriding all mouse listener methods
@Override
public void mousePressed(MouseEvent e)
{
// TODO Auto-generated method stub  
}
@Override
public void mouseReleased(MouseEvent e)
{
s=t1.getText().toLowerCase();
l1.setText(s);  
}
@Override
public void mouseEntered(MouseEvent e) // when mouse entered on jtextarea
{
s=t1.getText().toUpperCase(); // get data from jtextfield and make it in uppercase
l1.setText(s); // display uppercase string in jlabel
}

// I am doing this mouseExited method also because i think this is opposite operation of mouseEntered
// So if you want you can make this method empty
@Override
public void mouseExited(MouseEvent e)
{
s=t1.getText().toLowerCase(); / get data from jtextfield and make it in lowercase
l1.setText(s); // display lowercase string in jlabel
}
@Override
public void mouseClicked(MouseEvent e)
{
// TODO Auto-generated method stub  
}
public static void main(String args[])
{
new MythMouseListener(); // anonymous object of MythMouseListener class
}
}

Output

C:\Users\AKSHAY\Desktop>javac MythMouseListener.java

C:\Users\AKSHAY\Desktop>java MythMouseListener

1 My Mouse Listener HELLO.. .HOW ARE YOU...? Hello...How are you...?

My Mouse Listener hello..how are you.. Hello... How are you...?

Thank you...

Add a comment
Know the answer?
Add Answer to:
q2: Write a public class named MythMouseListener that implements the Mouselistener interface. This class will have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java question so right now this code is work perfectly the problem is I also want...

    Java question so right now this code is work perfectly the problem is I also want to know if possible to get the X and Y value outside the JFrame? import java.awt.FlowLayout; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JFrame; import javax.swing.JLabel; public class MouseEventDemo extends JFrame implements MouseListener { //It is a class which generate a JFrame and implements MouseListener interface //These all are text that show x , y coordinates on mouse click event JLabel lclick; JLabel lpressed; JLabel lreleased;...

  • please write code in java, assignment is due soon Thanks. public interface Named The Named interface...

    please write code in java, assignment is due soon Thanks. public interface Named The Named interface is a simple interface which applies to anything which has a name. The only thing required is the following method: String name() which returns the name of the instance. public interface MessageSink, It includes: void deliver(Named sender, String message) delivers the specified message from the given sender. public interface Sharable, which is Named, It includes no method. public abstract class GeneralCapability It incudes: The...

  • (The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal a...

    (The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make implement the Edible interface. howToEat() and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML diagram for the classes and the interface 2. Use Arraylist class to create an...

  • Create a data class named Automobile that implements the Comparable interface. Give the class data fields...

    Create a data class named Automobile that implements the Comparable interface. Give the class data fields for make, model, year, and price. Then add a constructor, all getters, a toString method that shows all attribute values, and implement Comparable by using the year as the criterion for comparing instances. Write a program named TestAutos that creates an ArrayList of five or six Automobiles. Use a for loop to display the elements in the ArrayList. Sort the Arraylist of autos by...

  • Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design...

    Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make Chicken and Cow as subclasses of Dairy. The Sheep and Dairy classes implement the Edible interface. howToEat) and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML...

  • Define an interface named Shape with a single method named area that calculates the area of...

    Define an interface named Shape with a single method named area that calculates the area of the geometric shape:        public double area(); Next, define a class named Circle that implements Shape. The Circle class should have an instance variable for the radius, a constructor that sets the radius, an accessor and a mutator method for the radius, and an implementation of the area method. Define another class named Rectangle that implements Shape. The Rectangle class should have instance variables...

  • Java code please. Please help * 95: Write a public class named TollInts with the following....

    Java code please. Please help * 95: Write a public class named TollInts with the following. * -A public constructor that takes 2 doubles as inputs. * -A public method named compute that takes no parameters and returns the the tangent of the * first constructor input subtracted by the the square root of the second constructor input * as a double. You will need to store the constructor input in instance variables to be able * to access them...

  • Consider the following Java interface. public interface Converter<A, B> { B convert(A xs); } (a) Write...

    Consider the following Java interface. public interface Converter<A, B> { B convert(A xs); } (a) Write a default method convertAll in the interface Converter that takes ArrayList<A> xs as input and returns a new ArrayList<B>. If the ArrayList xs is [x1, : : :, xn], the method returns [convert(x1), : : :, convert(xn)]. In your method you may assume that xs is never null. If one of the calls to convert throws an exception, your method should not catch it....

  • MasterMind in Java Activity MasterMind project Create a new Java Application project named MasterMind allowing Netbeans...

    MasterMind in Java Activity MasterMind project Create a new Java Application project named MasterMind allowing Netbeans IDE to create the main class called MasterMind.java MasterMind class Method main() should: Call static method System.out.println() and result in displaying “Welcome to MasterMind!” Call static method JOptionPane.showMessageDialog(arg1, arg2) and result in displaying a message dialog displaying “Let’s Play MasterMind!” Instantiate an instance of class Game() constants Create package Constants class Create class Constants Create constants by declaring them as “public static final”: public...

  • I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a...

    I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a void method named howToColor(). void howToColor(); } GeometricObject class: public class GeometricObject { } Sqaure class: public class Square extends GeometricObject implements Colorable{ //side variable of Square double side;    //Implementing howToColor() @Override public void howToColor() { System.out.println("Color all four sides."); }    //setter and getter methods for Square public void setSide(double side) { this.side = side; }    public double getSide() { return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT