Examlex
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JMouseActionFrame extends JFrame implements MouseListener
{
private int x, y;
private JLabel label = new JLabel("Do something with the mouse");
String msg = "";
public JMouseActionFrame()
{
setTitle("Mouse Actions"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout()); addMouseListener(this);
add(label);
}
public void mouseClicked(MouseEvent e)
{
int whichButton = e.getButton(); msg = "You pressed mouse ";
if(whichButton == MouseEvent.BUTTON1)
msg += "button 1.";
else
if(whichButton == MouseEvent.BUTTON2)
msg += "button 2.";
else
msg += "button 3.";
msg += " You are at position " +
e.getX() + ", " + e.getY() + ".";
if(e.getClickCount() == 2)
msg += " You double-clicked.";
else
msg += " You single-clicked.";
label.setText(msg);
}
@Override
public void mouseEntered(MouseEvent e)
{
msg = "You entered the frame.";
label.setText(msg);
}
@Override
public void mouseExited(MouseEvent e)
{
msg = "You exited the frame.";
label.setText(msg);
}
@Override
public void mousePressed(MouseEvent e)
{
}
@Override
public void mouseReleased(MouseEvent e)
{
}
@Override
public static void main(String[] args)
{
JMouseActionFrame mFrame = new JMouseActionFrame();
final int WIDTH = 750; final int HEIGHT = 300; mFrame.setSize(WIDTH, HEIGHT); mFrame.setVisible(true);
}
}
The above code shows a JMouseActionFrame application that demonstrates several of the mouse listener and event methods. The constructor sets a frame title by passing it to the parent of JMouseActionFrame , sets a close operation, sets the layout manager, enables the frame to listen for mouse events, and adds the JLabel to the JFrame . However, most of the action occurs in the mouseClicked() method. Describe what actions occur in this method.
Instrumental Value
The value of something not for what it is itself, but for its utility in achieving something else.
Dollar Value
The worth of a good or service expressed in terms of the amount of currency required to purchase it.
Net Worth
The total value of an individual's or entity's assets minus liabilities, indicating financial health or position.
Stewardship
The responsible overseeing and protection of something considered worth caring for and preserving, often related to environmental and natural resources.
Q5: When you use the BufferedReader class, you
Q10: According to individual ethical relativism, I cannot
Q11: Which of the following is not necessary
Q12: What is the process of inlining and
Q20: Of which kind of reasoning , Act
Q23: You can add an item at any
Q30: Affirmative action programs presume that past discrimination
Q49: An application's ability to select the correct
Q52: Clicking a component results in a(n) _.<br>A)
Q66: A _ is a component that combines