-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path素数 LinkedList链表
More file actions
98 lines (83 loc) · 2.6 KB
/
Copy path素数 LinkedList链表
File metadata and controls
98 lines (83 loc) · 2.6 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package primeNumber;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class PrimeNumbber {
public static void main(String args[])
{
new num();
}
}
class num extends Frame implements ActionListener {
Label prompt1, prompt2;
TextField input1, input2;
TextArea output;
Button btn;
int a, b, k = 0;
String lst;
LinkedList<String> list = new LinkedList<>();
public num() {
prompt1 = new Label("请输入数据上限:");
prompt2 = new Label("请输入数据下限:");
input1 = new TextField(5);
input2 = new TextField(5);
output = new TextArea("",20,60);
btn = new Button("输出素数");
add(prompt1);
add(input1);
add(prompt2);
add(input2);
add(btn);
add(output);
output.setBackground(Color.black);
output.setForeground(Color.green);
btn.addActionListener(this);
input1.addFocusListener(new HandleFocus());
input2.addFocusListener(new HandleFocus());
addWindowListener(new windowsClose());
setLayout(new FlowLayout());//少不得,否则add添加的东西会一一覆盖,最后只有最后一个add能显示
setSize(500,500);
setTitle("求素数的application");
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
a = Integer.parseInt(input1.getText());
b = Integer.parseInt(input2.getText());
output.setText(a+"与"+b+"之间的素数有:"+"\n");
outer_loop:
for (int i = a; i <= b; i++) {
for (int j = 2; j <= Math.sqrt(i); j++) {
if (i % j == 0) {
continue outer_loop;
}
}
list.add(i+";");
}
for(int m=0;m<list.size();m++) {
if(m%10==0) {
output.append("\n");
}
output.append(list.get(m));
}
}
class HandleFocus implements FocusListener{
public void focusGained(FocusEvent e) {
TextField text = (TextField)(e.getSource());
text.setBackground(Color.pink);
text.setText("");
}
public void focusLost(FocusEvent e) {
TextField text = (TextField)(e.getSource());
text.setBackground(Color.white);
output.setText(a+"与"+b+"之间的素数有:"+"\n");
list.clear();
}
}
class windowsClose extends WindowAdapter{//window监视执行函数
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
}//end of winC
}