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.
Variables
Elements or factors within a study or experiment that can change and potentially influence outcomes.
Scientific Method
A systematic process for gathering knowledge and testing scientific theories and hypotheses through observation and experimentation.
Hypothesis
A proposed explanation for a phenomenon, made as a starting point for further investigation, which can be tested through research and experimentation.
Theory
A coherent group of propositions formulated to explain a group of facts or phenomena in the natural world and repeatedly confirmed through experiment or observation.
Q9: Virtues are positive traits of character.
Q11: When a Swing object such as JPanel
Q13: According to Aristotle the good is<br>A) The
Q14: Removing a person from a respirator after
Q26: The ratio of boys to girls in
Q27: The _ method is useful in debugging
Q28: What has value because people value it
Q40: In the drawPolygon() method, what are the
Q42: Write the statement to draw a rectangle
Q49: The BufferedWriter class contains a _ method