当前位置:网站首页>Mouse monitor, Paintbrush
Mouse monitor, Paintbrush
2022-07-25 10:16:00 【Look at the bugs】
Simple brush
package Paint;
import java.awt.*;
public class Paint {
public static void main(String[] args) {
new MyPaint().loadFrame();
}
}
class MyPaint extends Frame {
public void loadFrame(){
setVisible(true);
setBounds(100,200,600,400);
}
// paint brush
@Override
public void paint(Graphics g) {
// The brush needs color , The brush can draw
// g.setColor(Color.red);
g.drawOval(100,200,100,100);
g.fill3DRect(100,100,100,100,true);
// g.setColor(Color.GREEN);
g.fillRect(200,200,100,100);
// Out of brushes , Restore to the original color
}
}
Mouse monitor , Draw points with a brush
package Listener;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Iterator;
//1, Create a mouse listener class , Get the current coordinates of the mouse by listening (x,y), And form a point
//2, Save this point in the set
//3, Take out the points in the set with a brush , And present it on the drawing board
public class MouseListener {
public static void main(String[] args) {
new MyFrame(" Drawing a picture ");
}
}
// My own class Test mouse monitoring events
class MyFrame extends Frame {
ArrayList points ;
public MyFrame(String title){
super(title);
setBounds(100,200,300,300);
// Save the mouse point
points =new ArrayList<>();
setVisible(true);
// Refresh the window in real time
// Not need it for now validate();
// Mouse monitor , Facing this window
this.addMouseListener(new MyMouseListener());
}
@Override
public void paint(Graphics g) {
// Painting requires monitoring mouse events
Iterator iterator=points.iterator();
while(iterator.hasNext()){
Point point=(Point) iterator.next();
g.setColor(Color.blue);
// g.drawOval(point.x,point.y,10,10);
g.fillOval(point.x,point.y,10,10);
}
}
// Add a point to the interface
public void addPoint(Point point){
points.add(point);
}
// Adapter pattern
private class MyMouseListener extends MouseAdapter{
// mouse
@Override
public void mousePressed(MouseEvent e) {
MyFrame myFrame= (MyFrame) e.getSource();
// Click to generate a point on the interface
// This point is the point of the mouse
myFrame.addPoint( new Point(e.getX(),e.getY()));
// new Point(e.getX(),e.getY());
// Redraw every time you click , Update window
myFrame.repaint();
}
}
}
Keyboard monitor
class KeyFrame extends Frame {
public KeyFrame() {
setBounds(100,100,200,200);
setVisible(true);
this.addKeyListener(new KeyAdapter() {
//K It's in capital letters
@Override
public void keyPressed(KeyEvent e) {
int KeyCode=e.getKeyCode();
System.out.println(KeyCode); // Get the key 16 Base number ASCII code
if(KeyCode==KeyEvent.VK_UP){
System.out.println(" You press the up button ");
}
}
});
}
}
边栏推荐
猜你喜欢

复现 ASVspoof 2021 baseline RawNet2

GCD详解

Common methods of nodejs version upgrade or switching

字典树的使用

升级 GLIBC 2.29 checking LD_LIBRARY_PATH variable... contains current directory error 解决方案

文件的上传功能

Pytorch 张量列表转换为张量 List of Tensor to Tensor 使用 torch.stack()

UE4 窗口控制(最大化 最小化)

ROS distributed operation -- launch file starts nodes on multiple machines

mysql 解决不支持中文的问题
随机推荐
Yarn quick reference manual
多线程——Runnable接口,龟兔赛跑
message from server: “Host ‘xxx.xxx.xxx.xxx‘ is not allowed to connect to this MySQL server“
小程序分享功能
动态规划,购物单问题
MVC三层架构理解
@Import,Conditional和@ImportResourse注解
Selenium 等待元素出现与等待操作可以执行的条件
记录一些JS工具函数
语音自监督预训练模型 CNN Encoder 调研总结
IO流中的输出流
emmet语法速查 syntax基本语法部分
Usage of string slicing
nodejs链接mysql报错:ER_NOT_SUPPORTED_AUTH_MODEError: ER_NOT_SUPPORTED_AUTH_MODE
VSCode Latex Workshop 设置 XeLatex 编译
salt常见问题
用户喜好
Pytorch 张量列表转换为张量 List of Tensor to Tensor 使用 torch.stack()
RedisUtil
Swing的组件图标