kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

Java WindowListener & ActionListener

Java WindowListener & ActionListener

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//package java_window;
import java.awt.*;
import java.awt.event.*;

class Window
{
	Frame fra = new Frame();
	public static int tt = 1;
	public static Label lb = new Label(" label ");
	public void go() {
		fra.addWindowListener(
			new WindowAdapter(){
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		fra.setSize(700, 550);
		fra.setLayout(null);
		Button but = new Button(" OK ");
		but.setBounds(200, 200, 100, 70); fra.add(but);
		lb.setBounds(200, 300, 200, 100);  fra.add(lb);

		but.addActionListener(
			new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				 lb.setText("ActionEvent "+event.getActionCommand()+"   "+(tt++));
			}
		});
		fra.show();
	}
}

public class Main {
	public static void main(String[] args) {
		Window win = new Window();
		win.go();
	}
}

Java KeyListener 的使用

Java KeyListener 的使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//package java_key;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class KeyWork extends JFrame implements KeyListener
{
	private JLabel status;
	public KeyWork()
	{
		super("abcd");
		status = new JLabel();
		status.setFont(new Font("TimesRoman", Font.BOLD, 50));
		getContentPane().add(status, BorderLayout.CENTER);
		addKeyListener(this);
		setSize(700,500);
		show();
	}
	public void keyPressed(KeyEvent e) {
		char ch = e.getKeyChar();
		status.setText(String.valueOf(ch) + "   " +(int)ch);
	}
	public void keyTyped(KeyEvent e) {
	   
	}
	public void keyReleased(KeyEvent e) {
	   
	}
}

public class Main {
	public static void main(String[] args) {
		KeyWork app = new KeyWork();
		app.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}
}

Java MouseListener & MouseMotionListener

Java 获取鼠标坐标
1
Point point= MouseInfo.getPointerInfo().getLocation();

Java MouseListener & MouseMotionListener 的使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class MouseWork extends JFrame implements MouseListener,MouseMotionListener
{
	private JLabel status;
	public MouseWork()
	{
		super("abcd");
		status = new JLabel();
		status.setFont(new Font("TimesRoman", Font.BOLD, 50));
		getContentPane().add(status, BorderLayout.CENTER);
		addMouseListener(this);
		addMouseMotionListener(this);
		setSize(700,500);
		show();
	}
	public void mousePressed(MouseEvent e) {
		status.setText(" Pressed "+e.getX()+" "+e.getY());
	}
	public void mouseExited(MouseEvent e) {
		status.setText(" Exited ");
	}
	public void mouseEntered(MouseEvent e) {
		status.setText(" Entered ");
	}
	public void mouseReleased(MouseEvent e) {
		status.setText(" Released ");
	}
	public void mouseClicked(MouseEvent e) {
		status.setText(" Clicked ");
	}
	public void mouseDragged(MouseEvent e) {
		status.setText(" Dragged "+e.getX()+" "+e.getY());
	}
	public void mouseMoved(MouseEvent e) {
		status.setText(" Moved "+e.getX()+" "+e.getY());
	}
}

public class Main {
	public static void main(String[] args) {
		MouseWork app = new MouseWork();
		app.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}
}