Created
October 15, 2020 04:48
-
-
Save peketamin/8183ef9ce74043e81750f18e84df3de4 to your computer and use it in GitHub Desktop.
frame_example.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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