发现
swing
中对控件的布局很麻烦,要想整个好看的界面确实是件烦人的事情,我做了一个简单的界面,代码如下:
package
gui;
import
java.awt.BorderLayout;
import
java.awt.GridLayout;
import
javax.swing.JButton;
import
javax.swing.JFrame;
import
javax.swing.JLabel;
import
javax.swing.JPanel;
import
javax.swing.JTextField;
import
javax.swing.JToolBar;
public
class
UserGui
extends
JFrame {
static
final
long
serialVersionUID
=
1
;
JPanel infBar;
JButton[] button
=
new
JButton[
6
];
JToolBar tb;
//
----------
JLabel idL
=
new
JLabel(
"
工号:
"
);
JLabel nameL
=
new
JLabel(
"
姓名:
"
);
JLabel moneyL
=
new
JLabel(
"
学历:
"
);
JLabel workL
=
new
JLabel(
"
职称:
"
);
JTextField idT
=
new
JTextField(
22
);
JTextField nameT
=
new
JTextField(
22
);
JTextField moneyT
=
new
JTextField(
22
);
JTextField workT
=
new
JTextField(
22
);
//
--------------------------------
public
UserGui(String name) {
super
(name);
setLayout(
new
BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(
290
,
200
);
setResizable(
false
);
setToolBar();
setInfBar();
add(infBar, BorderLayout.CENTER);
add(tb, BorderLayout.NORTH);
setVisible(
true
);
}
//
--------------------------------
public
void
setToolBar() {
tb
=
new
JToolBar();
tb.setFloatable(
false
);
String[] t1
=
{
"
查询
"
,
"
添加
"
,
"
修改
"
,
"
删除
"
,
"
应用更改
"
,
"
退出系统
"
};
for
(
int
i
=
0
; i
<
6
; i
++
) {
button[i]
=
new
JButton(t1[i]);
tb.add(button[i]);
}
}
public
void
setInfBar() {
infBar
=
new
JPanel();
infBar.setLayout(
new
BorderLayout());
JPanel left
=
new
JPanel();
left.setLayout(
new
GridLayout(
4
,
1
));
JPanel right
=
new
JPanel();
right.setLayout(
new
GridLayout(
4
,
1
));
infBar.add(left, BorderLayout.WEST);
infBar.add(right, BorderLayout.EAST);
left.add(idL);
left.add(nameL);
left.add(moneyL);
left.add(workL);
right.add(idT);
right.add(nameT);
right.add(moneyT);
right.add(workT);
}
//
--------------------------------
public
static
void
main(String[] args) {
UserGui ug
=
new
UserGui(
"
人事档案管理系统界面
"
);
}
}