⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccdm_add_mod.java

📁 一個學校的教学综合管理系统,包含了很多的功能。
💻 JAVA
字号:
package basecode.ccdm;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import com.zdsoft.gui.*;
import com.zdsoft.util.*;
//import util.*;
//import basedata.*;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */

public class CCDM_add_mod extends ASDialog
{
  private CCDM_list CMF;
  private String oper;
  int idCMF;
  private JPanel jPanel1 = new JPanel();
  private JPanel jPanel2 = new JPanel();
  private BorderLayout borderLayout1 = new BorderLayout();
  private JPanel jPanel3 = new JPanel();
  private JPanel jPanel4 = new JPanel();
  private JPanel jPanel5 = new JPanel();
  private GridBagLayout gridBagLayout1 = new GridBagLayout();
  private JLabel jLabel2 = new JLabel();
  private JTextField name = new JTextField();
  private JPanel jPanel6 = new JPanel();
  private FlowLayout flowLayout1 = new FlowLayout();
  private JButton saveButton = new JButton();
  private JButton cancelButton = new JButton();
  private JPanel jPanel7 = new JPanel();
  private JPanel jPanel8 = new JPanel();

  public CCDM_add_mod(CCDM_list cmf,String oper)
  {
    //传入父窗体,即可引用其中的各public成员
    this.CMF = cmf;
    //传入增加或修改标记
    this.oper = oper;
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception
  {
    this.setSize(new Dimension(394, 184));
    if (oper.equals("add"))
      this.setTitle("增加信息");
    else
      this.setTitle("修改信息");
    init();
    this.getContentPane().setLayout(borderLayout1);
    jPanel1.setBorder(BorderFactory.createEtchedBorder());
    jPanel1.setLayout(gridBagLayout1);
    jLabel2.setFont(new java.awt.Font("Dialog", 0, 13));
    jLabel2.setText("学习层次名称:");
    name.setFont(new java.awt.Font("Dialog", 0, 13));
    name.setPreferredSize(new Dimension(200, 25));
    jPanel6.setLayout(flowLayout1);
    saveButton.setFont(new java.awt.Font("Dialog", 0, 13));
    saveButton.setText("保  存");
    saveButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        saveButton_actionPerformed(e);
      }
    });
    cancelButton.setFont(new java.awt.Font("Dialog", 0, 13));
    cancelButton.setText("取  消");
    cancelButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        cancelButton_actionPerformed(e);
      }
    });
    jPanel8.setBorder(BorderFactory.createEtchedBorder());
    this.getContentPane().add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jLabel2,            new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0));
    jPanel1.add(name,            new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0));
    jPanel1.add(jPanel6,            new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0));
    jPanel6.add(jPanel8, null);
    jPanel8.add(saveButton, null);
    jPanel8.add(cancelButton, null);
    jPanel1.add(jPanel7,     new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    this.getContentPane().add(jPanel2, BorderLayout.SOUTH);
    this.getContentPane().add(jPanel3, BorderLayout.WEST);
    this.getContentPane().add(jPanel4, BorderLayout.EAST);
    this.getContentPane().add(jPanel5, BorderLayout.NORTH);
    setWindowCenter();////将本对话框居中
  }
  void init()
  {
    try
    {
      if(oper.equals("mod"))
      {
        int row = CMF.jTable1.getSelectedRow();//得到父窗体中表格的选中行行号,从0开始
        name.setText(CMF.ds.getItemString(row,"cc_name"));
      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e)
  {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING)
    {
      this.dispose();
    }
  }

  void cancelButton_actionPerformed(ActionEvent e)
  {
     this.dispose();
  }

  void saveButton_actionPerformed(ActionEvent e)
{
    if (name.getText().trim().equals(""))
      JOptionPane.showMessageDialog(this,"请输入学习层次名称!","输入错误",JOptionPane.ERROR_MESSAGE);
  else
  {
    try
    {
      String msg[]={"",""};
      //构造Object数组,将相应信息传递到后台方法
      Object[] obj  = new Object[6];

      obj[1] = name.getText().trim();
      OperData od = new OperData();

      if (oper.equals("add"))
      {
        msg = od.addKc_info(obj);//后台方法调用,返回值为数组
        if (msg[0].equals("false"))//调用方法失败
          JOptionPane.showMessageDialog(this,"操作失败!","",JOptionPane.ERROR_MESSAGE);
        else{
          //调用方法成功(数据库操作成功),将新增加的信息添加到表格中显示
          int row = CMF.ds.addRow();//ASDatastore对象增加一行,返回增加行的行号

          //设置相应行号,相应列的ASDatastore对象值
          CMF.ds.setObjectAt(row,"cc_id",new Integer(msg[1]));
          CMF.ds.setObjectAt(row,"cc_name",name.getText().trim());
          //通知相应表格视图,其数据源已发生改变
          CMF.jTable1.ASTableRepant();
          this.dispose();//关闭本对话框
        }
      }
      else{
        int row = CMF.jTable1.getSelectedRow();//得到ASTable对象的选中行行号
        obj[0] = CMF.ds.getItemInteger(row,"cc_id");
        msg = od.modKc_info(obj);
        if (msg[0].equals("false"))
          JOptionPane.showMessageDialog(this,"操作失败!","",JOptionPane.ERROR_MESSAGE);
        else{
          //调用方法成功(数据库操作成功),将ds相应行信息修改并显示

          //设置相应行号,相应列的ASDatastore对象值
          CMF.ds.setObjectAt(row,"cc_name",name.getText().trim());
          //通知相应表格视图,其数据源已发生改变
          CMF.jTable1.ASTableRepant();
          this.dispose();
        }
      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -