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

📄 新建 文本文档.txt

📁 Personal financial management system
💻 TXT
📖 第 1 页 / 共 2 页
字号:
JAVA+SQL SERVER项目开发实践
//登录类:
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import javawork.jdbc.*;
public class Login extends JFrame implements ActionListener{
 public static void main(String ary[]){
  new Login("home financial management system");
 }
 private JButton login=new JButton("登陆");
 private JButton register=new JButton("注册");
 private JButton cancel=new JButton("取消");
 private JPanel panelsouth=new JPanel(new FlowLayout(new FlowLayout().CENTER));
 private JPanel paneluser=new JPanel(new FlowLayout(new  FlowLayout().CENTER));
 private JPanel panelpassword=new JPanel(new FlowLayout(new  FlowLayout().CENTER));
 private JPanel panelcenter=new JPanel(new GridLayout(2,1));
 private JLabel user=new JLabel("用户名:  ");
 private JLabel title=new JLabel("  家庭财务管理系统");
 private JLabel password=new JLabel("密  码:  ");
 private JTextField userT=new JTextField(10);
 private JPasswordField passwordT=new JPasswordField(10);
 public Login(String title){
  super(title);
  this.setResizable(false);
  this.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e){System.exit(0);}
  });
  this.setBounds(300,250,350,250);
  frameLayout();
  addListener();
  this.setVisible(true);
 }
 public void frameLayout(){
  panelsouth.add(login);
  panelsouth.add(register);
  panelsouth.add(cancel);
  this.getContentPane().add(panelsouth,BorderLayout.SOUTH);
  paneluser.add(user);
  paneluser.add(userT);
  panelpassword.add(password);
  panelpassword.add(passwordT);
  panelcenter.add(paneluser);
  panelcenter.add(panelpassword);
  this.getContentPane().add(panelcenter,BorderLayout.CENTER);
  title.setFont(new Font("黑体",Font.BOLD,30));
  this.getContentPane().add(title,BorderLayout.NORTH);
 }
 public void addListener(){
  login.addActionListener(this);
  cancel.addActionListener(this);
  register.addActionListener(this);
  passwordT.addActionListener(this);
 }
 public void actionPerformed(ActionEvent e) {
  if(e.getSource()==login||e.getSource()==passwordT){
   String use=userT.getText();
   String pass=new String(passwordT.getPassword());
   Operate operate=new Operate();
   if(operate.login(use, pass)){
    new MainFrame(userT.getText());
    this.setVisible(false);
   }else{
    JOptionPane.showMessageDialog(this, "用户名或密码不正确");
   }
  }
  if(e.getSource()==register){
   String info="";
   String use=userT.getText();
   String pass=new String(passwordT.getPassword());
   Operate operate=new Operate();
   if(operate.register(use, pass)){
    info="注册成功";
   }else{
    info="注册失败";
   }
   JOptionPane.showMessageDialog(this, info);
  }
  if(e.getSource()==cancel){
   System.exit(0);
  }
  
 }
}
//主柜架类:
import java.awt.event.*;
import javawork.bean.SysBean;
import javawork.jdbc.*;

import javax.swing.*;
import java.awt.*;
import java.util.Vector;
public class MainFrame extends JFrame implements ActionListener{
 private boolean mode=true;
 private JTable tabel=null;
 private JPanel south=new JPanel(new FlowLayout(new FlowLayout().CENTER));
 private JPanel north=new JPanel(new FlowLayout(new FlowLayout().CENTER));
 private JLabel begin=new JLabel("从:");
 private JLabel beginyear=new JLabel("年");
 private JLabel beginmonth=new JLabel("月");
 private JLabel beginday=new JLabel("日");
 private JLabel end=new JLabel("到:");
 private JLabel endyear=new JLabel("年");
 private JLabel endmonth=new JLabel("月");
 private JLabel endday=new JLabel("日");
 private JComboBox beginyearB=new JComboBox();
 private JComboBox beginmonthB=new JComboBox();
 private JComboBox begindayB=new JComboBox();
 private JComboBox endyearB=new JComboBox();
 private JComboBox endmonthB=new JComboBox();
 private JComboBox enddayB=new JComboBox();
 private JButton add=new JButton("添加记录");
 private JButton delete=new JButton("删除记录");
 private JButton update=new JButton("更新记录");
 private JButton cancel=new JButton("退出系统");
 private JButton refresh=new JButton("刷新记录");
 private JButton select=new JButton("查询记录");
 String info[][]=null;
 private String[] field={"ID","spending","epecificSpending","income","epecificIncome","total","journal","date"};
 private String use=null;
 public MainFrame(String name){
  use=name;
  this.setTitle("home financial management system");
  this.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e){
    System.exit(0);
   }
  });
  this.setSize(700,500);
  this.setResizable(false);
  this.setLocationRelativeTo(null);
  frameLayout();
  addListener();
  this.setVisible(true);
 }

 public void editnorth(){
  for(int i=1950;i<=2050;i++){
   beginyearB.addItem(""+i);
   endyearB.addItem(""+i);
  }
  for(int i=1;i<=12;i++){
   beginmonthB.addItem(""+i);
   endmonthB.addItem(""+i);
  }
  north.add(begin);     north.add(beginyear);  north.add(beginyearB);
  north.add(beginmonth);north.add(beginmonthB);
  north.add(beginday);  north.add(begindayB);
  north.add(end);       north.add(endyear);    north.add(endyearB);
  north.add(endmonth);  north.add(endmonthB);
  north.add(endday);    north.add(enddayB);    north.add(select);
 }
 Vector<SysBean> vector=new Operate().select(use);
 public void editJTable(){
  info=new String[200][8]; 
  info[0]=new String[]{"","","","","","","",""};
  for(int i=1;i<vector.size()+1;i++){
   info[i][0]=""+vector.get(i-1).getID();
   info[i][1]=""+vector.get(i-1).getSpending();
   info[i][2]=""+vector.get(i-1).getEpecificSpending();
   info[i][3]=""+vector.get(i-1).getIncome();
   info[i][4]=""+vector.get(i-1).getEpecificIncome();
   info[i][5]=""+vector.get(i-1).getTotal();
   info[i][6]=""+vector.get(i-1).getJournal();
   info[i][7]=""+vector.get(i-1).getDate();
  }
 }
 public void frameLayout(){
  south.add(add);
  south.add(delete);
  south.add(update);
  south.add(refresh);
  south.add(cancel);
  editnorth();
  editJTable();
  tabel=new JTable(info,field);
  tabel.setAutoResizeMode(tabel.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
  this.getContentPane().add(new JScrollPane(tabel),BorderLayout.CENTER);
  this.getContentPane().add(south,BorderLayout.SOUTH);
  this.getContentPane().add(north,BorderLayout.NORTH);
 }
 public void addListener(){
  add.addActionListener(this);
  delete.addActionListener(this);
  update.addActionListener(this);
  cancel.addActionListener(this);
  refresh.addActionListener(this);
  select.addActionListener(this);
  beginmonthB.addActionListener(this);
  beginyearB.addActionListener(this);
  endyearB.addActionListener(this);
  endmonthB.addActionListener(this);
 }
 public void removeB(){
  beginyearB.removeAll();
  beginmonthB.removeAll();
  begindayB.removeAll();
  endyearB.removeAll();
  endmonthB.removeAll();
  enddayB.removeAll();
 }
 public void removeListener(){
  add.removeActionListener(this);
  delete.removeActionListener(this);
  update.removeActionListener(this);
  cancel.removeActionListener(this);
  refresh.removeActionListener(this);
  select.removeActionListener(this);
  beginmonthB.removeActionListener(this);
  endmonthB.removeActionListener(this);
  beginyearB.removeActionListener(this);
  endyearB.removeActionListener(this);
  
 }
 public void actionPerformed(ActionEvent e) {
  if(e.getSource()==add){
   addSource();
  }if(e.getSource()==delete){
   deleteSource();
  }if(e.getSource()==update){
   updateSource();
  }if(e.getSource()==select){
   selectSource();
  }if(e.getSource()==cancel){
   System.exit(0);
  }if(e.getSource()==refresh){
   refreshSource();
  }if(e.getSource()==beginmonthB||e.getSource()==beginyearB){
   beginmonthBSource();
  }if(e.getSource()==endmonthB||e.getSource()==endyearB){
   endmonthBSource();
  }
 }
 public void refreshSource(){
  //beginyearB.removeAll();
  //beginmonthB.removeAll();
  //endyearB.removeAll();
  //endmonthB.removeAll();
  frameLayout();
  this.setVisible(true);
 }
 public void deleteSource(){
  String info="";
  try{
   int ID=Integer.parseInt(((String)tabel.getValueAt(0, 0)).trim());
   if(new Operate().delete(ID, use)){
    info="删除成功";
   }else{
    info="删除失败";
   }
  }catch(Exception e){
   info="请正确输入数据";
  }
  JOptionPane.showMessageDialog(this,info);
 }
 public void selectSource(){
  String byear=(String)beginyearB.getSelectedItem();
  String bmonth=(String)beginmonthB.getSelectedItem();
  String bday=(String)begindayB.getSelectedItem();
  String eyear=(String)endyearB.getSelectedItem();
  String emonth=(String)endmonthB.getSelectedItem();
  String eday=(String)enddayB.getSelectedItem();
  if("".equals(bday)){
   bday="01";
  }if("".equals(eday)){
   eday="01";
  }
  String beginDate=byear+"-"+bmonth+"-"+bday;
  String endDate=eyear+"-"+emonth+"-"+eday;
  vector=new Operate().selectDay(use, java.sql.Date.valueOf(beginDate), java.sql.Date.valueOf(endDate));
  refreshSource();
 }
 public void beginmonthBSource(){
  int byear=Integer.parseInt((String)beginyearB.getSelectedItem());
  int bmonth=Integer.parseInt((String)beginmonthB.getSelectedItem());
  removeB();
  boolean yn=false;
  if((byear%4==0&&byear%100!=0)||(byear%100==0&&byear%400==0)){
   yn=true;
  }
  for(int i=1;i<=31;i++){
   if(bmonth==2){
    if(yn){
     if(i<=28){
      begindayB.addItem(""+i);
     }
    }else{
     if(i<=29){
      begindayB.addItem(""+i);
     }
    }
   }else{
    if(bmonth==1||bmonth==3||bmonth==5||bmonth==7||bmonth==8||bmonth==10||bmonth==12){
     begindayB.addItem(""+i);
    }else{
     if(i<=30){
      begindayB.addItem(""+i);
     }
    }
   }
  }
 }
 public void endmonthBSource(){
  int eyear=Integer.parseInt((String)endyearB.getSelectedItem());
  int emonth=Integer.parseInt((String)endmonthB.getSelectedItem());
  boolean yn=false;
  removeB();
  if((eyear%4==0&&eyear%100!=0)||(eyear%100==0&&eyear%400==0)){
   yn=true;
  }
  for(int i=1;i<=31;i++){
   if(emonth==2){
    if(yn){
     if(i<=28){
      enddayB.addItem(""+i);
     }
    }
   }else{
    if(emonth==1||emonth==3||emonth==5||emonth==7||emonth==8||emonth==10||emonth==12){
     enddayB.addItem(""+i);
    }else{
     if(i<=30){
      enddayB.addItem(""+i);
     }
    }
   }
  }
  System.out.print("haah");
 }
 public void updateSource(){

⌨️ 快捷键说明

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