📄 trainfo.java
字号:
package employee;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
/**
* 培训信息综合管理类
* 提供主界面,供其他类继承
*/
public class TraInfo extends JFrame implements ActionListener{
Container contentPane;
JPanel centerPanel = new JPanel();
JPanel upPanel = new JPanel();
JPanel downPanel = new JPanel();
//框架的大小
Dimension faceSize = new Dimension(800, 500);
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JTextField tTid = new JTextField(15);
JTextField tName = new JTextField(15);
JTextField tContent = new JTextField(15);
JButton searchInfo = new JButton();
JButton addInfo = new JButton();
JButton modifyInfo = new JButton();
JButton deleteInfo = new JButton();
JButton clearInfo = new JButton();
JButton saveInfo = new JButton();
JButton eixtInfo = new JButton();
GridBagLayout girdBag = new GridBagLayout();
GridBagConstraints girdBagCon;
public TraInfo() {this.setSize(faceSize);
//设置标题
this.setTitle("培训综合信息管理");
this.setResizable(false);
//设置程序图标
this.setIconImage(getImage("icon.gif"));
try {
Init();
}
catch(Exception e) {
e.printStackTrace();
}
}
public void Init() throws Exception {
contentPane = this.getContentPane();
contentPane.setLayout(new BorderLayout());
//中部面板的布局
centerPanel.setLayout(girdBag);
jLabel1.setText("培训编码:");
jLabel1.setFont(new Font("Dialog",0,12));
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 0;
girdBagCon.gridy = 0;
girdBagCon.insets = new Insets(10,10,10,1);
girdBag.setConstraints(jLabel1,girdBagCon);
centerPanel.add(jLabel1);
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 1;
girdBagCon.gridy = 0;
girdBagCon.insets = new Insets(10,1,10,15);
girdBag.setConstraints(tTid,girdBagCon);
centerPanel.add(tTid);
jLabel2.setText("培训名称:");
jLabel2.setFont(new Font("Dialog",0,12));
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 2;
girdBagCon.gridy = 0;
girdBagCon.insets = new Insets(10,15,10,1);
girdBag.setConstraints(jLabel2,girdBagCon);
centerPanel.add(jLabel2);
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 3;
girdBagCon.gridy = 0;
girdBagCon.insets = new Insets(10,1,10,10);
girdBag.setConstraints(tName,girdBagCon);
centerPanel.add(tName);
jLabel3.setText("培训内容:");
jLabel3.setFont(new Font("Dialog",0,12));
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 0;
girdBagCon.gridy = 1;
girdBagCon.insets = new Insets(10,10,10,1);
girdBag.setConstraints(jLabel3,girdBagCon);
centerPanel.add(jLabel3);
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 1;
girdBagCon.gridy = 1;
girdBagCon.insets = new Insets(10,1,10,15);
girdBag.setConstraints(tContent,girdBagCon);
centerPanel.add(tContent);
contentPane.add(centerPanel,BorderLayout.CENTER);
}
/**
* 下部面板的布局
*/
public void downInit(){
searchInfo.setText("查询");
searchInfo.setFont(new Font("Dialog",0,12));
downPanel.add(searchInfo);
addInfo.setText("增加");
addInfo.setFont(new Font("Dialog",0,12));
downPanel.add(addInfo);
modifyInfo.setText("修改");
modifyInfo.setFont(new Font("Dialog",0,12));
downPanel.add(modifyInfo);
deleteInfo.setText("删除");
deleteInfo.setFont(new Font("Dialog",0,12));
downPanel.add(deleteInfo);
saveInfo.setText("保存");
saveInfo.setFont(new Font("Dialog",0,12));
downPanel.add(saveInfo);
clearInfo.setText("清空");
clearInfo.setFont(new Font("Dialog",0,12));
downPanel.add(clearInfo);
eixtInfo.setText("退出");
eixtInfo.setFont(new Font("Dialog",0,12));
downPanel.add(eixtInfo);
contentPane.add(downPanel,BorderLayout.SOUTH);
//添加事件侦听
searchInfo.addActionListener(this);
addInfo.addActionListener(this);
modifyInfo.addActionListener(this);
deleteInfo.addActionListener(this);
saveInfo.addActionListener(this);
clearInfo.addActionListener(this);
eixtInfo.addActionListener(this);
}
/**
* 事件处理
*/
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if (obj == searchInfo) { //查询
}
else if (obj == addInfo) { //增加
}
else if (obj == modifyInfo) { //修改
}
else if (obj == deleteInfo) { //删除
}
else if (obj == saveInfo) { //保存
}
else if (obj == clearInfo) { //清空
}
else if (obj == eixtInfo) { //退出
this.dispose();
}
}
/**
* 将文本框清空
*/
void setNull(){
tTid.setText(null);
tName.setText(null);
tContent.setText(null);
}
/**
* 通过给定的文件名获得图像
*/
Image getImage(String filename) {
URLClassLoader urlLoader = (URLClassLoader)this.getClass().
getClassLoader();
URL url = null;
Image image = null;
url = urlLoader.findResource(filename);
image = Toolkit.getDefaultToolkit().getImage(url);
MediaTracker mediatracker = new MediaTracker(this);
try {
mediatracker.addImage(image, 0);
mediatracker.waitForID(0);
}
catch (InterruptedException _ex) {
image = null;
}
if (mediatracker.isErrorID(0)) {
image = null;
}
return image;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -