基于java+mysql的swing+mysql物业收费系统(java+gui)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于java+mysql的Swing+MySQL物业收费系统(java+gui)
功能介绍:
用户登陆、用户注册、收费记录、生成业单、用户管理、查询缴费、历史账单、资料设置
setResizable(false);
initHeadPane();
add(initJTabbedPane());
new UserListener(this);
setVisible(true);
}
public void initHeadPane() {
headPanel=new JPanel(null);
headPanel.setBounds(0, 0, 900, 60);
headPanel.setBackground(Color.white);
miniBtn=new JButton();
closeBtn=new JButton();
miniBtn.setBounds(786,5,50,50);
closeBtn.setBounds(845,5,50,50);
miniBtn.setFocusPainted(false);
closeBtn.setFocusPainted(false);
miniBtn.setBorder(null);
closeBtn.setBorder(null);
miniBtn.setBackground(null);
closeBtn.setBackground(null);
miniBtn.setIcon(new ImageIcon("mstUI_img/mini2.png"));
miniBtn.setRolloverIcon(new ImageIcon("mstUI_img/mini1.png"));
miniBtn.setPressedIcon(new ImageIcon("mstUI_img/mini3.png"));
closeBtn.setIcon(new ImageIcon("mstUI_img/close2.png"));
closeBtn.setRolloverIcon(new ImageIcon("mstUI_img/close1.png"));
closeBtn.setPressedIcon(new ImageIcon("mstUI_img/close3.png"));
headPanel.add(miniBtn);
headPanel.add(closeBtn);
JLabel showWhoJLabel=new JLabel();
showWhoJLabel.setBounds(20, 0, 600, 60);
showWhoJLabel.setFont(new Font("微软雅黑",Font.BOLD,20));
String textString="物业收费系统-居民模式 Hi! "+user.getName()+" ,今天是"+getDateStr();
//String textString="物业收费系统-居民模式 Hi! "+" ,今天是"+getDateStr();
showWhoJLabel.setText(textString);
headPanel.add(showWhoJLabel);
add(headPanel);
}
jPanel04.setBounds(0,200,this.getWidth(),50);
this.add(jPanel04);
// 学历+下拉列表
jPanel05=new JPanel(null);
jPanel05.setBackground(color);
JLabel jLabel=new JLabel("类型");
jLabel.setBounds(100, 15, 60, 40);
jLabel.setFont(font);
box=new JComboBox<String>();
box.addItem("常住");
box.addItem("租户");
box.setSelectedIndex(0);
box.setFont(new Font("幼圆", Font.PLAIN, 17));
box.setBounds(170, 25, 200, 30);
jPanel05.add(jLabel);
jPanel05.add(box);
jPanel05.setBounds(0, 250, this.getWidth(), 50);
this.add(jPanel05);
// 自我介绍+文本域
jPanel06=new JPanel();
jPanel06.setLayout(null);
jPanel06.setBackground(color);
JLabel jLabel05=new JLabel("门牌信息");
jLabel05.setBounds(100, 15, 60, 40);
jLabel05.setFont(font);
textArea=new JTextArea();
textArea.setLineWrap(true);
textArea.setFont(fontField);
textArea.setBorder(null);
jScrollPane=new JScrollPane(textArea);
jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
jScrollPane.setBounds(170, 25, 200, 80);
jPanel06.add(jLabel05);
jPanel06.add(jScrollPane);
jPanel06.setBounds(0, 300, this.getWidth(), 130);
this.add(jPanel06);
// 提交按钮
jPanel07=new JPanel();
jPanel07.setLayout(null);
jPanel07.setBackground(color);
submitBtn=new JButton("注 册");
submitBtn.setFocusPainted(false);
submitBtn.setBorderPainted(false);
submitBtn.setBackground(new Color(0,90,171));
submitBtn.setFont(new Font("幼圆",Font.PLAIN,17));
submitBtn.setForeground(Color.white);
submitBtn.setBounds(220, 0, 78, 35);
jPanel07.add(submitBtn);
jPanel07.setBounds(0, 450, this.getWidth(), 50);
this.add(jPanel07);
}
private JPanel jPanel01,jPanel02,jPanel03;
private JPanel headPanel;
private List<Payment> lists;
private JButton miniBtn,closeBtn;
private User user;
private UserPaneSon1 paneSon1;
private UserPaneSon2 paneSon2;
private UserPaneSon3 paneSon3;
public UserUI(User user) throws HeadlessException {
this.user = user;
setSize(900, 700);
setLayout(null);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setBackground(color);
setUndecorated(true);
setResizable(false);
initHeadPane();
add(initJTabbedPane());
new UserListener(this);
setVisible(true);
}
public void initHeadPane() {
headPanel=new JPanel(null);
headPanel.setBounds(0, 0, 900, 60);
headPanel.setBackground(Color.white);
miniBtn=new JButton();
closeBtn=new JButton();
miniBtn.setBounds(786,5,50,50);
closeBtn.setBounds(845,5,50,50);
miniBtn.setFocusPainted(false);
closeBtn.setFocusPainted(false);
miniBtn.setBorder(null);
closeBtn.setBorder(null);
miniBtn.setBackground(null);
closeBtn.setBackground(null);
miniBtn.setIcon(new ImageIcon("mstUI_img/mini2.png"));
miniBtn.setRolloverIcon(new ImageIcon("mstUI_img/mini1.png"));
}
@Override
public void actionPerformed(ActionEvent e) {
User u = sPanel01.getUser();
// TODO Auto-generated method stub
if(e.getSource()==userUI.getCloseBtn()) {
System.exit(0);
}
if(e.getSource()==userUI.getMiniBtn()) {
userUI.setExtendedState(JFrame.ICONIFIED);
}
if(e.getSource()==this.sPanel02.getDelBtn()) {
delRows(sPanel02.getDtm(), sPanel02.getPayedTable(), new PaymentDAOImp());
}
if(e.getSource()==sPanel01.getCodeBtn()){
clockCodeBtn(u);
}
if(e.getSource()==sPanel01.getPayBtn()) {
readyToPay(u);
}
}
private void clockCodeBtn(User u) {
timer.schedule(new TimerTask() {
int i=60;
@Override
public void run() {
sPanel01.getCodeBtn().setBackground(Color.DARK_GRAY);
sPanel01.getCodeBtn().setEnabled(false);
i--;
sPanel01.getCodeBtn().setText(i + "s");
sPanel01.getCodeBtn().setForeground(Color.white);
//sendBtn.setHorizontalTextPosition(JButton.CENTER);
if (i <= 0) {
//设置按钮可点击 并且停止任务
sPanel01.getCodeBtn().setEnabled(true);
sPanel01.getCodeBtn().setText("发送");
//sendBtn.setHorizontalTextPosition(JButton.CENTER);
timer.cancel();
}
}
}, 1000, 1000);
//readyToPay();
String phone=u.getPhone();
String phonemsg = PhoneCode.getPhonemsg(phone, 1);
public MasterPaneSon2() {
super(null); // 绝对布局
setBounds(0, 0, 900, 590);
setBackground(Color.WHITE);
this.delButton = initJButton(delButton,"删除用户",750, 520);
add(delButton);
this.reflashButton = initJButton(reflashButton,"数据刷新",600, 520);
add(reflashButton);
userList=getUsersList();
add(initScrollPane(userList));
dtm.addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(TableModelEvent e) {
// 修改单元格中的数据并推送到数据库
int id=Integer.parseInt(userTable.getValueAt(userTable.getSelectedRow(), 0)+"");
int selectedColumn = userTable.getSelectedColumn();
String newValue = userTable.getValueAt(userTable.getSelectedRow(), selectedColumn)+"";
int updateForMaster = new UserDAOImp().updateForMaster(id, selectedColumn, newValue);
if(updateForMaster==1) {
JOptionPane.showMessageDialog(null, "修改成功");
masterPaneSon1.setL(masterPaneSon1.getUserLists()); // 刷新业单中的用户数据
Object uname = userTable.getValueAt(userTable.getSelectedRow(), 1);
Object rowName = userTable.getValueAt(userTable.getSelectedRow(), 2);
if(masterPaneSon1.getPayBox().getSelectedItem().equals(uname)&columnNames[selectedColumn].equals("业主姓名")) {
masterPaneSon1.getField01().setText("* 业主姓名:"+rowName);
}
}
}
});
}
private JButton initJButton(JButton button,String title,int x,int y) {
button=new JButton(title);
button.setBounds(x,y,100, 40);
button.setBorder(null);
button.setFocusPainted(false);
button.setBackground(new Color(235,135,112));
button.setForeground(Color.WHITE);
button.setFont(new Font("幼圆",Font.PLAIN,16));
return button;
}
public List<User> getUsersList() {
@SuppressWarnings("unchecked")
List<User> userAll = (List<User>)new UserDAOImp().selectAll();
if(userAll.size()<=0) {
userAll.add(new User());
}
JLabel showWhoJLabel=new JLabel();
showWhoJLabel.setBounds(20, 0, 600, 60);
showWhoJLabel.setFont(new Font("微软雅黑",Font.BOLD,20));
String textString="物业收费系统-物管模式 Hi! 管理员,今天是"+getDateStr();
//String textString="物业收费系统-物管模式 Hi! "+" ,今天是"+getDateStr();
showWhoJLabel.setText(textString);
headPanel.add(showWhoJLabel);
add(headPanel);
}
private static String getDateStr() {
Calendar c=Calendar.getInstance();
Date d=new Date();
c.setTime(d);//设置指定时间
int year=c.get(Calendar.YEAR);
int month=c.get(Calendar.MONTH)+1; //默认是0-11,我国是1-12
int day=c.get(Calendar.DAY_OF_MONTH);
return year+"/"+month+"/"+day;
}
public JTabbedPane initJTabbedPane() {
allTabbedPane=new JTabbedPane();
jPanel01=new JPanel(null);
jPanel02=new JPanel(null);
jPanel03=new JPanel(null);
jPanel01.setBackground(color);
jPanel02.setBackground(color);
jPanel03.setBackground(color);
allTabbedPane.addTab("jPanel01", jPanel01); //添加选项卡容器,并且设置其中每个选项卡的标签以及其是否可启用
allTabbedPane.setEnabledAt(0, true);
allTabbedPane.setTitleAt(0, "收费记录");
allTabbedPane.addTab("jPanel02", jPanel02); //添加选项卡容器,并且设置其中每个选项卡的标签以及其是否可启用
allTabbedPane.setEnabledAt(1, true);
allTabbedPane.setTitleAt(1, "生成业单");
allTabbedPane.addTab("jPanel03", jPanel03); //添加选项卡容器,并且设置其中每个选项卡的标签以及其是否可启用
allTabbedPane.setEnabledAt(2, true);
allTabbedPane.setTitleAt(2, "用户管理");
allTabbedPane.setUI(new TabbedPaneDef());
allTabbedPane.setBounds(0, 60, 900, 640);
allTabbedPane.setFont(new Font("宋体", Font.BOLD, 18));
allTabbedPane.setForeground(new Color(255,255,255));
int i=0;
for(Payment p:lists) {
data[i++]=p.toStrArray();
}
DefaultTableModel dtm=new DefaultTableModel(data,columnNames);
payJTable=new JTable(dtm) {
private static final long serialVersionUID = -2001L;
// 重写这个表格的方法:设置不可编辑,但可以选中
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
payJTable.getTableHeader().setFont(new Font("微软雅黑",Font.BOLD,16));
payJTable.setFont(new Font("幼圆",Font.PLAIN,14));
payJTable.setRowHeight(24);
payJTable.getTableHeader().setReorderingAllowed(false);// 设置列不可拖动
// 设置部分列宽度
payJTable.getColumnModel().getColumn(0).setPreferredWidth(15);
payJTable.getColumnModel().getColumn(2).setPreferredWidth(25);
payJTable.getColumnModel().getColumn(3).setPreferredWidth(25);
payJTable.getColumnModel().getColumn(4).setPreferredWidth(25);
payJTable.getColumnModel().getColumn(0).setResizable(false);
payJTable.getColumnModel().getColumn(2).setResizable(false);
payJTable.getColumnModel().getColumn(3).setResizable(false);
payJTable.getColumnModel().getColumn(4).setResizable(false);
// 设置居中
DefaultTableCellRenderer renderer=new DefaultTableCellRenderer();
renderer.setHorizontalAlignment(JLabel.CENTER);
payJTable.setDefaultRenderer(Object.class, renderer);
return payJTable;
}
@SuppressWarnings("unchecked") //取消小黄标经过
public List<Payment> getPayments() {
PaymentDAOImp paymentDAOImp = new PaymentDAOImp();
List<Payment> list = (List<Payment>)paymentDAOImp.selectAll();
return list;
}
private JPanel initBtnPane() {
this.floorPanel=new JPanel(null);
this.refleshBtn=new JButton("刷 新");
this.addBtn=new JButton("添 加");
forgetButton.setFocusPainted(false);
forgetButton.setBorderPainted(false);
forgetButton.setBackground(null);
forgetButton.setIcon(new ImageIcon("login_img/forget.png"));
forgetButton.setPressedIcon(new ImageIcon("login_img/forget3.png"));
forgetButton.setRolloverIcon(new ImageIcon("login_img/forget2.png"));
forgetButton.setBounds(10, 20, 50, 50);
floorJPanel.add(forgetButton);
registButton=new JButton();
registButton.setToolTipText("注册账户");
registButton.setFocusPainted(false);
registButton.setBorderPainted(false);
registButton.setBackground(null);
registButton.setIcon(new ImageIcon("login_img/oldRegist.png"));
registButton.setRolloverIcon(new ImageIcon("login_img/rolloverRegist.png"));
registButton.setPressedIcon(new ImageIcon("login_img/pressedRegist.png"));
registButton.setBounds(540, 20, 50, 50);
floorJPanel.add(registButton);
return floorJPanel;
}
}
package com.program.userUI;
infoField03.setEditable(false);
infoField03.setBorder(null);
infoField03.setBackground(null);
infoField03.setForeground(new Color(211,82,48));
add(field02);
add(field03);
add(field04);
add(infoField01);
add(infoField02);
add(infoField03);
yesButton=new JButton("生 成");
clearButton=new JButton("清 空");
yesButton.setBounds(300, 380, 90, 40);
clearButton.setBounds(470, 380, 90, 40);
yesButton.setBorder(null);
yesButton.setFocusPainted(false);
yesButton.setForeground(Color.white);
yesButton.setBackground(new Color(30,180,64));
yesButton.setFont(font1);
clearButton.setBorder(null);
clearButton.setFocusPainted(false);
clearButton.setForeground(Color.white);
clearButton.setBackground(new Color(130,100,64));
clearButton.setFont(font1);
add(yesButton);
add(clearButton);
}
public JComboBox<String> initBox() {
JComboBox<String> box=new JComboBox<String>();
l = getUserLists();
box.addItem(" ---请选择--- ");
for (User user : l) {
box.addItem(user.getUserName());
}
return box;
}
@SuppressWarnings("unchecked")
public List<User> getUserLists() {
return (List<User>)new UserDAOImp().selectAll();
}
public ItemListener getItemListener() {
public class LoginListener implements ActionListener{
private JFrame loginUI;
private JTextField userNameField;
private JPasswordField passwordField;
private JComboBox<String> box;
private JButton logButton,minButton,closeButton;
private JPanel headPanel ;
private JButton registButton;
private JButton forgetButton;
private int mouseAtX = 0;
private int mouseAtY = 0;
public LoginListener() {
super();
}
public LoginListener(JFrame loginUI,JTextField userNameField, JPasswordField passwordField, JComboBox<String> box,
JButton logButton, JButton minButton, JButton closeButton, JPanel headPanel, JButton registButton,
JButton forgetButton) {
super();
this.loginUI=loginUI;
this.userNameField = userNameField;
this.passwordField = passwordField;
this.box = box;
this.logButton = logButton;
this.minButton = minButton;
this.closeButton = closeButton;
this.headPanel = headPanel;
this.registButton = registButton;
this.forgetButton = forgetButton;
this.canDraged(this.headPanel);
}
}
}else {
JOptionPane.showMessageDialog(null, "用户不存在或者此用户预留手机号码不正确", "找回失败", JOptionPane.ERROR_MESSAGE);
}
// }else {
// JOptionPane.showMessageDialog(null, "验证码错误或者无效", "找回失败", JOptionPane.ERROR_MESSAGE);
// }
// }else {
// JOptionPane.showMessageDialog(null, "请先获取验证码", "警告", JOptionPane.WARNING_MESSAGE);
// }
}else {
JOptionPane.showMessageDialog(null, "两次输入密码不一致", "找回失败", JOptionPane.ERROR_MESSAGE);
}
}
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==sendBtn) {
codeCheck();
}
if(e.getSource()==submitBtn) {
checkRight();
}
}
private void codeCheck() {
if(phoneField.getText().matches(regexCh)) {
timer.schedule(new TimerTask() {
int i = 60;
@Override
public void run() {
sendBtn.setForeground(Color.white);
sendBtn.setBackground(Color.DARK_GRAY);
sendBtn.setEnabled(false);
i--;
sendBtn.setText(i + "s");
//sendBtn.setHorizontalTextPosition(JButton.CENTER);
if (i <= 0) {
//设置按钮可点击 并且停止任务
sendBtn.setEnabled(true);
sendBtn.setText("验证码");
//sendBtn.setHorizontalTextPosition(JButton.CENTER);
timer.cancel();
}
public class CodeDialog {
JDialog dialog;
JTextField field01,field02;
JButton button01,button02,button03;
MyListener myListener;
@SuppressWarnings("unused")
private UserUI owner;
int flag=0;
Object[][] data;
JTable vtable;
DefaultTableModel dtm;
int row;
int column;
String code=null;
Timer timer=new Timer();
public CodeDialog(UserUI owner,Object[][] data,JTable vtable,DefaultTableModel dtm,int row,int column) {
this.data=data;
this.vtable=vtable;
this.dtm=dtm;
this.row=row;
this.column=column;
this.owner=owner;
dialog=new JDialog(owner, true);
dialog.setUndecorated(true);
dialog.setTitle("资料修改验证");
dialog.setSize(400, 300);
dialog.setResizable(false);
dialog.setLocationRelativeTo(null);
dialog.setLayout(null);
dialog.getContentPane().setBackground(Color.lightGray);
JLabel jLabel=new JLabel("手机号验证:");
jLabel.setBounds(75, 70, 100, 40);
jLabel.setFont(new Font("",Font.PLAIN,16));
String phone = ((UserUI)owner).getUser().getPhone();
field01=new JTextField();
field01.setBounds(185, 70, 140, 40);
field01.setText(phone);
field01.setEditable(false);
field01.setBackground(null);
field01.setFont(new Font("",Font.PLAIN,16));
JLabel jLabel2=new JLabel("获取验证码:");
jLabel2.setBounds(75, 130, 100, 40);
jLabel2.setFont(new Font("",Font.PLAIN,16));
field02=new JTextField();
button.setFocusPainted(false);
button.setBackground(new Color(235,135,112));
button.setForeground(Color.WHITE);
button.setFont(new Font("幼圆",Font.PLAIN,16));
return button;
}
public List<User> getUsersList() {
@SuppressWarnings("unchecked")
List<User> userAll = (List<User>)new UserDAOImp().selectAll();
if(userAll.size()<=0) {
userAll.add(new User());
}
return userAll;
}
private JScrollPane initScrollPane(List<User> list) {
scP=new JScrollPane();
scP.setBackground(Color.WHITE);
scP.setBounds(0, 0, 896, 500);
scP.setViewportView(getViewtable(list));
return scP;
}
private JTable getViewtable(List<User> list) {
data=new Object[list.size()][];
int i=0;
for(User u:list) {
data[i++]=u.toStrArray();
}
dtm=new DefaultTableModel(data,columnNames);
userTable=new JTable(dtm) {
private static final long serialVersionUID = -021L;
// 重写这个表格的方法:设置不可编辑,但可以选中
@Override
public boolean isCellEditable(int row, int column) {
if(column==2|column==4|column==5|column==6) { // 2 4 6 列中的值可以修改
return true;
}
return false;
}
};
userTable.getTableHeader().setFont(new Font("微软雅黑",Font.BOLD,16));
userTable.setFont(new Font("幼圆",Font.PLAIN,16));
userTable.setRowHeight(24);
userTable.getTableHeader().setReorderingAllowed(false);// 设置列不可拖动
// 设置部分列宽度
userTable.getColumnModel().getColumn(0).setPreferredWidth(15);
userTable.getColumnModel().getColumn(1).setPreferredWidth(20);
userTable.getColumnModel().getColumn(2).setPreferredWidth(20);
field02.setFont(new Font("",Font.PLAIN,16));
button01=new JButton("发送");
button01.setBounds(260, 130, 65, 40);
button01.setBorder(null);
button01.setFocusPainted(false);
button01.setBackground(new Color(133, 162, 190));
button01.setForeground(Color.white);
button02=new JButton("确 认");
button02.setBounds(80, 200, 95, 40);
button02.setBorder(null);
button02.setFocusPainted(false);
button02.setBackground(new Color(103, 162, 100));
button02.setForeground(Color.white);
button03=new JButton("取 消");
button03.setBounds(220, 200, 95, 40);
button03.setBorder(null);
button03.setFocusPainted(false);
button03.setBackground(new Color(193, 162, 100));
button03.setForeground(Color.white);
dialog.add(jLabel);
dialog.add(field01);
dialog.add(jLabel2);
dialog.add(field02);
dialog.add(button01);
dialog.add(button02);
dialog.add(button03);
myListener= new MyListener();
button03.addActionListener(myListener);
button02.addActionListener(myListener);
button01.addActionListener(myListener);
dialog.setVisible(true);
}
class MyListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==button03) {
TableModelListener[] tableModelListeners = dtm.getTableModelListeners();
dtm.removeTableModelListener(tableModelListeners[0]);
vtable.setValueAt(data[row][column],vtable.getSelectedRow(), 1);
List<Payment> insertList=new ArrayList<Payment>();
Payment payment=new Payment( uName, Integer.parseInt(checkExp), Integer.parseInt(cleanExp), Integer.parseInt(parkExp), null, "0");
insertList.add(payment);
try {
int insertNum = new PaymentDAOImp().insertObj(insertList);
JOptionPane.showMessageDialog(null, "业单生成成功:"+insertNum+"条", "添加成功",JOptionPane.PLAIN_MESSAGE);
} catch (SQLException e1) {
System.out.println("MasterListener中账单生成的SQL语句错误");
}
}
}
}
if(e.getSource()==masterPaneSon1.getClearButton()) {
masterPaneSon1.getPayBox().setSelectedIndex(0);
masterPaneSon1.getField02().setText("");
masterPaneSon1.getField03().setText("");
masterPaneSon1.getField04().setText("");
}
if(e.getSource()==masterPaneSon2.getDelButton()) {
delRows(masterPaneSon2.getDtm(), masterPaneSon2.getUserTable(), new UserDAOImp());
}
}
public void delRows(DefaultTableModel tableModel,JTable table,AdapterDAO adapterDAO) {
List<Integer> idList=new ArrayList<Integer>();
int selectRows=table.getSelectedRows().length;// 取得用户所选行的行数
int[] selectedRows = table.getSelectedRows();
if(selectRows<=0) {
JOptionPane.showMessageDialog(null, "删除前要选中行", "警告", JOptionPane.WARNING_MESSAGE);
}else {
// 确认是否删除
int get = JOptionPane.showOptionDialog(null, "请确认是否删除?", "友情询问", JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE, null, new Object[]{"是","否"}, "否");
if(get!=1) {
// 视觉上:倒着删避免数组下标越界
for(int i=selectRows-1;i>=0;i--) {
idList.add((Integer.parseInt(tableModel.getValueAt(selectedRows[i], 0)+"")));
tableModel.removeRow(selectedRows[i]);
}
// 数据库中:先获取选中行的第0列 -> 编号列,通过编号删除数据库中的数据
// 调用删除方法
showWhoJLabel.setText(textString);
headPanel.add(showWhoJLabel);
add(headPanel);
}
private static String getDateStr() {
Calendar c=Calendar.getInstance();
Date d=new Date();
c.setTime(d);//设置指定时间
int year=c.get(Calendar.YEAR);
int month=c.get(Calendar.MONTH)+1; //默认是0-11,我国是1-12
int day=c.get(Calendar.DAY_OF_MONTH);
return year+"/"+month+"/"+day;
}
public JTabbedPane initJTabbedPane() {
uTabbedPane=new JTabbedPane();
jPanel01=new JPanel(null);
jPanel02=new JPanel(null);
jPanel03=new JPanel(null);
jPanel01.setBackground(color);
jPanel02.setBackground(color);
jPanel03.setBackground(color);
uTabbedPane.addTab("jPanel01", jPanel01); //添加选项卡容器,并且设置其中每个选项卡的标签以及其是否可启用
uTabbedPane.setEnabledAt(0, true);
uTabbedPane.setTitleAt(0, "查询缴费");
uTabbedPane.addTab("jPanel02", jPanel02); //添加选项卡容器,并且设置其中每个选项卡的标签以及其是否可启用
uTabbedPane.setEnabledAt(1, true);
uTabbedPane.setTitleAt(1, "历史账单");
uTabbedPane.addTab("jPanel03", jPanel03); //添加选项卡容器,并且设置其中每个选项卡的标签以及其是否可启用
uTabbedPane.setEnabledAt(2, true);
uTabbedPane.setTitleAt(2, "资料设置");
uTabbedPane.setUI(new TabbedPaneDef());
uTabbedPane.setBounds(0, 60, 900, 640);
uTabbedPane.setFont(new Font("宋体", Font.BOLD, 18));
uTabbedPane.setForeground(new Color(255,255,255));
paneSon1=new UserPaneSon1(user);
jPanel01.add(paneSon1);
paneSon2=new UserPaneSon2(user);
jPanel02.add(paneSon2);
paneSon3=new UserPaneSon3(user);
paneSon3.setOwner(this);
jPanel03.add(paneSon3);
return uTabbedPane;
}
private JPanel initBtnPane() {
this.floorPanel=new JPanel(null);
this.refleshBtn=new JButton("刷 新");
this.addBtn=new JButton("添 加");
this.modBtn=new JButton("修 改");
this.dellBtn=new JButton("删 除");
refleshBtn.setBounds(40, 20, 100, 40);
addBtn.setBounds(150, 20, 100, 40);
modBtn.setBounds(260, 20, 100, 40);
dellBtn.setBounds(370, 20, 100, 40);
refleshBtn.setBorder(null);
addBtn.setBorder(null);
modBtn.setBorder(null);
dellBtn.setBorder(null);
refleshBtn.setFocusPainted(false);
addBtn.setFocusPainted(false);
modBtn.setFocusPainted(false);
dellBtn.setFocusPainted(false);
addBtn.setBackground(new Color(22, 141, 90));
refleshBtn.setBackground(new Color(138, 41, 48));
dellBtn.setBackground(new Color(219,81,69));
modBtn.setBackground(new Color(191, 230, 230));
addBtn.setForeground(Color.white);
modBtn.setForeground(Color.white);
dellBtn.setForeground(Color.white);
refleshBtn.setForeground(Color.white);
refleshBtn.setFont(new Font("",Font.PLAIN,16));
addBtn.setFont(new Font("",Font.PLAIN,16));
modBtn.setFont(new Font("",Font.PLAIN,16));
dellBtn.setFont(new Font("",Font.PLAIN,16));
modBtn.setToolTipText("管理员是不能修改账单的!");
modBtn.setEnabled(false);
floorPanel.setBounds(0, 500, 900, 88);
floorPanel.setBackground(Color.WHITE);
floorPanel.add(refleshBtn);
floorPanel.add(addBtn);
floorPanel.add(modBtn);
floorPanel.add(dellBtn);
return floorPanel;
}
public JPanel initJpanel02() {
// final String accessKeySecret = StaticPeram.accessKeySecret;// 你的accessKeySecret,参考本文档步骤2
// // 初始化ascClient,暂时不支持多region
// IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou",
// accessKeyId, accessKeySecret);
// try {
// DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product,
// domain);
// } catch (ClientException e1) {
// e1.printStackTrace();
// }
//
// //获取验证码
// codeNum = vcode();
// code="{\"name\":\"Tom\", \"code\":\""+codeNum+"\"}";
//
// IAcsClient acsClient = new DefaultAcsClient(profile);
// // 组装请求对象
// SendSmsRequest request = new SendSmsRequest();
// // 使用post提交
// request.setMethod(MethodType.POST);
// // 必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
// request.setPhoneNumbers(mobile);
// // 必填:短信签名-可在短信控制台中找到
// request.setSignName(StaticPeram.SignName);
// // 必填:短信模板-可在短信控制台中找到
// if(mode==0|mode==1) {
// request.setTemplateCode(StaticPeram.TemplateCode[mode]);
// }else {
// return "无该模式";
// }
// // 可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
// // 友情提示:如果JSON中需要带换行符,请参照标准的JSON协议对换行符的要求,比如短信内容中包含\r\n的情况在JSON中需要表示成\\r\\n,否则会导致JSON在服务端解析失败
// //request.setTemplateParam("{ \"number\":\""+code+"\"}");
// request.setTemplateParam(code);
// // 可选-上行短信扩展码(无特殊需求用户请忽略此字段)
// // request.setSmsUpExtendCode("90997");
// // 可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
// request.setOutId("yourOutId");
// // 请求失败这里会抛ClientException异常
// SendSmsResponse sendSmsResponse;
// try {
// sendSmsResponse = acsClient.getAcsResponse(request);
// if (sendSmsResponse.getCode() != null
// && sendSmsResponse.getCode().equals("OK")) {
// // 请求成功
button01.setBackground(new Color(133, 162, 190));
button01.setForeground(Color.white);
button02=new JButton("确 认");
button02.setBounds(80, 200, 95, 40);
button02.setBorder(null);
button02.setFocusPainted(false);
button02.setBackground(new Color(103, 162, 100));
button02.setForeground(Color.white);
button03=new JButton("取 消");
button03.setBounds(220, 200, 95, 40);
button03.setBorder(null);
button03.setFocusPainted(false);
button03.setBackground(new Color(193, 162, 100));
button03.setForeground(Color.white);
dialog.add(jLabel);
dialog.add(field01);
dialog.add(jLabel2);
dialog.add(field02);
dialog.add(button01);
dialog.add(button02);
dialog.add(button03);
myListener= new MyListener();
button03.addActionListener(myListener);
button02.addActionListener(myListener);
button01.addActionListener(myListener);
dialog.setVisible(true);
}
class MyListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==button03) {
TableModelListener[] tableModelListeners = dtm.getTableModelListeners();
dtm.removeTableModelListener(tableModelListeners[0]);
vtable.setValueAt(data[row][column],vtable.getSelectedRow(), 1);
dtm.addTableModelListener(tableModelListeners[0]);
dialog.dispose();
setFlag(0);
}
if(e.getSource()==button02) {
if(field02.getText().length()<=0) {
JOptionPane.showMessageDialog(null, "验证码不能为空!","警告",JOptionPane.WARNING_MESSAGE);
}else {
if(field02.getText().equals(code)) {
code="";
dialog.dispose();
JOptionPane.showMessageDialog(null, "修改成功!");
public class MasterListener implements ActionListener{
private MasterUI masterUI;
private JTabbedPane allTabbedPane;
private JTable payJTable;
@SuppressWarnings("unused")
private JPanel headPanel;
private JButton refleshBtn,addBtn,modBtn,dellBtn;
private JButton miniBtn,closeBtn;
private MasterPaneSon1 masterPaneSon1;
private MasterPaneSon2 masterPaneSon2;
private int mouseAtX = 0;
private int mouseAtY = 0;
public MasterListener(MasterUI masterUI,JTabbedPane allTabbedPane,JTable payJTable,JPanel headPanel,JButton refleshBtn,
JButton addBtn, JButton modBtn, JButton dellBtn,MasterPaneSon1 masterPaneSon1,MasterPaneSon2 masterPaneSon2) {
super();
this.masterUI=masterUI;
this.allTabbedPane=allTabbedPane;
this.payJTable=payJTable;
this.headPanel = headPanel;
this.refleshBtn = refleshBtn;
this.addBtn = addBtn;
this.modBtn = modBtn;
this.dellBtn = dellBtn;
this.masterPaneSon1=masterPaneSon1;
this.masterPaneSon2=masterPaneSon2;
canDraged(headPanel);
refleshBtn.addActionListener(this);
addBtn.addActionListener(this);
modBtn.addActionListener(this);
dellBtn.addActionListener(this);
keyField.setBounds(170, 15, 100, 40);
keyField.setFont(fontField);
keyField.setBorder(null);
sendBtn=new JButton();
sendBtn.setText("验证码");
sendBtn.setHorizontalTextPosition(JButton.CENTER);
sendBtn.setFocusPainted(false);
sendBtn.setBorderPainted(false);
sendBtn.setBackground(new Color(0,90,171));
sendBtn.setFont(new Font("幼圆",Font.PLAIN,14));
sendBtn.setForeground(Color.white);
sendBtn.setBounds(290, 15, 80, 40);
jPanel04.add(jLabel04);
jPanel04.add(keyField);
jPanel04.add(sendBtn);
jPanel04.setBounds(0,200,this.getWidth(),50);
this.add(jPanel04);
// 学历+下拉列表
jPanel05=new JPanel(null);
jPanel05.setBackground(color);
JLabel jLabel=new JLabel("类型");
jLabel.setBounds(100, 15, 60, 40);
jLabel.setFont(font);
box=new JComboBox<String>();
box.addItem("常住");
box.addItem("租户");
box.setSelectedIndex(0);
box.setFont(new Font("幼圆", Font.PLAIN, 17));
box.setBounds(170, 25, 200, 30);
jPanel05.add(jLabel);
jPanel05.add(box);
jPanel05.setBounds(0, 250, this.getWidth(), 50);
this.add(jPanel05);
// 自我介绍+文本域
jPanel06=new JPanel();
jPanel06.setLayout(null);
jPanel06.setBackground(color);
JLabel jLabel05=new JLabel("门牌信息");
jLabel05.setBounds(100, 15, 60, 40);
jLabel05.setFont(font);
textArea=new JTextArea();
}
public void setWillPayBox(JComboBox<String> willPayBox) {
this.willPayBox = willPayBox;
}
public List<Payment> getpList() {
return pList;
}
public void setpList(List<Payment> pList) {
this.pList = pList;
}
public JButton getPayBtn() {
return payBtn;
}
public void setPayBtn(JButton payBtn) {
this.payBtn = payBtn;
}
public JButton getCodeBtn() {
return codeBtn;
}
public void setCodeBtn(JButton codeBtn) {
this.codeBtn = codeBtn;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
package com.program.userUI;
public class UserDAOImp extends AdapterDAO{
DataSource dataSource=DruidJDBC.getDataSource();
JdbcTemplate jt=new JdbcTemplate(dataSource);
String sql;
@Override
public List<User> getRightPost(String userName, String password){
// TODO Auto-generated method stub
sql="select * from user where userName = ? and userPassword = ?";
List<User> user=null;
user = jt.query(sql, new BeanPropertyRowMapper<User>(User.class),userName,password);
return user;
}
@Override
public int insertObj(List<?> list) throws SQLException {
// TODO Auto-generated method stub
int count=0;
if(list.size()==0) {
return count;
}
sql="insert into user(userName,userPassword,name,phone,userType,advDeposit,place,available) values(?,?,?,?,?,?,?,?)";
try {
for(Object one:list) {
User user=(User) one;
PreparedStatement pS = DruidJDBC.getConnection().prepareStatement("select * from user where userName=? or phone=?");
pS.setString(1, user.getUserName());
pS.setString(2, user.getPhone());
ResultSet rs = pS.executeQuery();
if(rs.next()==true) {
return -1;
}else {
count+=jt.update(sql, user.getUserName(),user.getUserPassword(),user.getName(),user.getPhone(),
user.getUserType(),"10000",user.getPlace(),user.getAvailable());
}
button.setBorder(null);
button.setFocusPainted(false);
button.setBackground(new Color(235,135,112));
button.setForeground(Color.WHITE);
button.setFont(new Font("幼圆",Font.PLAIN,16));
return button;
}
public List<User> getUsersList() {
@SuppressWarnings("unchecked")
List<User> userAll = (List<User>)new UserDAOImp().selectAll();
if(userAll.size()<=0) {
userAll.add(new User());
}
return userAll;
}
private JScrollPane initScrollPane(List<User> list) {
scP=new JScrollPane();
scP.setBackground(Color.WHITE);
scP.setBounds(0, 0, 896, 500);
scP.setViewportView(getViewtable(list));
return scP;
}
private JTable getViewtable(List<User> list) {
data=new Object[list.size()][];
int i=0;
for(User u:list) {
data[i++]=u.toStrArray();
}
dtm=new DefaultTableModel(data,columnNames);
userTable=new JTable(dtm) {
private static final long serialVersionUID = -021L;
// 重写这个表格的方法:设置不可编辑,但可以选中
@Override
public boolean isCellEditable(int row, int column) {
if(column==2|column==4|column==5|column==6) { // 2 4 6 列中的值可以修改
return true;
}
return false;
}
};
}
private JTable getViewtable(List<Payment> list) {
data=new Object[list.size()][];
int i=0;
for(Payment p:list) {
data[i++]=setArrObj(p);
}
dtm=new DefaultTableModel(data,columnNames);
payedTable=new JTable(dtm) {
private static final long serialVersionUID = -111L;
// 重写这个表格的方法:设置不可编辑,但可以选中
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
payedTable.getTableHeader().setFont(new Font("微软雅黑",Font.BOLD,16));
payedTable.setFont(new Font("幼圆",Font.PLAIN,16));
payedTable.setRowHeight(24);
payedTable.getTableHeader().setReorderingAllowed(false);// 设置列不可拖动
// 设置部分列宽度
//payedTable.getColumnModel().getColumn(k).setResizable(false);
payedTable.getColumnModel().getColumn(7).setPreferredWidth(200);
// 设置居中
DefaultTableCellRenderer renderer=new DefaultTableCellRenderer();
renderer.setHorizontalAlignment(JLabel.CENTER);
payedTable.setDefaultRenderer(Object.class, renderer);
return payedTable;
}
@SuppressWarnings("unchecked")
public List<Payment> getPayments(User u) {
PaymentDAOImp paymentDAOImp = new PaymentDAOImp();
List<Payment> list = (List<Payment>)paymentDAOImp.selectAll(u);
return list;
}
public Object[] setArrObj(Payment p) {
// {"账单编号","用户名","业主姓名","手机","检查费","清洁费","停车费","缴费日期"};
Object[] objs= {p.getID(),user.getUserName(),user.getName(),user.getPhone(),p.getCheckEXP(),
p.getCleanEXP(),p.getParkEXP(),p.getPayDate()};
return objs;
}
private JButton initJButton(JButton button,String title,int x,int y) {
button=new JButton(title);
button.setBounds(x,y,100, 40);
button.setBorder(null);
button.setFocusPainted(false);
button.setBackground(new Color(235,135,112));
button.setForeground(Color.WHITE);
button.setFont(new Font("幼圆",Font.PLAIN,16));
return button;
// // 可选-上行短信扩展码(无特殊需求用户请忽略此字段)
// // request.setSmsUpExtendCode("90997");
// // 可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
// request.setOutId("yourOutId");
// // 请求失败这里会抛ClientException异常
// SendSmsResponse sendSmsResponse;
// try {
// sendSmsResponse = acsClient.getAcsResponse(request);
// if (sendSmsResponse.getCode() != null
// && sendSmsResponse.getCode().equals("OK")) {
// // 请求成功
// //System.out.println("获取验证码成功!!!");
// } else {
// //如果验证码出错,会输出错误码告诉你具体原因
// //isv.MOBILE_NUMBER_ILLEGAL 手机号码非法
// /*System.out.println(sendSmsResponse.getCode());
// System.out.println("获取验证码失败...");*/
// }
// } catch (ServerException e) {
// e.printStackTrace();
// return "由于系统维护,暂时无法注册!!!";
// } catch (ClientException e) {
// e.printStackTrace();
// return "由于系统维护,暂时无法注册!!!";
// }
return "true";
}
/**
* 生成6位随机数验证码(暂时写死)
* @return
*/
public static String vcode(){
String vcode = "123456";
// for (int i = 0; i < 6; i++) {
// vcode = vcode + (int)(Math.random() * 9);
// }
return vcode;
}
/*public static void main(String[] args) {
String phonemsg = PhoneCode.getPhonemsg("15082542389", 1);
System.out.println(phonemsg);
}*/
}
package com.program.daoimp;