kk Blog —— 通用基础


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

Java 多次排序的方法

Java 多次排序的方法

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
import java.util.*;

class Node implements Comparable
{
	int x,y;
	public int compareTo(Object obj){
		Node oo=(Node)obj;
		if(Main.u == 1) {
			if(oo.x < this.x || oo.x == this.x && oo.y <this.y)return 1;
			return -1;
		} else
		if(Main.u == 2) {
			if(oo.y < this.y || oo.y == this.y && oo.x <this.x)return 1;
			return -1;
		}
		return -1;
	}
}

public class Main {
	public static int u;

	public static void main(String[] args) throws Exception {
		Scanner cin = new Scanner(System.in);
		Node a[]=new Node[11];
		int i,j,k,l;
		for(i=1;i<=10;i++) {
			a[i]=new Node();
			a[i].x=Math.abs(5-i); a[i].y=10-Math.abs(7-i);
		}
		u = 1;
		Arrays.sort(a, 1, 11);
		System.out.println(" sort u = 1");
		for(i=1;i<=10;i++)System.out.println(a[i].x+" "+a[i].y);
		u = 2;
		Arrays.sort(a, 1, 11);
		System.out.println(" sort u = 2");
		for(i=1;i<=10;i++)System.out.println(a[i].x+" "+a[i].y);
	}
}

Java Mune & Button

Java Mune & Button

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
52
53
54
55
56
57
58
59
60
61
62
//package java_menu;
import java.awt.*;
import java.awt.event.*;

class BBB extends Button
{
	private int tt=0;
	public BBB() {
		super("0");
		addMouseListener( new MouseListener() {
			public void mousePressed(MouseEvent e) {
				setLabel(String.valueOf((++tt)));
			}
			public void mouseExited(MouseEvent e) {}
			public void mouseReleased(MouseEvent e) {}
			public void mouseEntered(MouseEvent e) {}
			public void mouseClicked(MouseEvent e) {}
		});
		int x=(int)(Math.random()*10000), y=(int)(Math.random()*10000);
		setBounds( x % 500+70, y % 300+70, 70, 70);
		show();
	}
}

class MenuExam extends Frame
{
	public MenuExam()
	{
		super("abcdxyzk");
		MenuBar bar = new MenuBar(); setMenuBar(bar);
		Menu bb = new Menu(" bbb ");
		MenuItem b1 = new MenuItem(" b1 ");
		MenuItem b2 = new MenuItem(" b2 ");
		bb.add(b1); bb.addSeparator(); bb.add(b2); bar.add(bb);

		b2.addActionListener( new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				BBB bbb = new BBB();
				add(bbb);
			}
		});
		setLayout(null);   setSize(700, 500);
		TextField tf = new TextField();
		tf.setText("click b2");
		tf.setFont(new Font("TimesRoman", Font.BOLD, 30));
		tf.setEnabled(false);
		tf.setBounds(100, 350, 200, 100);
		add(tf);
		show();
	}
}

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

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();
	}
}