?? money.java
字號(hào):
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.redingsoft.checkout;import com.redingsoft.locationutil.LocationUtil;import com.redingsoft.sql.SetSQL;import com.test.Counter;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import java.sql.SQLException;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.*;import javax.swing.table.DefaultTableModel;/** * * @author Administrator */public class money extends JDialog implements ActionListener{ //聲明一個(gè)面板 JPanel jp1; //聲明一個(gè)標(biāo)簽 JLabel jl1,jl2; JButton bt1,bt2; JTable tb1; JScrollPane sp; DefaultTableModel dftm1; //時(shí)、聲明數(shù)組出示阿華表模式 String cols[]={"結(jié)算單號(hào)","入住時(shí)間","入住天數(shù)","實(shí)際收入","結(jié)算時(shí)間"}; String rows[][]=new String [30][5]; String sql=null; //構(gòu)造方法 public money (){ //實(shí)例化 jl1=new JLabel("營(yíng)業(yè)額:"); jl2=new JLabel("營(yíng)業(yè)額"); bt1=new JButton("總營(yíng)業(yè)額"); bt2=new JButton("更新"); bt1.setContentAreaFilled(false); bt2.setContentAreaFilled(false); jp1=new JPanel(); //是理化化表格 dftm1=new DefaultTableModel(){ @Override public boolean isCellEditable(int row, int column) { return false; } } ; tb1=new JTable(); dftm1.setDataVector(rows, cols); sql="select chk_no 結(jié)算單號(hào),in_no 入住時(shí)間,days 入住天數(shù),money 實(shí)際收入,chk_time 結(jié)算時(shí)間 from checkout where delmark=0"; initTabel(sql); tb1.setModel(dftm1); sp=new JScrollPane(tb1); jp1.add(jl1); jp1.add(jl2); jp1.add(bt1); jp1.add(bt2); //修飾面板 jp1.setBackground(Color.CYAN); sp.setPreferredSize(new Dimension(300,300)); //添加偵聽 bt1.addActionListener(this); bt2.addActionListener(this); //添加到主窗口 this.add(BorderLayout.NORTH,sp); this.add(BorderLayout.SOUTH,jp1); this.setDefaultCloseOperation(money.DISPOSE_ON_CLOSE); this.setTitle("查詢營(yíng)業(yè)額"); this.setSize(500, 380); LocationUtil.setLocation(this); } /**** public static void main(String []aa){ new money(); } * ****************************/ public void initTabel(String sql){ //設(shè)置表格的模式 //初始化表表模式 SetSQL.initDTM(dftm1,sql); if(dftm1.getRowCount()!=0){ tb1.setModel(dftm1); // tb=new JTable(); }else{ WarnMsg("提示","還沒有營(yíng)業(yè)額的信息!"); }} /******************************************************* * 函數(shù)名稱:WarnMsgPane(String title ,String msg ,component null) * 參數(shù):tile 提示標(biāo)題 msg 提示消息 顯示他的父組件 * 功能:為錯(cuò)誤的輸入和連接錯(cuò)誤做出提示 ************************************************************/ public static void WarnMsg(String title,String msg){ JOptionPane.showMessageDialog(null,msg,title,JOptionPane.WARNING_MESSAGE); } public void actionPerformed(ActionEvent e) { // throw new UnsupportedOperationException("Not supported yet."); Object o=e.getSource(); if(o==bt1){ try { String sel = "select sum(money) from checkout where delmark=0"; ResultSet rs = SetSQL.executeQuery(sel); rs.next(); String money=String.valueOf(rs.getFloat(1)); jl2.setForeground(Color.BLUE); jl2.setText(money); // System.out.print(money); } catch (SQLException ex) { // Logger.getLogger(money.class.getName()).log(Level.SEVERE, null, ex); } }//end if(o==bt1) if(o==bt2){ //更新 initTabel(sql); } } }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -