📄 addcourseframe.java
字号:
package edu.xscj.business;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import edu.xscj.bean.*;
import edu.xscj.action.*;
public class addCourseFrame extends JFrame {
public addCourseFrame() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(xYLayout1);
lbCourseNo.setText("课程编号");
lbCourseName.setText("课程名");
lbXuefen.setText("学分");
btnSubmit.setText("确认");
btnSubmit.addActionListener(new addCourseFrame_btnSubmit_actionAdapter(this));
btnReset.setText("重填");
for (int i = 1; i < 20; i++) {
boxXuefen.addItem(Integer.toString(i));
}
this.getContentPane().add(lbCourseNo, new XYConstraints(75, 35, 53, 24));
this.getContentPane().add(lbCourseName,
new XYConstraints(81, 90, -1, -1));
this.getContentPane().add(txtCourseNo,
new XYConstraints(159, 35, 115, 25));
this.getContentPane().add(txtCourseName,
new XYConstraints(159, 85, 115, 24));
this.getContentPane().add(lbXuefen, new XYConstraints(87, 139, -1, -1));
this.getContentPane().add(btnSubmit, new XYConstraints(99, 208, 63, 26));
this.getContentPane().add(btnReset, new XYConstraints(211, 209, -1, -1));
this.getContentPane().add(boxXuefen,
new XYConstraints(159, 135, 75, 22));
this.setSize(380, 280);
this.setResizable(false);
this.setTitle("添加课程信息");
}
XYLayout xYLayout1 = new XYLayout();
JLabel lbCourseNo = new JLabel();
JTextField txtCourseNo = new JTextField();
JLabel lbCourseName = new JLabel();
JTextField txtCourseName = new JTextField();
JLabel lbXuefen = new JLabel();
JButton btnSubmit = new JButton();
JButton btnReset = new JButton();
JComboBox boxXuefen = new JComboBox();
public void btnSubmit_actionPerformed(ActionEvent e) {
String courseNo = txtCourseNo.getText();
String courseName = txtCourseName.getText();
String xuefen = (String) boxXuefen.getSelectedItem();
if (courseNo.equals("") || courseName.equals("")) {
JOptionPane.showMessageDialog(this, "课程编号和课程名不能为空!", "温心提示",
JOptionPane.
INFORMATION_MESSAGE);
return;
}
Course course = new Course();
course.setCourNo(courseNo);
course.setCourName(courseName);
course.setCourXuefen(Integer.parseInt(xuefen));
AddCourseAction addCourse = new AddCourseAction();
String str = addCourse.addCourse(course);
if (str.equals("sucess")) {
JOptionPane.showMessageDialog(this, "添加课程成功!", "温心提示",
JOptionPane.
INFORMATION_MESSAGE);
} else if (str.equals("failer")) {
JOptionPane.showMessageDialog(this, "添加课程失败!!", "温心提示",
JOptionPane.
INFORMATION_MESSAGE);
}
}
}
class addCourseFrame_btnSubmit_actionAdapter implements ActionListener {
private addCourseFrame adaptee;
addCourseFrame_btnSubmit_actionAdapter(addCourseFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnSubmit_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -