📄 addcoursejpanel.java
字号:
/*
* AddCourseJPanel.java
*
* Created on 2007年12月13日, 下午2:08
*/
package 考试成绩分析程序;
import javax.swing.*;
/**
*
* @author drawen
*/
public class AddCourseJPanel extends javax.swing.JPanel {
/** Creates new form AddCourseJPanel */
public AddCourseJPanel() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
courseId = new javax.swing.JTextField();
courseName = new javax.swing.JTextField();
courseCredit = new javax.swing.JTextField();
coursePeriod = new javax.swing.JTextField();
confirm = new javax.swing.JButton();
reset = new javax.swing.JButton();
jLabel5 = new javax.swing.JLabel();
jLabel1.setText("\u8bfe\u7a0b\u7f16\u53f7\uff1a");
jLabel2.setText("\u8bfe\u7a0b\u540d\u79f0\uff1a");
jLabel3.setText("\u8bfe\u7a0b\u5b66\u5206\uff1a");
jLabel4.setText("\u8bfe\u7a0b\u5b66\u65f6\uff1a");
courseId.setText("1001");
courseName.setText("\u9762\u5411\u5bf9\u8c61\u6280\u672f\u8bbe\u8ba1");
courseCredit.setText("2.5");
coursePeriod.setText("60");
confirm.setText("\u786e\u5b9a");
confirm.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
confirmButtonActionListener(evt);
}
});
reset.setText("\u91cd\u7f6e");
jLabel5.setText("\u589e\u52a0\u8bfe\u7a0b\u4fe1\u606f");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(31, 31, 31)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
.add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jLabel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(43, 43, 43)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(courseName)
.add(coursePeriod)
.add(courseCredit)
.add(courseId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 122, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(layout.createSequentialGroup()
.add(77, 77, 77)
.add(confirm)
.add(57, 57, 57)
.add(reset))
.add(layout.createSequentialGroup()
.add(118, 118, 118)
.add(jLabel5)))
.addContainerGap(110, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(19, 19, 19)
.add(jLabel5)
.add(19, 19, 19)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(courseId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(39, 39, 39)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(courseName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(30, 30, 30)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel3)
.add(courseCredit, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(23, 23, 23)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel4)
.add(coursePeriod, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(22, 22, 22)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(confirm)
.add(reset))
.addContainerGap(30, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void confirmButtonActionListener(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmButtonActionListener
String id,name;
float credit;
int period;
try{
id=courseId.getText();
name=courseName.getText();
credit=Float.parseFloat(courseCredit.getText());
period=Integer.parseInt(coursePeriod.getText());
if((credit<=0)||(period<=0))
JOptionPane.showMessageDialog(null,"输入数据范围有误!",
"警告",JOptionPane.ERROR_MESSAGE);
else{
course=new Course(id,name,credit,period);
if(course.saveToFile())
JOptionPane.showMessageDialog(null,"已经成功增加课程信息!",
"增加成功",JOptionPane.WARNING_MESSAGE);
else
JOptionPane.showMessageDialog(null,"课程信息已经存在,或课程编号重复!",
"增加失败",JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
JOptionPane.showMessageDialog(null,"输入数据格式有误!",
"警告",JOptionPane.ERROR_MESSAGE);
}
}//GEN-LAST:event_confirmButtonActionListener
private Course course;
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JButton confirm;
private javax.swing.JTextField courseCredit;
private javax.swing.JTextField courseId;
private javax.swing.JTextField courseName;
private javax.swing.JTextField coursePeriod;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JButton reset;
// 变量声明结束//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -