The first one is answered as follows. Help with the second one. package test; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JavaApplication1 { public static void main(String[] arguments) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("print X and Y Coordinates"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.setSize(500,400); final JTextField output = new JTextField();; frame.add(output,BorderLayout.SOUTH); frame.addMouseListener(new MouseListener() { public void mousePressed(MouseEvent me) { } public void mouseReleased(MouseEvent me) { } public void mouseEntered(MouseEvent me) { } public void mouseExited(MouseEvent me) { } public void mouseClicked(MouseEvent me) {
The first one is answered as follows. Help with the second one.
package test;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JavaApplication1 {
public static void main(String[] arguments) {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("print X and Y Coordinates");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.setSize(500,400);
final JTextField output = new JTextField();;
frame.add(output,BorderLayout.SOUTH);
frame.addMouseListener(new MouseListener() {
public void mousePressed(MouseEvent me) { }
public void mouseReleased(MouseEvent me) { }
public void mouseEntered(MouseEvent me) { }
public void mouseExited(MouseEvent me) { }
public void mouseClicked(MouseEvent me) {
int x = me.getX();
int y = me.getY();
output.setText("Coordinate X:" + x + "|| Coordinate Y:" + y);
}
});
frame.setVisible(true);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps