Skip to content

Instantly share code, notes, and snippets.

@peketamin
Created October 15, 2020 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peketamin/8183ef9ce74043e81750f18e84df3de4 to your computer and use it in GitHub Desktop.
Save peketamin/8183ef9ce74043e81750f18e84df3de4 to your computer and use it in GitHub Desktop.
frame_example.java
import java.awt.*;
import java.awt.event.*;
public class Rei26 extends Frame {
private int oldx = 0, oldy = 0;
public Rei26() {
setSize(400, 300);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
oldx = e.getX();
oldy = e.getY();
}
});
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
Graphics g = getGraphics();
int x = e.getX();
int y = e.getY();
setTitle("x=" + x + ": y=" + y);
g.drawLine(oldx, oldy, x, y);
oldx = x;
oldy = y;
g.dispose();
}
});
}
public static void main(String[] args) {
Frame w = new Rei26();
w.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment