Advance Java Programming Assignment 1: Q1. What Components Will Be Needed To Get Following Output? 2 Marks
Advance Java Programming Assignment 1: Q1. What Components Will Be Needed To Get Following Output? 2 Marks
Advance Java Programming Assignment 1: Q1. What Components Will Be Needed To Get Following Output? 2 Marks
1
public void mousePressed(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Down";
repaint();
}
// Handle button released.
public void mouseReleased(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Up";
repaint();
}
// Handle mouse dragged.
public void mouseDragged(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "*";
showStatus("Dragging mouse at " + mouseX + ", " + mouseY);
repaint();
}
// Handle mouse moved.
public void mouseMoved(MouseEvent me)
{
showStatus("Moving mouse at " + me.getX() + ", " + me.getY());
}
// Display msg in applet window at current X,Y location.
public void paint(Graphics g)
{
g.drawString(msg, mouseX, mouseY);
}
}
a)addMouseListener(this);
b)addMouseListener(this);
addMouseMotionListener(this);
import java.awt.event.*;
c) addMouseListener();
d) all of above
2
add(m1);
add(m2);
add(m3);
m1.addItemListener(this);
m2.addItemListener(this);
}
public void itemStateChanged(ItemEventie)
{
if(ie.getSource()==m1)
setBackground(Color.red);
if(ie.getSource()==m2)
setBackground(Color.green);
}
}
/*<applet code=checkbackg.class height=150 width=150>
</applet>*/
// Display keystrokes.
4
public void paint(Graphics g) {
g.drawString(msg, X, Y);
}
}
Q10). Which method is used to translate a mouse click on a specific point of the tree to a tree path?
a) translatePoint( )
b) getLocation( )
c) getPathForLocation( )
d) getPath( )