验证中...
码云账号不再使用社区账号进行二次身份验证的通知 详情
私信发送成功
语言: Java
最后更新于 2017-07-27 18:33
AddTemperaFrame.java
原始数据 复制代码
/*
* ListTempera.java
*
* Created on __DATE__, __TIME__
*/
package com.ruif.view;
import java.sql.Connection;
import javax.swing.JOptionPane;
import com.ruif.dao.TemperaDAO;
import com.ruif.model.Tempera;
import com.ruif.util.DBUtil;
import com.ruif.util.StringUtil;
/**
*
* @author __USER__
*/
public class AddTemperaFrame extends javax.swing.JInternalFrame
{
DBUtil dbUtil = new DBUtil();
TemperaDAO temDao = new TemperaDAO();
private static final long serialVersionUID = -1336761306424610231L;
/** Creates new form ListTempera */
public AddTemperaFrame() {
initComponents();
this.setLocation(200, 50);
}
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents()
{
jLabel1 = new javax.swing.JLabel();
jTextField_temp = new javax.swing.JTextField();
jButton_add = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jComboBox_status = new javax.swing.JComboBox();
jButton_reset = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
setTitle("\u65b0\u589e\u6e29\u5ea6\u8bb0\u5f55");
jLabel1.setText("\u6e29 \u5ea6\uff1a");
jButton_add.setIcon(new javax.swing.ImageIcon(
"C:\\Documents and Settings\\pc\\桌面\\Images\\add.png")); // NOI18N
jButton_add.setText("\u65b0\u589e");
jButton_add.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton_addActionPerformed(evt);
}
});
jLabel2.setText("\u72b6 \u6001\uff1a");
jComboBox_status.setModel(new javax.swing.DefaultComboBoxModel(
new String[] { "正常", "报警" }));
jButton_reset.setIcon(new javax.swing.ImageIcon(
"C:\\Documents and Settings\\pc\\桌面\\Images\\reset.png")); // NOI18N
jButton_reset.setText("\u91cd\u7f6e");
jButton_reset.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton_resetActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addContainerGap(50, Short.MAX_VALUE)
.addGroup(
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(
layout.createSequentialGroup()
.addComponent(
jButton_add)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(
jButton_reset,
javax.swing.GroupLayout.PREFERRED_SIZE,
81,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(
layout.createSequentialGroup()
.addGroup(
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jLabel1)
.addComponent(
jLabel2))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
false)
.addComponent(
jComboBox_status,
javax.swing.GroupLayout.Alignment.LEADING,
0,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(
jTextField_temp,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.PREFERRED_SIZE,
155,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(54, 54, 54)));
layout.setVerticalGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout.createSequentialGroup()
.addGap(27, 27, 27)
.addGroup(
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(
jTextField_temp,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(
jComboBox_status,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
39, Short.MAX_VALUE)
.addGroup(
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton_add)
.addComponent(
jButton_reset,
javax.swing.GroupLayout.PREFERRED_SIZE,
24,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(37, 37, 37)));
pack();
}// </editor-fold>
//GEN-END:initComponents
private void jButton_resetActionPerformed(java.awt.event.ActionEvent evt)
{
resetValue();
}
private void jButton_addActionPerformed(java.awt.event.ActionEvent evt)
{
String temp = this.jTextField_temp.getText().trim();
String status = (String) this.jComboBox_status.getSelectedItem();
if (StringUtil.isEmpty(temp))
{
JOptionPane.showMessageDialog(null, "请输入温度!");
return;
}
Tempera tem = new Tempera(Integer.parseInt(temp),
"正常".equals(status) ? 0 : 1);
Connection conn = null;
try
{
conn = dbUtil.getConn();
int ok = temDao.addTempera(conn, tem);
if (ok == 1)
{
JOptionPane.showMessageDialog(null, "新增成功!");
resetValue();
}
else
{
JOptionPane.showMessageDialog(null, "新增失败!");
}
}
catch (Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null, "新增失败!");
}
finally
{
try
{
dbUtil.closeConn(conn);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
/**
* 重置事件处理
*/
public void resetValue()
{
this.jTextField_temp.setText("");
this.jComboBox_status.setSelectedItem("正常");
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton_add;
private javax.swing.JButton jButton_reset;
private javax.swing.JComboBox jComboBox_status;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField jTextField_temp;
// End of variables declaration//GEN-END:variables
}

评论列表( 0 )

你可以在登录后,对此项目发表评论

2_float_left_people 2_float_left_close