-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteBlank.java
More file actions
94 lines (83 loc) · 2.97 KB
/
Copy pathDeleteBlank.java
File metadata and controls
94 lines (83 loc) · 2.97 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
package com.mingrisoft;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
public class DeleteBlank extends JFrame {
/**
*
*/
private static final long serialVersionUID = -6680541067185258193L;
private JPanel contentPane;
private JTextField textField;
private JTextField resultField;
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
UIManager
.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Throwable e) {
e.printStackTrace();
}
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
DeleteBlank frame = new DeleteBlank();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public DeleteBlank() {
setTitle("\u53BB\u6389\u5B57\u7B26\u4E32\u4E2D\u7684\u6240\u6709\u7A7A\u683C");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 386, 128);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel label = new JLabel("\u8F93\u5165\u5B57\u7B26\u4E32\uFF1A");
label.setBounds(21, 10, 75, 15);
contentPane.add(label);
JButton button = new JButton("\u53BB\u9664\u7A7A\u683C");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
do_button_actionPerformed(e);
}
});
button.setBounds(10, 49, 82, 23);
contentPane.add(button);
textField = new JTextField();
textField.setBounds(102, 2, 258, 30);
contentPane.add(textField);
textField.setColumns(10);
resultField = new JTextField();
resultField.setBounds(102, 45, 258, 30);
contentPane.add(resultField);
resultField.setColumns(10);
}
protected void do_button_actionPerformed(ActionEvent e) {
String text = textField.getText();// 获取用户输入文本
StringBuilder strBuilder = new StringBuilder();// 创建字符串构建器
for (int i = 0; i < text.length(); i++) {// 遍历字符串
char charAt = text.charAt(i);// 获取每个字符
if (charAt == ' ')// 过滤空格字符
continue;
strBuilder.append(charAt);// 追加非空格字符到字符构建器
}
resultField.setText(strBuilder.toString());// 把构建器中的字符串显示到文本框
}
}