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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
| package index;
|
| import index.JPanelMoudle.*;
|
| import java.awt.*;
| import javax.swing.*;
|
|
| /**
| * @author zsh
| */
| public class GCUWBreadIndex extends JFrame {
| static ImageIcon icon = new ImageIcon("image/scan.png"); // 请替换为你图标的路径
| public GCUWBreadIndex() {
| // 获取屏幕的分辨率
| GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
| GraphicsDevice gd = ge.getDefaultScreenDevice();
| Rectangle screenBounds = gd.getDefaultConfiguration().getBounds();
| int screenWidth = screenBounds.width;
| int screenHeight = screenBounds.height;
|
| // 根据屏幕尺寸调整窗口大小
| setSize(screenWidth / 2, screenHeight / 2); // 设置窗口为屏幕尺寸的一半
| setLocationRelativeTo(null); // 居中显示窗口
|
| // 窗口属性
| setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
| setTitle("GC UWB信标扫描软件V1.2");
| setIconImage(icon.getImage());
| initComponents();
| }
|
| private void initComponents() {
| try {
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
| } catch (Exception e) {
| e.printStackTrace();
| }
| Container contentPane = getPane();
| anchor_TableList(contentPane);
| readComList(contentPane);
| readWriteAnchorParams(contentPane);
| DataShow(contentPane);
| versionUpgrade(contentPane);
| pack();
| setLocationRelativeTo(getOwner());
| }
|
|
| //选择串口界面
| private void readComList(Container contentPane) {
| ComMoudleComp.getCom_jp().setLayout(new GridBagLayout());
| int[] columnWidths = {110, 110, 220};
| int[] rowHeights = {46, 46, 0, 46};
| double[] columnWeights = {1.0, 1.0, 1.0};
| double[] rowWeights = {1.0, 1.0, 1.0, 1.0};
| //设置布局器的参数
| setGridBagLayoutParams(ComMoudleComp.getCom_jp(), columnWidths, rowHeights, columnWeights, rowWeights);
| // 添加组件
| addLabelAndField(ComMoudleComp.getCom_jp(), ComMoudleComp.getChuanKou_jl(), ComMoudleComp.getChuanKou_jcom(), 0, 0,2);
| addLabelAndField(ComMoudleComp.getCom_jp(), ComMoudleComp.getBotelv_jl(), ComMoudleComp.getBoteLV_jcm(), 0, 1,2);
| // 添加按钮
| addButton(ComMoudleComp.getCom_jp(), ComMoudleComp.getOpen(), 0, 3, 2, 1);
| addButton(ComMoudleComp.getCom_jp(), ComMoudleComp.getClose(), 2, 3, 1, 1);
| // 最后将容器添加到 contentPane
| contentPane.add(ComMoudleComp.getCom_jp(),
| new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
| GridBagConstraints.CENTER, GridBagConstraints.BOTH,
| new Insets(0, 0, 5, 5), 0, 0));
| }
|
| //信标列表模块
| private void anchor_TableList(Container contentPane) {
| anchorListComp.getAncList_jp().setLayout(new GridBagLayout());
| int[] columnWidths = {449, 0};
| int[] rowHeights = {480, 50, 0};
| double[] columnWeights = {1.0, 1.0E-4};
| double[] rowWeights = {1.0, 0.0, 1.0E-4};
| // 设置 GridBagLayout 配置
| setGridBagLayoutParams(anchorListComp.getAncList_jp(), columnWidths, rowHeights, columnWeights, rowWeights);
| // 添加组件
| addScrollPane(anchorListComp.getAncList_jp(), anchorListComp.getScrollPane1(), anchorListComp.getAncTable(), 0, 0, 1, 1);
| addButton(anchorListComp.getAncList_jp(), anchorListComp.getSelect_anc(), 0, 1, 1, 1);
|
| // 最后将容器添加到 contentPane
| contentPane.add(anchorListComp.getAncList_jp(),
| new GridBagConstraints(0, 1, 1, 2, 0.0, 0.0,
| GridBagConstraints.CENTER, GridBagConstraints.BOTH,
| new Insets(0, 0, 0, 5), 0, 0));
| }
|
| //固件升级界面
| private void versionUpgrade(Container contentPane) {
| versionUpgradeComp.getVersionUpdate().setLayout(new GridBagLayout());
| int[] columnWidths = {143, 350, 0};
| int[] rowHeights = {38, 54, 50, 58, 54, 0};
| double[] columnWeights = {1.0, 1.0, 1.0};
| double[] rowWeights = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
| // 设置 GridBagLayout 配置
| setGridBagLayoutParams(versionUpgradeComp.getVersionUpdate(), columnWidths, rowHeights, columnWeights, rowWeights);
| addLabelAndField(versionUpgradeComp.getVersionUpdate(), versionUpgradeComp.getLabel9(), versionUpgradeComp.getLabel9(), 0, 0,2);
| addLabelAndField(versionUpgradeComp.getVersionUpdate(), versionUpgradeComp.getReadVersion_jb(), versionUpgradeComp.getReadVersion_jf(), 0, 1,2);
| addLabelAndField(versionUpgradeComp.getVersionUpdate(), versionUpgradeComp.getChooseVersion(), versionUpgradeComp.getChooseVersion_jf(), 0, 2,2);
| addLabelAndField(versionUpgradeComp.getVersionUpdate(), versionUpgradeComp.getWrite_saoMiao(), versionUpgradeComp.getJindu_SaoMiaoQi(), 0, 3,2);
| addLabelAndField(versionUpgradeComp.getVersionUpdate(), versionUpgradeComp.getUpdateAnchor_jb(), versionUpgradeComp.getUpdateAnchor_jf(), 0, 4,2);
| // 添加到 contentPane
| contentPane.add(versionUpgradeComp.getVersionUpdate(), new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
| GridBagConstraints.CENTER, GridBagConstraints.BOTH,
| new Insets(0, 0, 0, 5), 0, 0));
| }
|
|
| //读写参数模块
| private void readWriteAnchorParams(Container contentPane) {
| readParamsComp.getReadAncParam_jp().setLayout(new GridBagLayout());
| int[] columnWidths = {139, 124*2,30, 160, 0};//每列的宽度
| int[] rowHeights = {50, 50, 50, 50, 50, 50, 50, 50, 50, 0};//每行的高度
| double[] columnWeights = {1.0, 1.0, 1.0,1.0, 0};
| double[] rowWeights = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0};
| // 设置 GridBagLayout 配置
| setGridBagLayoutParams(readParamsComp.getReadAncParam_jp(), columnWidths, rowHeights, columnWeights, rowWeights);
| // 添加组件
| addLabelAndField(readParamsComp.getReadAncParam_jp(), readParamsComp.getAnchorId(), readParamsComp.getAnchorId_jf(), 0, 1,3);
| addLabelAndField(readParamsComp.getReadAncParam_jp(), readParamsComp.getAnchorVersion(), readParamsComp.getAnchorVersion_jf(), 0, 2,3);
| addLabelAndFieldAndButton(readParamsComp.getReadAncParam_jp(), readParamsComp.getGroupId(), readParamsComp.getGroupId_jf(), readParamsComp.getSaveParam_GroupID(),0, 3);
| addLabelAndFieldAndButton(readParamsComp.getReadAncParam_jp(), readParamsComp.getAnchorPower(), readParamsComp.getAnchorPower_jf(), readParamsComp.getSaveParam_anchorPower(),0, 4);
| addLabelAndFieldAndButton(readParamsComp.getReadAncParam_jp(), readParamsComp.getJiaoZhunDis(), readParamsComp.getJiaoZhunDis_jf(), readParamsComp.getSaveParam_jiaoZhunDis(),0, 5);
| addLabelAndFieldAndButton(readParamsComp.getReadAncParam_jp(), readParamsComp.getLabel6(), readParamsComp.getTextField6(), readParamsComp.getSaveParam_label6(),0, 6);
| addLabelAndFieldAndButton(readParamsComp.getReadAncParam_jp(), readParamsComp.getLabel7(), readParamsComp.getTextField7(),readParamsComp.getSaveParam_label7(), 0, 7);
| addLabelAndFieldAndButton(readParamsComp.getReadAncParam_jp(), readParamsComp.getLabel8(), readParamsComp.getTextField8(), readParamsComp.getSaveParam_label8(),0, 8);
| // 添加按钮
| addButton(readParamsComp.getReadAncParam_jp(), readParamsComp.getReadParam(), 0, 0, 4, 1);
|
| // 最后将容器添加到 contentPane
| contentPane.add(readParamsComp.getReadAncParam_jp(),
| new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0,
| GridBagConstraints.CENTER, GridBagConstraints.BOTH,
| new Insets(0, 0, 5, 5), 0, 0));
| }
|
|
| //数据接收解析模块
| private void DataShow(Container contentPane) {
| showDataComp.getDataShow().setViewportView(showDataComp.getTextArea1());
| contentPane.add(showDataComp.getDataShow(),
| new GridBagConstraints(2, 0, 1, 3, 0.0, 0.0,
| GridBagConstraints.CENTER, GridBagConstraints.BOTH,
| new Insets(0, 0, 0, 0), 0, 0));
| }
|
| // 简化的标签和输入框添加方法
| private void addLabelAndField(Container panel, JComponent label, JComponent textField, int gridx, int gridy,int width) {
| panel.add(label, new GridBagConstraints(gridx, gridy, 1, 1, 0.0, 0.0,
| GridBagConstraints.CENTER, GridBagConstraints.BOTH,
| new Insets(0, 0, 5, 5), 0, 0));
| panel.add(textField, new GridBagConstraints(gridx + 1, gridy, width,1, 0.0, 0.0,
| GridBagConstraints.CENTER, GridBagConstraints.BOTH,
| new Insets(0, 0, 5, 0), 0, 0));
| }
|
| // 简化的标签和输入 按钮添加方法
| private void addLabelAndFieldAndButton(Container panel, JComponent label, JComponent textField, JComponent button,int gridx, int gridy) {
| panel.add(label, new GridBagConstraints(gridx, gridy, 1, 1, 0.0, 0.0,
| GridBagConstraints.CENTER, GridBagConstraints.BOTH,
| new Insets(0, 0, 5, 5), 0, 0));
|
| panel.add(textField, new GridBagConstraints(gridx + 1, gridy, 1, 1, 0.0, 0.0,
| GridBagConstraints.CENTER, GridBagConstraints.BOTH,
| new Insets(0, 0, 5, 0), 0, 0));
|
| panel.add(button, new GridBagConstraints(gridx + 3, gridy, 1, 1, 0.0, 0.0,
| GridBagConstraints.CENTER, GridBagConstraints.BOTH,
| new Insets(0, 0, 5, 0), 0, 0));
| }
|
| // 简化的按钮添加方法
| private void addButton(Container panel, JButton button, int gridx, int gridy, int gridwidth, int gridheight) {
| panel.add(button, new GridBagConstraints(gridx, gridy, gridwidth, gridheight, 0.0, 0.0,
| GridBagConstraints.CENTER, GridBagConstraints.BOTH,
| new Insets(0, 0, 5, 0), 0, 0));
| }
|
| // 添加 JScrollPane 的方法
| private void addScrollPane(Container panel, JScrollPane scrollPane, JTable table, int gridx, int gridy, int gridwidth, int gridheight) {
| scrollPane.setViewportView(table);
| panel.add(scrollPane, new GridBagConstraints(gridx, gridy, gridwidth, gridheight, 0.0, 0.0,
| GridBagConstraints.CENTER, GridBagConstraints.BOTH,
| new Insets(0, 0, 5, 0), 0, 0));
| }
|
| //全局页面
| private Container getPane() {
| Container contentPane = getContentPane();
| contentPane.setLayout(new GridBagLayout());
| // 设置适应窗口大小的布局
| ((GridBagLayout) contentPane.getLayout()).columnWidths = new int[]{0, 504, 374, 0}; // 可以调整宽度
| ((GridBagLayout) contentPane.getLayout()).rowHeights = new int[]{170, 268, 315, 0}; // 可以调整高度
| // 设置伸缩权重,确保内容在窗口放大时自适应
| ((GridBagLayout) contentPane.getLayout()).columnWeights = new double[]{1.0, 1.0, 1.0, 1.0E-4};
| ((GridBagLayout) contentPane.getLayout()).rowWeights = new double[]{1.0, 1.0, 1.0, 1.0E-4};
| return contentPane;
| }
|
| private void setGridBagLayoutParams(JPanel jPanel, int[] columnWidths, int[] rowHeights, double[] columnWeights, double[] rowWeights) {
| GridBagLayout layout = (GridBagLayout) jPanel.getLayout();
| layout.columnWidths = columnWidths;
| layout.rowHeights = rowHeights;
| layout.columnWeights = columnWeights;
| layout.rowWeights = rowWeights;
| }
|
| public static void startFrame(){
| SwingUtilities.invokeLater(new Runnable() {
| @Override
| public void run() {
| new GCUWBreadIndex().setVisible(true);
| }
| });
| }
| }
|
|