📄 setrate.java
字号:
/*
* SetRate.java
*
* Created on 2007年1月22日, 下午4:12
*/
package javaapplication1;
import java.awt.Toolkit;
import java.sql.*;
/**
*
* @author zengzz
*/
public class SetRate extends javax.swing.JFrame {
/** Creates new form SetRate */
public SetRate() {
connectDB();
initComponents();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
//-------设置窗口位置居中---------------------------------------------------------------
int locationX=(int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth()-getSize().getWidth())/2;
int locationY=(int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight()-getSize().getHeight())/2;
setLocation(locationX,locationY);
//--------------------------------------------------------------------------------------
}
/** 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();
typeComboBox = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
rateField = new javax.swing.JTextField();
confirmButton = new javax.swing.JButton();
resetButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("\u8bbe\u7f6e\u5229\u7387");
typeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "\u6d3b\u671f", "\u5b9a\u671f1\u5e74", "\u5b9a\u671f3\u5e74", "\u5b9a\u671f5\u5e74", "\u5b9a\u671f10\u5e74" }));
jLabel2.setText("\u5b58\u6b3e\u7c7b\u578b");
confirmButton.setText("\u786e\u5b9a");
confirmButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
confirmButtonActionPerformed(evt);
}
});
resetButton.setText("\u91cd\u7f6e");
resetButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resetButtonActionPerformed(evt);
}
});
cancelButton.setText("\u53d6\u6d88");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
jLabel3.setText("\u5229\u7387");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().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(19, 19, 19)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(confirmButton)
.add(jLabel3)
.add(jLabel2))
.add(0, 0, 0)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(6, 6, 6)
.add(resetButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(cancelButton))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(typeComboBox, 0, 126, Short.MAX_VALUE)
.add(rateField))))
.add(layout.createSequentialGroup()
.add(88, 88, 88)
.add(jLabel1)))
.addContainerGap(25, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1)
.add(26, 26, 26)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(typeComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel3)
.add(rateField, 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.BASELINE)
.add(confirmButton)
.add(cancelButton)
.add(resetButton))
.addContainerGap(28, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
// TODO 将在此处添加您的处理代码:
this.dispose();
try
{
setRate.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}//GEN-LAST:event_cancelButtonActionPerformed
private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
// TODO 将在此处添加您的处理代码:
typeComboBox.setSelectedIndex(0);
rateField.setText("");
}//GEN-LAST:event_resetButtonActionPerformed
private void confirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmButtonActionPerformed
// TODO 将在此处添加您的处理代码:
int limitTime = 0;
switch(typeComboBox.getSelectedIndex())
{
case 0:
{
limitTime = 0;
break;
}
case 1:
{
limitTime = 1;
break;
}
case 2:
{
limitTime = 3;
break;
}
case 3:
{
limitTime = 5;
break;
}
case 4:
{
limitTime = 10;
break;
}
}
float rate = Float.parseFloat(rateField.getText());
CallableStatement proc = null;
try
{
proc = setRate.prepareCall("{ call ChangeRate(?,?) }");
proc.setInt(1, limitTime);
proc.setFloat(2,rate);
proc.execute();
}
catch(Exception alterStaffException)
{
alterStaffException.printStackTrace();
}
finally
{
try
{
proc.close();
setRate.close();
}
catch(Exception closeAlterStaffException)
{
closeAlterStaffException.printStackTrace();
}
}
dispose();
}//GEN-LAST:event_confirmButtonActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SetRate().setVisible(true);
}
});
}
//连接数据库操作------------------------------
public void connectDB()
{
String dbUrl = "jdbc:odbc:afei";
String user = "scott";
String password = "tiger";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
setRate = DriverManager.getConnection(dbUrl,user,password);
}
catch(Exception connectException)
{
connectException.printStackTrace();
}
}
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JButton confirmButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField rateField;
private javax.swing.JButton resetButton;
private javax.swing.JComboBox typeComboBox;
// 变量声明结束//GEN-END:variables
private Connection setRate = null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -