Compare commits
8 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
f6eb1cc301 | 2 years ago |
|
|
41c0c984a2 | 2 years ago |
|
|
0c68589c93 | 2 years ago |
|
|
da905b66a4 | 2 years ago |
|
|
209541065e | 2 years ago |
|
|
59f52cbe3f | 2 years ago |
|
|
875caf88e1 | 2 years ago |
|
|
ca56a34ef9 | 2 years ago |
@ -1,117 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import dao.GuanliyuanDao;
|
||||
import dao.impl.GuanliyuanImpl;
|
||||
import entity.Guanliyuan;
|
||||
|
||||
|
||||
public class GuanliyuanAddUI extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
GuanliyuanDao dao = new GuanliyuanImpl();
|
||||
public GuanliyuanAddUI() {
|
||||
init(null);
|
||||
}
|
||||
public GuanliyuanAddUI(Tableinter mui) {
|
||||
init(mui);
|
||||
}
|
||||
public void init(Tableinter mui) {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 643, 646);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
JPanel panel = new JPanel();
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(new GridLayout(0, 2, 0, 0));
|
||||
JLabel yonghumingyclabel = new JLabel("用户名");
|
||||
yonghumingyclabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(yonghumingyclabel);
|
||||
JTextField yonghumingyctextField = new JTextField();
|
||||
panel.add(yonghumingyctextField);
|
||||
|
||||
JLabel mimayclabel = new JLabel("密码");
|
||||
mimayclabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(mimayclabel);
|
||||
JTextField mimayctextField = new JTextField();
|
||||
panel.add(mimayctextField);
|
||||
|
||||
JLabel jiaoseyclabel = new JLabel("角色");
|
||||
jiaoseyclabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(jiaoseyclabel);
|
||||
JComboBox jiaoseyccomboBox = new JComboBox();
|
||||
jiaoseyccomboBox.setModel(new DefaultComboBoxModel(new String[] {"管理员"}));
|
||||
panel.add(jiaoseyccomboBox);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
panel.setBounds(10, 10, 607, 90);
|
||||
JButton button = new JButton("添加");
|
||||
/**
|
||||
新增按钮触发事件
|
||||
*/
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Guanliyuan bean=new Guanliyuan();
|
||||
bean.setYonghumingyc(yonghumingyctextField.getText());
|
||||
|
||||
bean.setMimayc(mimayctextField.getText());
|
||||
|
||||
bean.setJiaoseyc(jiaoseyccomboBox.getSelectedItem().toString());
|
||||
|
||||
|
||||
dao.create(bean);
|
||||
JOptionPane.showMessageDialog(null, "添加成功");
|
||||
if(mui!=null)
|
||||
mui.refresh(dao.findAll());
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button.setBounds(173, 550, 93, 47);
|
||||
contentPane.add(button);
|
||||
|
||||
JButton button_1 = new JButton("取消");
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button_1.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button_1.setBounds(334, 550, 93, 47);
|
||||
contentPane.add(button_1);
|
||||
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
public String getRadioValue(JPanel panel){
|
||||
for(Component c:panel.getComponents()){
|
||||
if(c instanceof JRadioButton){
|
||||
if(((JRadioButton) c).isSelected()){
|
||||
return ((JRadioButton)c).getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,165 @@
|
||||
|
||||
package dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dao.GuanliyuanDao;
|
||||
import entity.Guanliyuan;
|
||||
|
||||
public class GuanliyuanImpl implements GuanliyuanDao{
|
||||
|
||||
public Guanliyuan findById(String id) {
|
||||
Guanliyuan acyc=new Guanliyuan();
|
||||
try {
|
||||
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sql = "select*from guanliyuan where id = ?";
|
||||
PreparedStatement prestm=conn.prepareStatement(sql);
|
||||
prestm.setInt(1, Integer.valueOf(id));
|
||||
ResultSet rs=prestm.executeQuery();
|
||||
|
||||
while(rs.next()) {
|
||||
Guanliyuan guanliyuan=new Guanliyuan();
|
||||
guanliyuan.setId(rs.getInt("id"));
|
||||
guanliyuan.setYonghumingyc(rs.getString("yonghumingyc"));
|
||||
guanliyuan.setMimayc(rs.getString("mimayc"));
|
||||
guanliyuan.setJiaoseyc(rs.getString("jiaoseyc"));
|
||||
acyc=guanliyuan;
|
||||
}
|
||||
rs.close();
|
||||
prestm.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return acyc;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Guanliyuan> findAll() {
|
||||
ArrayList<Guanliyuan> zhushus=new ArrayList<Guanliyuan>();
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
|
||||
String sqlyc ="select *from guanliyuan";
|
||||
Statement stsyc =conn.createStatement();
|
||||
ResultSet rsyc=stsyc.executeQuery(sqlyc);
|
||||
|
||||
while(rsyc.next()) {
|
||||
Guanliyuan guanliyuan=new Guanliyuan();
|
||||
guanliyuan.setId(rsyc.getInt("id"));
|
||||
guanliyuan.setYonghumingyc(rsyc.getString("yonghumingyc"));
|
||||
guanliyuan.setMimayc(rsyc.getString("mimayc"));
|
||||
guanliyuan.setJiaoseyc(rsyc.getString("jiaoseyc"));
|
||||
zhushus.add(guanliyuan);
|
||||
}
|
||||
rsyc.close();
|
||||
stsyc.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// TODO 自动生成的方法存根
|
||||
return zhushus;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int modify(Guanliyuan guanliyuan) {
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
|
||||
String sqlyc ="update guanliyuan set yonghumingyc=?,mimayc=?,jiaoseyc=? where id=?";
|
||||
PreparedStatement prestmyc=conn.prepareStatement(sqlyc);
|
||||
prestmyc.setString(1,guanliyuan.getYonghumingyc());
|
||||
prestmyc.setString(2,guanliyuan.getMimayc());
|
||||
prestmyc.setString(3,guanliyuan.getJiaoseyc());
|
||||
prestmyc.setInt(4,guanliyuan.getId());
|
||||
prestmyc.executeUpdate();
|
||||
prestmyc.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int create(Guanliyuan guanliyuan) {
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sqlyc ="Insert into guanliyuan (yonghumingyc,mimayc,jiaoseyc) values(?,?,?)";
|
||||
PreparedStatement prestmyc=conn.prepareStatement(sqlyc);
|
||||
prestmyc.setString(1,guanliyuan.getYonghumingyc());
|
||||
prestmyc.setString(2,guanliyuan.getMimayc());
|
||||
prestmyc.setString(3,guanliyuan.getJiaoseyc());
|
||||
prestmyc.executeUpdate();
|
||||
prestmyc.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int remove(Guanliyuan guanliyuan) {
|
||||
int flagyc=0;
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sqlyc ="delete from guanliyuan where id=?";
|
||||
PreparedStatement prestmyc=conn.prepareStatement(sqlyc);
|
||||
prestmyc.setInt(1, guanliyuan.getId());
|
||||
flagyc = prestmyc.executeUpdate();
|
||||
prestmyc.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flagyc;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Guanliyuan findByUsername(String yonghuming) {
|
||||
Guanliyuan acyc=new Guanliyuan();
|
||||
try {
|
||||
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sql = "select*from guanliyuan where yonghumingyc = ?";
|
||||
PreparedStatement prestm=conn.prepareStatement(sql);
|
||||
prestm.setString(1, yonghuming);
|
||||
ResultSet rs=prestm.executeQuery();
|
||||
|
||||
while(rs.next()) {
|
||||
Guanliyuan guanliyuan=new Guanliyuan();
|
||||
guanliyuan.setId(rs.getInt("id"));
|
||||
guanliyuan.setYonghumingyc(rs.getString("yonghumingyc"));
|
||||
guanliyuan.setMimayc(rs.getString("mimayc"));
|
||||
guanliyuan.setJiaoseyc(rs.getString("jiaoseyc"));
|
||||
acyc=guanliyuan;
|
||||
}
|
||||
rs.close();
|
||||
prestm.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return acyc;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
public class GuanliyuanManageUI extends JFrame{
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new GuanliyuanManageUI().setVisible(true);
|
||||
}
|
||||
public GuanliyuanManageUI() {
|
||||
setTitle("管理员管理");
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 879, 665);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
add(new GuanliyuanManageUIListPanel(""), BorderLayout.CENTER);
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,172 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import dao.GuanliyuanDao;
|
||||
import dao.impl.GuanliyuanImpl;
|
||||
import entity.Guanliyuan;
|
||||
|
||||
public class GuanliyuanManageUIListPanel extends JPanel implements Tableinter{
|
||||
GuanliyuanDao dao = new GuanliyuanImpl();
|
||||
private JPanel contentPane;
|
||||
|
||||
|
||||
|
||||
|
||||
private static String[] columnCount = { "id","用户名","密码","角色" };
|
||||
public JTable table;
|
||||
private static DefaultTableModel tableModel;
|
||||
private String mainid;
|
||||
|
||||
public GuanliyuanManageUIListPanel(String mainid) {
|
||||
this.mainid=mainid;
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
add(contentPane);
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
contentPane.add(scrollPane, BorderLayout.CENTER);
|
||||
table = new JTable();
|
||||
scrollPane.setViewportView(table);
|
||||
JPanel toppanel = new JPanel();
|
||||
contentPane.add(toppanel, BorderLayout.NORTH);
|
||||
toppanel.setLayout(new GridLayout(2, 1, 0, 0));
|
||||
|
||||
JPanel btnpanel = new JPanel();
|
||||
btnpanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
|
||||
toppanel.add(btnpanel);
|
||||
|
||||
|
||||
JButton button = new JButton("添加");
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
new GuanliyuanAddUI(me()).setVisible(true);
|
||||
}
|
||||
});
|
||||
btnpanel.add(button);
|
||||
|
||||
JButton button_1 = new JButton("删除");
|
||||
/**
|
||||
删除操作
|
||||
*/
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int row = table.getSelectedRow();
|
||||
if (row == -1) {
|
||||
JOptionPane.showMessageDialog(null, "请选择一行进行删除");
|
||||
return;
|
||||
}
|
||||
String keyvalue = (String) table.getValueAt(row, 0);
|
||||
/**
|
||||
根据主键进行查询,如果查询到则删除
|
||||
*/
|
||||
Guanliyuan gl=new Guanliyuan();
|
||||
gl.setId(Integer.valueOf(keyvalue));
|
||||
dao.remove(gl);
|
||||
JOptionPane.showMessageDialog(null, "删除成功");
|
||||
refresh(dao.findAll());
|
||||
}
|
||||
});
|
||||
btnpanel.add(button_1);
|
||||
|
||||
JButton button_2 = new JButton("修改");
|
||||
/**
|
||||
修改操作
|
||||
*/
|
||||
button_2.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int row = table.getSelectedRow();
|
||||
if (row == -1) {
|
||||
JOptionPane.showMessageDialog(null, "请选择一行进行修改");
|
||||
return;
|
||||
}
|
||||
//跳转到修改页面
|
||||
new GuanliyuanUpdateUI(me()).setVisible(true);
|
||||
}
|
||||
|
||||
});
|
||||
btnpanel.add(button_2);
|
||||
refresh(dao.findAll());
|
||||
}
|
||||
public GuanliyuanManageUIListPanel me(){
|
||||
return this;
|
||||
}
|
||||
//刷新表格列表
|
||||
public void refresh(List list){
|
||||
|
||||
|
||||
tableModel = new DefaultTableModel(transferList(list), columnCount){
|
||||
public Class getColumnClass(int column) {
|
||||
Vector<?> v = (Vector<?>) dataVector.elementAt(0);
|
||||
if(v.elementAt(column)!=null){
|
||||
return v.elementAt(column).getClass();
|
||||
}else{
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
Class<?> columnClass = getColumnClass(col);
|
||||
return columnClass != ImageIcon.class;
|
||||
}
|
||||
};
|
||||
table.setModel(tableModel);
|
||||
|
||||
|
||||
updateRowHeights();
|
||||
}
|
||||
//自动调整列高
|
||||
private void updateRowHeights()
|
||||
{
|
||||
for (int row = 0; row < table.getRowCount(); row++)
|
||||
{
|
||||
int rowHeight = table.getRowHeight();
|
||||
|
||||
for (int column = 0; column < table.getColumnCount(); column++)
|
||||
{
|
||||
Component comp = table.prepareRenderer(table.getCellRenderer(row, column), row, column);
|
||||
rowHeight = Math.max(rowHeight, comp.getPreferredSize().height);
|
||||
}
|
||||
table.setRowHeight(row, rowHeight);
|
||||
}
|
||||
}
|
||||
//将实体列表转换为表格实体
|
||||
public static Object[][] transferList(List<Guanliyuan> list) {
|
||||
Object[][] olist = new Object[list.size()][];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Object str[] = {list.get(i).getId().toString(), list.get(i).getYonghumingyc(),list.get(i).getMimayc(),list.get(i).getJiaoseyc() };
|
||||
//如果包含图片格式则以图片形式显示
|
||||
for (int j = 0; j < str.length; j++) {
|
||||
if(str[j]!=null&&(str[j].toString().contains("png")||str[j].toString().contains("jpg")||str[j].toString().contains("gif"))){
|
||||
str[j]=new ImageIcon(new ImageIcon(str[j].toString()).getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT));
|
||||
}
|
||||
}
|
||||
olist[i] = str;
|
||||
}
|
||||
|
||||
return olist;
|
||||
}
|
||||
public JTable getTable() {
|
||||
return table;
|
||||
}
|
||||
public String getMainid(){
|
||||
return mainid;
|
||||
}
|
||||
}
|
||||
@ -1,131 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import dao.GuanliyuanDao;
|
||||
import dao.impl.GuanliyuanImpl;
|
||||
import entity.Guanliyuan;
|
||||
public class GuanliyuanUpdateUI extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
|
||||
|
||||
GuanliyuanDao dao = new GuanliyuanImpl();
|
||||
public GuanliyuanUpdateUI() {
|
||||
init(null);
|
||||
}
|
||||
public GuanliyuanUpdateUI(Tableinter mui) {
|
||||
init(mui);
|
||||
}
|
||||
public void init(Tableinter mui) {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 643, 646);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
Guanliyuan guanliyuan=null;
|
||||
guanliyuan = dao.findById((String) mui.getTable().getValueAt(mui.getTable().getSelectedRow(), 0));
|
||||
JPanel panel = new BackgroundPanel();
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(new GridLayout(0, 2, 0, 0));
|
||||
JLabel idlabel = new JLabel("id");
|
||||
idlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(idlabel);
|
||||
JTextField idtextField = new JTextField(guanliyuan.getId().toString());
|
||||
idtextField.setEnabled(false);
|
||||
panel.add(idtextField);
|
||||
JLabel yonghumingyclabel = new JLabel("用户名");
|
||||
yonghumingyclabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(yonghumingyclabel);
|
||||
JTextField yonghumingyctextField = new JTextField(guanliyuan.getYonghumingyc());
|
||||
panel.add(yonghumingyctextField);
|
||||
|
||||
JLabel mimayclabel = new JLabel("密码");
|
||||
mimayclabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(mimayclabel);
|
||||
JTextField mimayctextField = new JTextField(guanliyuan.getMimayc());
|
||||
panel.add(mimayctextField);
|
||||
|
||||
JLabel jiaoseyclabel = new JLabel("角色");
|
||||
jiaoseyclabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(jiaoseyclabel);
|
||||
JComboBox jiaoseyccomboBox = new JComboBox();
|
||||
jiaoseyccomboBox.setModel(new DefaultComboBoxModel(new String[] {"管理员"}));
|
||||
jiaoseyccomboBox.setSelectedItem(guanliyuan.getJiaoseyc());
|
||||
panel.add(jiaoseyccomboBox);
|
||||
|
||||
|
||||
|
||||
panel.setBounds(10, 10, 607, 120);
|
||||
JButton button = new JButton("修改");
|
||||
/**
|
||||
修改按钮触发事件
|
||||
*/
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
||||
Guanliyuan bean=new Guanliyuan();
|
||||
bean.setYonghumingyc(yonghumingyctextField.getText());
|
||||
|
||||
bean.setMimayc(mimayctextField.getText());
|
||||
|
||||
bean.setJiaoseyc(jiaoseyccomboBox.getSelectedItem().toString());
|
||||
|
||||
bean.setId(Integer.valueOf(idtextField.getText()));
|
||||
|
||||
|
||||
dao.modify(bean);
|
||||
JOptionPane.showMessageDialog(null, "修改成功");
|
||||
//刷新主界面列表
|
||||
if(mui!=null)
|
||||
mui.refresh(dao.findAll());
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button.setBounds(173, 550, 93, 47);
|
||||
contentPane.add(button);
|
||||
|
||||
JButton button_1 = new JButton("取消");
|
||||
/**
|
||||
取消按钮触发事件
|
||||
*/
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button_1.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button_1.setBounds(334, 550, 93, 47);
|
||||
contentPane.add(button_1);
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
public String getRadioValue(JPanel panel){
|
||||
for(Component c:panel.getComponents()){
|
||||
if(c instanceof JRadioButton){
|
||||
if(((JRadioButton) c).isSelected()){
|
||||
return ((JRadioButton)c).getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -1,132 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import dao.GuanliyuanDao;
|
||||
import dao.impl.GuanliyuanImpl;
|
||||
import entity.Guanliyuan;
|
||||
|
||||
public class LoginUI extends JFrame {
|
||||
|
||||
GuanliyuanDao dao = new GuanliyuanImpl();
|
||||
public static String username;
|
||||
public static String role;
|
||||
private JPanel contentPane;
|
||||
private JTextField textField;
|
||||
private JPasswordField textField_1;
|
||||
private JComboBox comboBox;
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
LoginUI frame = new LoginUI();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public LoginUI() {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 643, 508);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
setTitle("家庭收支管理系统");
|
||||
JLabel label = new JLabel("用户名");
|
||||
label.setFont(new Font("楷体", Font.PLAIN, 20));
|
||||
label.setBounds(104, 125, 110, 32);
|
||||
contentPane.add(label);
|
||||
|
||||
textField = new JTextField();
|
||||
textField.setBounds(224, 119, 227, 38);
|
||||
contentPane.add(textField);
|
||||
textField.setColumns(10);
|
||||
|
||||
JLabel label_1 = new JLabel("密码");
|
||||
label_1.setFont(new Font("楷体", Font.PLAIN, 20));
|
||||
label_1.setBounds(104, 210, 110, 32);
|
||||
contentPane.add(label_1);
|
||||
|
||||
textField_1 = new JPasswordField();
|
||||
textField_1.setColumns(10);
|
||||
textField_1.setBounds(224, 204, 227, 38);
|
||||
contentPane.add(textField_1);
|
||||
|
||||
JButton button = new JButton("登录");
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Guanliyuan gl = dao.findByUsername(textField.getText());
|
||||
if(gl!=null){
|
||||
if(gl.getMimayc().equals(textField_1.getText())){
|
||||
username=gl.getYonghumingyc();
|
||||
role=gl.getJiaoseyc();
|
||||
if(!role.equals(comboBox.getSelectedItem().toString())){
|
||||
JOptionPane.showMessageDialog(null, "用户名或密码错误,登录失败");
|
||||
return;
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "登录成功");
|
||||
MainUI frame = new MainUI();
|
||||
frame.setVisible(true);
|
||||
setVisible(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
JOptionPane.showMessageDialog(null, "用户名或密码错误,登录失败");
|
||||
}
|
||||
});
|
||||
button.setFont(new Font("楷体", Font.PLAIN, 20));
|
||||
button.setBounds(175, 371, 105, 38);
|
||||
contentPane.add(button);
|
||||
JButton button_1 = new JButton("注册");
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
RegistUI frame = new RegistUI();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
});
|
||||
button_1.setFont(new Font("楷体", Font.PLAIN, 20));
|
||||
button_1.setBounds(332, 371, 105, 38);
|
||||
contentPane.add(button_1);
|
||||
JLabel lblNewLabel = new JLabel("家庭收支管理系统");
|
||||
lblNewLabel.setFont(new Font("楷体", Font.PLAIN, 28));
|
||||
lblNewLabel.setBounds(235, 28, 497, 55);
|
||||
contentPane.add(lblNewLabel);
|
||||
|
||||
JLabel label_2 = new JLabel("角色");
|
||||
label_2.setFont(new Font("楷体", Font.PLAIN, 20));
|
||||
label_2.setBounds(104, 291, 110, 32);
|
||||
contentPane.add(label_2);
|
||||
|
||||
comboBox = new JComboBox();
|
||||
comboBox.setModel(new DefaultComboBoxModel(new String[] {"管理员"}));
|
||||
comboBox.setBounds(224, 291, 227, 32);
|
||||
contentPane.add(comboBox);
|
||||
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
}
|
||||
@ -1,87 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.border.LineBorder;
|
||||
public class MainUI extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
public static void main(String[] args) {
|
||||
MainUI frame = new MainUI();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public MainUI() {
|
||||
setTitle("家庭收支管理系统");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 1159, 793);
|
||||
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JPanel toppanel = new JPanel();
|
||||
toppanel.setBorder(new LineBorder(new Color(0, 0, 0)));
|
||||
FlowLayout flowLayout = (FlowLayout) toppanel.getLayout();
|
||||
flowLayout.setAlignment(FlowLayout.LEFT);
|
||||
contentPane.add(toppanel, BorderLayout.NORTH);
|
||||
|
||||
JButton GuanliyuanManageUI = new JButton("管理员管理");
|
||||
GuanliyuanManageUI.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
new GuanliyuanManageUI().setVisible(true);
|
||||
}
|
||||
});
|
||||
GuanliyuanManageUI.setFont(new Font("华文楷体", Font.PLAIN, 25));
|
||||
|
||||
toppanel.add(GuanliyuanManageUI);
|
||||
JButton ZhuhuManageUI = new JButton("住户管理");
|
||||
ZhuhuManageUI.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
new ZhuhuManageUI().setVisible(true);
|
||||
}
|
||||
});
|
||||
ZhuhuManageUI.setFont(new Font("华文楷体", Font.PLAIN, 25));
|
||||
|
||||
toppanel.add(ZhuhuManageUI);
|
||||
JButton ShouruqingkuangManageUI = new JButton("收入情况管理");
|
||||
ShouruqingkuangManageUI.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
new ShouruqingkuangManageUI().setVisible(true);
|
||||
}
|
||||
});
|
||||
ShouruqingkuangManageUI.setFont(new Font("华文楷体", Font.PLAIN, 25));
|
||||
|
||||
toppanel.add(ShouruqingkuangManageUI);
|
||||
JButton ZhichuqingkuangManageUI = new JButton("支出情况管理");
|
||||
ZhichuqingkuangManageUI.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
new ZhichuqingkuangManageUI().setVisible(true);
|
||||
}
|
||||
});
|
||||
ZhichuqingkuangManageUI.setFont(new Font("华文楷体", Font.PLAIN, 25));
|
||||
|
||||
toppanel.add(ZhichuqingkuangManageUI);
|
||||
JButton exitbutton = new JButton("退出");
|
||||
exitbutton.setFont(new Font("华文楷体", Font.PLAIN, 25));
|
||||
toppanel.add(exitbutton);
|
||||
exitbutton.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
}
|
||||
@ -1,94 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import dao.GuanliyuanDao;
|
||||
import dao.impl.GuanliyuanImpl;
|
||||
import entity.Guanliyuan;
|
||||
public class RegistUI extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
GuanliyuanDao dao = new GuanliyuanImpl();
|
||||
public RegistUI() {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 643, 646);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
JPanel panel = new JPanel();
|
||||
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(new GridLayout(3, 2, 0, 0));
|
||||
JLabel yonghumingyclabel = new JLabel("用户名");
|
||||
yonghumingyclabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(yonghumingyclabel);
|
||||
JTextField yonghumingyctextField = new JTextField();
|
||||
panel.add(yonghumingyctextField);
|
||||
JLabel mimayclabel = new JLabel("密码");
|
||||
mimayclabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(mimayclabel);
|
||||
JTextField mimayctextField = new JTextField();
|
||||
panel.add(mimayctextField);
|
||||
JLabel jiaoseyclabel = new JLabel("角色");
|
||||
jiaoseyclabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(jiaoseyclabel);
|
||||
JComboBox jiaoseyccomboBox = new JComboBox();
|
||||
jiaoseyccomboBox.setModel(new DefaultComboBoxModel(new String[] {"管理员"}));
|
||||
panel.add(jiaoseyccomboBox);
|
||||
|
||||
panel.setBounds(10, 10, 607, 90);
|
||||
JButton button = new JButton("注册");
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Guanliyuan bean=new Guanliyuan();
|
||||
bean.setYonghumingyc(yonghumingyctextField.getText());
|
||||
bean.setMimayc(mimayctextField.getText());
|
||||
bean.setJiaoseyc(jiaoseyccomboBox.getSelectedItem().toString());
|
||||
dao.create(bean);
|
||||
JOptionPane.showMessageDialog(null, "注册成功");
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button.setBounds(173, 550, 93, 47);
|
||||
contentPane.add(button);
|
||||
|
||||
JButton button_1 = new JButton("取消");
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button_1.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button_1.setBounds(334, 550, 93, 47);
|
||||
contentPane.add(button_1);
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
public String getRadioValue(JPanel panel){
|
||||
for(Component c:panel.getComponents()){
|
||||
if(c instanceof JRadioButton){
|
||||
if(((JRadioButton) c).isSelected()){
|
||||
return ((JRadioButton)c).getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -1,141 +0,0 @@
|
||||
package com.ym.view;
|
||||
|
||||
import java.awt.Component;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import com.eltima.components.ui.DatePicker;
|
||||
|
||||
|
||||
|
||||
import com.ym.dao.ShouruqingkuangymDao;
|
||||
import com.ym.dao.impl.ShouruqingkuangymImpl;
|
||||
import com.ym.entity.Shouruqingkuangym;
|
||||
|
||||
|
||||
public class ShouruqingkuangAddUI extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
ShouruqingkuangymDao dao = new ShouruqingkuangymImpl();
|
||||
//ZhuhuDao zhuhuhuzhuymdao = new ZhuhuImpl();
|
||||
public ShouruqingkuangAddUI() {
|
||||
init(null);
|
||||
}
|
||||
public ShouruqingkuangAddUI(Tableinter mui) {
|
||||
init(mui);
|
||||
}
|
||||
public void init(Tableinter mui) {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 643, 646);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
JPanel panel = new JPanel();
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(new GridLayout(0, 2, 0, 0));
|
||||
JLabel mingxiymlabel = new JLabel("明细");
|
||||
mingxiymlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(mingxiymlabel);
|
||||
JTextField mingxiymtextField = new JTextField();
|
||||
panel.add(mingxiymtextField);
|
||||
|
||||
JLabel fashengriqiymlabel = new JLabel("发生日期");
|
||||
fashengriqiymlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(fashengriqiymlabel);
|
||||
DatePicker fashengriqiymtextField = new DatePicker(this);
|
||||
fashengriqiymtextField.setPattern("yyyy-MM-dd");
|
||||
fashengriqiymtextField.setTimePanleVisible(true);
|
||||
fashengriqiymtextField.setEditorable(false);
|
||||
panel.add(fashengriqiymtextField);
|
||||
|
||||
JLabel fashengfeiyongymlabel = new JLabel("发生费用");
|
||||
fashengfeiyongymlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(fashengfeiyongymlabel);
|
||||
JTextField fashengfeiyongymtextField = new JTextField();
|
||||
panel.add(fashengfeiyongymtextField);
|
||||
|
||||
JLabel huzhuymlabel = new JLabel("户主");
|
||||
huzhuymlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(huzhuymlabel);
|
||||
|
||||
JComboBox huzhuymcomboBox = new JComboBox();
|
||||
List<Zhuhu> zhuhuhuzhuymlist=zhuhuhuzhudao.findAll();
|
||||
huzhuymcomboBox.addItem("");
|
||||
for (int i = 0; i < zhuhuhuzhuymlist.size(); i++) {
|
||||
huzhuymcomboBox.addItem(zhuhuhuzhuymlist.get(i).getHuzhudxy());
|
||||
}
|
||||
panel.add(huzhuymcomboBox);
|
||||
|
||||
|
||||
|
||||
panel.setBounds(10, 10, 607, 120);
|
||||
JButton button = new JButton("添加");
|
||||
/**
|
||||
新增按钮触发事件
|
||||
*/
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Shouruqingkuangym bean=new Shouruqingkuangym();
|
||||
bean.setMingxiym(mingxiymtextField.getText());
|
||||
|
||||
bean.setFashengriqiym(fashengriqiymtextField.getText());
|
||||
|
||||
bean.setFashengfeiyongym(fashengfeiyongymtextField.getText());
|
||||
|
||||
if(huzhuymcomboBox.getSelectedItem()!=null){
|
||||
bean.setHuzhuym(huzhuymcomboBox.getSelectedItem().toString());
|
||||
}else{
|
||||
bean.setHuzhuym("");
|
||||
}
|
||||
|
||||
|
||||
dao.create(bean);
|
||||
JOptionPane.showMessageDialog(null, "添加成功");
|
||||
if(mui!=null)
|
||||
mui.refresh(dao.findAll());
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button.setBounds(173, 550, 93, 47);
|
||||
contentPane.add(button);
|
||||
|
||||
JButton button_1 = new JButton("取消");
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button_1.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button_1.setBounds(334, 550, 93, 47);
|
||||
contentPane.add(button_1);
|
||||
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
public String getRadioValue(JPanel panel){
|
||||
for(Component c:panel.getComponents()){
|
||||
if(c instanceof JRadioButton){
|
||||
if(((JRadioButton) c).isSelected()){
|
||||
return ((JRadioButton)c).getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
package com.ym.view;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
public class ShouruqingkuangManageUI extends JFrame{
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ShouruqingkuangManageUI().setVisible(true);
|
||||
}
|
||||
public ShouruqingkuangManageUI() {
|
||||
setTitle("收入情况管理");
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 879, 665);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
add(new ShouruqingkuangManageUIListPanel(""), BorderLayout.CENTER);
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,176 +0,0 @@
|
||||
package com.ym.view;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import com.ym.dao.ShouruqingkuangymDao;
|
||||
//import dao.ZhuhuDao;
|
||||
import com.ym.dao.impl.ShouruqingkuangymImpl;
|
||||
//import dao.impl.ZhuhuImpl;
|
||||
import com.ym.entity.Shouruqingkuangym;
|
||||
|
||||
public class ShouruqingkuangManageUIListPanel extends JPanel implements Tableinter{
|
||||
ShouruqingkuangymDao dao = new ShouruqingkuangymImpl();
|
||||
//ZhuhuDao zhuhuhuzhuymdao = new ZhuhuImpl();
|
||||
private JPanel contentPane;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static String[] columnCount = { "id","明细","发生日期","发生费用","户主" };
|
||||
public JTable table;
|
||||
private static DefaultTableModel tableModel;
|
||||
private String mainid;
|
||||
|
||||
public ShouruqingkuangManageUIListPanel(String mainid) {
|
||||
this.mainid=mainid;
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
add(contentPane);
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
contentPane.add(scrollPane, BorderLayout.CENTER);
|
||||
table = new JTable();
|
||||
scrollPane.setViewportView(table);
|
||||
JPanel toppanel = new JPanel();
|
||||
contentPane.add(toppanel, BorderLayout.NORTH);
|
||||
toppanel.setLayout(new GridLayout(2, 1, 0, 0));
|
||||
JPanel btnpanel = new JPanel();
|
||||
btnpanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
|
||||
toppanel.add(btnpanel);
|
||||
|
||||
|
||||
JButton button = new JButton("添加");
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
new ShouruqingkuangAddUI(me()).setVisible(true);
|
||||
}
|
||||
});
|
||||
btnpanel.add(button);
|
||||
|
||||
JButton button_1 = new JButton("删除");
|
||||
/**
|
||||
删除操作
|
||||
*/
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int row = table.getSelectedRow();
|
||||
if (row == -1) {
|
||||
JOptionPane.showMessageDialog(null, "请选择一行进行删除");
|
||||
return;
|
||||
}
|
||||
String keyvalue = (String) table.getValueAt(row, 0);
|
||||
/**
|
||||
根据主键进行查询,如果查询到则删除
|
||||
*/
|
||||
Shouruqingkuangym sf=new Shouruqingkuangym();
|
||||
sf.setId(Integer.valueOf(keyvalue));
|
||||
dao.remove(sf);
|
||||
JOptionPane.showMessageDialog(null, "删除成功");
|
||||
refresh(dao.findAll());
|
||||
}
|
||||
});
|
||||
btnpanel.add(button_1);
|
||||
|
||||
JButton button_2 = new JButton("修改");
|
||||
/**
|
||||
修改操作
|
||||
*/
|
||||
button_2.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int row = table.getSelectedRow();
|
||||
if (row == -1) {
|
||||
JOptionPane.showMessageDialog(null, "请选择一行进行修改");
|
||||
return;
|
||||
}
|
||||
//跳转到修改页面
|
||||
new ShouruqingkuangUpdateUI(me()).setVisible(true);
|
||||
}
|
||||
|
||||
});
|
||||
btnpanel.add(button_2);
|
||||
refresh(dao.findAll());
|
||||
}
|
||||
public ShouruqingkuangManageUIListPanel me(){
|
||||
return this;
|
||||
}
|
||||
//刷新表格列表
|
||||
public void refresh(List list){
|
||||
|
||||
|
||||
tableModel = new DefaultTableModel(transferList(list), columnCount){
|
||||
public Class getColumnClass(int column) {
|
||||
Vector<?> v = (Vector<?>) dataVector.elementAt(0);
|
||||
if(v.elementAt(column)!=null){
|
||||
return v.elementAt(column).getClass();
|
||||
}else{
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
Class<?> columnClass = getColumnClass(col);
|
||||
return columnClass != ImageIcon.class;
|
||||
}
|
||||
};
|
||||
table.setModel(tableModel);
|
||||
|
||||
|
||||
updateRowHeights();
|
||||
}
|
||||
//自动调整列高
|
||||
private void updateRowHeights()
|
||||
{
|
||||
for (int row = 0; row < table.getRowCount(); row++)
|
||||
{
|
||||
int rowHeight = table.getRowHeight();
|
||||
|
||||
for (int column = 0; column < table.getColumnCount(); column++)
|
||||
{
|
||||
Component comp = table.prepareRenderer(table.getCellRenderer(row, column), row, column);
|
||||
rowHeight = Math.max(rowHeight, comp.getPreferredSize().height);
|
||||
}
|
||||
table.setRowHeight(row, rowHeight);
|
||||
}
|
||||
}
|
||||
//将实体列表转换为表格实体
|
||||
public static Object[][] transferList(List<Shouruqingkuangym> list) {
|
||||
Object[][] olist = new Object[list.size()][];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Object str[] = {list.get(i).getId().toString(), list.get(i).getMingxiym(),list.get(i).getFashengriqiym(),list.get(i).getFashengfeiyongym(),list.get(i).getHuzhuym() };
|
||||
//如果包含图片格式则以图片形式显示
|
||||
for (int j = 0; j < str.length; j++) {
|
||||
if(str[j]!=null&&(str[j].toString().contains("png")||str[j].toString().contains("jpg")||str[j].toString().contains("gif"))){
|
||||
str[j]=new ImageIcon(new ImageIcon(str[j].toString()).getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT));
|
||||
}
|
||||
}
|
||||
olist[i] = str;
|
||||
}
|
||||
|
||||
return olist;
|
||||
}
|
||||
public JTable getTable() {
|
||||
return table;
|
||||
}
|
||||
public String getMainid(){
|
||||
return mainid;
|
||||
}
|
||||
}
|
||||
@ -1,162 +0,0 @@
|
||||
package com.ym.view;
|
||||
|
||||
import java.awt.Component;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import com.eltima.components.ui.DatePicker;
|
||||
import com.ym.dao.ShouruqingkuangymDao;
|
||||
//import dao.ZhuhuDao;
|
||||
import com.ym.dao.impl.ShouruqingkuangymImpl;
|
||||
//import dao.impl.ZhuhuImpl;
|
||||
import com.ym.entity.Shouruqingkuangym;
|
||||
//import entity.Zhuhu;
|
||||
public class ShouruqingkuangUpdateUI extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
|
||||
|
||||
ShouruqingkuangymDao dao = new ShouruqingkuangymImpl();
|
||||
//ZhuhuDao zhuhuhuzhuymdao = new ZhuhuImpl();
|
||||
public ShouruqingkuangUpdateUI() {
|
||||
init(null);
|
||||
}
|
||||
public ShouruqingkuangUpdateUI(Tableinter mui) {
|
||||
init(mui);
|
||||
}
|
||||
public void init(Tableinter mui) {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 643, 646);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
Shouruqingkuangym shouruqingkuang = dao.findByIdym((String) mui.getTable().getValueAt(mui.getTable().getSelectedRow(), 0));
|
||||
JPanel panel = new BackgroundPanel();
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(new GridLayout(0, 2, 0, 0));
|
||||
JLabel idlabel = new JLabel("id");
|
||||
idlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(idlabel);
|
||||
JTextField idtextField = new JTextField(shouruqingkuang.getId().toString());
|
||||
idtextField.setEnabled(false);
|
||||
panel.add(idtextField);
|
||||
JLabel mingxiymlabel = new JLabel("明细");
|
||||
mingxiymlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(mingxiymlabel);
|
||||
JTextField mingxiymtextField = new JTextField(shouruqingkuang.getMingxiym());
|
||||
panel.add(mingxiymtextField);
|
||||
|
||||
JLabel fashengriqiymlabel = new JLabel("发生日期");
|
||||
fashengriqiymlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(fashengriqiymlabel);
|
||||
DatePicker fashengriqiymtextField = new DatePicker(this);
|
||||
fashengriqiymtextField.setPattern("yyyy-MM-dd");
|
||||
fashengriqiymtextField.setTimePanleVisible(true);
|
||||
fashengriqiymtextField.setEditorable(false);
|
||||
try {
|
||||
fashengriqiymtextField.setDate(new SimpleDateFormat("yyyy-MM-dd").parse(shouruqingkuang.getFashengriqiym()));
|
||||
} catch (ParseException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
panel.add(fashengriqiymtextField);
|
||||
|
||||
JLabel fashengfeiyongymlabel = new JLabel("发生费用");
|
||||
fashengfeiyongymlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(fashengfeiyongymlabel);
|
||||
JTextField fashengfeiyongymtextField = new JTextField(shouruqingkuang.getFashengfeiyongym());
|
||||
panel.add(fashengfeiyongymtextField);
|
||||
|
||||
JLabel huzhuymlabel = new JLabel("户主");
|
||||
huzhuymlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(huzhuymlabel);
|
||||
|
||||
JComboBox huzhuymcomboBox = new JComboBox();
|
||||
//List<Zhuhu> zhuhuhuzhuymlist=zhuhuhuzhuymdao.findAll();
|
||||
huzhuymcomboBox.addItem("");
|
||||
for (int i = 0; i < zhuhuhuzhuymlist.size(); i++) {
|
||||
huzhuymcomboBox.addItem(zhuhuhuzhuymlist.get(i).getHuzhudxy());
|
||||
}
|
||||
huzhuymcomboBox.setSelectedItem(shouruqingkuang.getHuzhuym());
|
||||
panel.add(huzhuymcomboBox);
|
||||
|
||||
|
||||
|
||||
panel.setBounds(10, 10, 607, 150);
|
||||
JButton button = new JButton("修改");
|
||||
/**
|
||||
修改按钮触发事件
|
||||
*/
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
||||
Shouruqingkuangym bean=new Shouruqingkuangym();
|
||||
bean.setMingxiym(mingxiymtextField.getText());
|
||||
|
||||
bean.setFashengriqiym(fashengriqiymtextField.getText());
|
||||
|
||||
bean.setFashengfeiyongym(fashengfeiyongymtextField.getText());
|
||||
|
||||
if(huzhuymcomboBox.getSelectedItem()!=null){
|
||||
bean.setHuzhuym(huzhuymcomboBox.getSelectedItem().toString());
|
||||
}else{
|
||||
bean.setHuzhuym("");
|
||||
}
|
||||
|
||||
bean.setId(Integer.valueOf(idtextField.getText()));
|
||||
|
||||
|
||||
dao.modify(bean);
|
||||
JOptionPane.showMessageDialog(null, "修改成功");
|
||||
//刷新主界面列表
|
||||
if(mui!=null)
|
||||
mui.refresh(dao.findAll());
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button.setBounds(173, 550, 93, 47);
|
||||
contentPane.add(button);
|
||||
|
||||
JButton button_1 = new JButton("取消");
|
||||
/**
|
||||
取消按钮触发事件
|
||||
*/
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button_1.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button_1.setBounds(334, 550, 93, 47);
|
||||
contentPane.add(button_1);
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
public String getRadioValue(JPanel panel){
|
||||
for(Component c:panel.getComponents()){
|
||||
if(c instanceof JRadioButton){
|
||||
if(((JRadioButton) c).isSelected()){
|
||||
return ((JRadioButton)c).getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,153 @@
|
||||
package com.ym.dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.ym.dao.ShouruqingkuangymDao;
|
||||
import com.ym.entity.Shouruqingkuangym;
|
||||
|
||||
public class ShouruqingkuangymImpl implements ShouruqingkuangymDao{
|
||||
|
||||
public Shouruqingkuangym findById(String id) {
|
||||
Shouruqingkuangym acym=new Shouruqingkuangym();
|
||||
try {
|
||||
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sql = "select*from shouruqingkuang where id = ?";
|
||||
PreparedStatement prestm=conn.prepareStatement(sql);
|
||||
prestm.setInt(1, Integer.valueOf(id));
|
||||
ResultSet rs=prestm.executeQuery();
|
||||
|
||||
while(rs.next()) {
|
||||
Shouruqingkuangym shouruqingkuang=new Shouruqingkuangym();
|
||||
shouruqingkuang.setId(rs.getInt("id"));
|
||||
shouruqingkuang.setFashengfeiyongym(rs.getString("fashengfeiyongym"));
|
||||
shouruqingkuang.setFashengriqiym(rs.getString("fashengriqiym"));
|
||||
shouruqingkuang.setHuzhuym(rs.getString("huzhuym"));
|
||||
shouruqingkuang.setMingxiym(rs.getString("mingxiym"));
|
||||
acym=shouruqingkuang;
|
||||
}
|
||||
rs.close();
|
||||
prestm.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return acym;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Shouruqingkuangym> findAll() {
|
||||
ArrayList<Shouruqingkuangym> zhushus=new ArrayList<Shouruqingkuangym>();
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
|
||||
String sqlym ="select *from shouruqingkuang";
|
||||
Statement stsym =conn.createStatement();
|
||||
ResultSet rs=stsym.executeQuery(sqlym);
|
||||
|
||||
while(rs.next()) {
|
||||
Shouruqingkuangym shouruqingkuang=new Shouruqingkuangym();
|
||||
shouruqingkuang.setId(rs.getInt("id"));
|
||||
shouruqingkuang.setFashengfeiyongym(rs.getString("fashengfeiyongym"));
|
||||
shouruqingkuang.setFashengriqiym(rs.getString("fashengriqiym"));
|
||||
shouruqingkuang.setHuzhuym(rs.getString("huzhuym"));
|
||||
shouruqingkuang.setMingxiym(rs.getString("mingxiym"));
|
||||
zhushus.add(shouruqingkuang);
|
||||
}
|
||||
rs.close();
|
||||
stsym.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// TODO 自动生成的方法存根
|
||||
return zhushus;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int modify(Shouruqingkuangym shouruqingkuang) {
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
|
||||
String sqlym ="update shouruqingkuang set fashengfeiyongym=?,fashengriqiym=?,huzhuym=?,mingxiym=? where id=?";
|
||||
PreparedStatement prestmym=conn.prepareStatement(sqlym);
|
||||
prestmym.setString(1,shouruqingkuang.getFashengfeiyongym());
|
||||
prestmym.setString(2,shouruqingkuang.getFashengriqiym());
|
||||
prestmym.setString(3,shouruqingkuang.getHuzhuym());
|
||||
prestmym.setString(4,shouruqingkuang.getMingxiym());
|
||||
prestmym.setInt(5,shouruqingkuang.getId());
|
||||
prestmym.executeUpdate();
|
||||
prestmym.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int create(Shouruqingkuangym shouruqingkuang) {
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sqlym ="Insert into shouruqingkuang (fashengfeiyongym,fashengriqiym,huzhuym,mingxiym) values(?,?,?,?)";
|
||||
PreparedStatement prestmym=conn.prepareStatement(sqlym);
|
||||
prestmym.setString(1,shouruqingkuang.getFashengfeiyongym());
|
||||
prestmym.setString(2,shouruqingkuang.getFashengriqiym());
|
||||
prestmym.setString(3,shouruqingkuang.getHuzhuym());
|
||||
prestmym.setString(4,shouruqingkuang.getMingxiym());
|
||||
prestmym.executeUpdate();
|
||||
prestmym.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int remove(Shouruqingkuangym shouruqingkuang) {
|
||||
int flagym=0;
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sqlym ="delete from shouruqingkuang where id=?";
|
||||
PreparedStatement prestmym=conn.prepareStatement(sqlym);
|
||||
prestmym.setInt(1, shouruqingkuang.getId());
|
||||
flagym = prestmym.executeUpdate();
|
||||
prestmym.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flagym;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Shouruqingkuangym findByIdym(String idym) {
|
||||
// TODO 自动生成的方法存根
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Shouruqingkuangym findByUsername(String text) {
|
||||
// TODO 自动生成的方法存根
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,141 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import com.eltima.components.ui.DatePicker;
|
||||
|
||||
import dao.ZhichuqingkuangDao;
|
||||
import dao.ZhuhuDao;
|
||||
import dao.impl.ZhichuqingkuangImpl;
|
||||
import dao.impl.ZhuhuImpl;
|
||||
import entity.Zhichuqingkuang;
|
||||
import entity.Zhuhu;
|
||||
|
||||
public class ZhichuqingkuangAddUI extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
ZhichuqingkuangDao dao = new ZhichuqingkuangImpl();
|
||||
ZhuhuDao zhuhuhuzhuhssdao = new ZhuhuImpl();
|
||||
public ZhichuqingkuangAddUI() {
|
||||
init(null);
|
||||
}
|
||||
public ZhichuqingkuangAddUI(Tableinter mui) {
|
||||
init(mui);
|
||||
}
|
||||
public void init(Tableinter mui) {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 643, 646);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
JPanel panel = new JPanel();
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(new GridLayout(0, 2, 0, 0));
|
||||
JLabel mingxihsslabel = new JLabel("明细");
|
||||
mingxihsslabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(mingxihsslabel);
|
||||
JTextField mingxihsstextField = new JTextField();
|
||||
panel.add(mingxihsstextField);
|
||||
|
||||
JLabel fashengriqihsslabel = new JLabel("发生日期");
|
||||
fashengriqihsslabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(fashengriqihsslabel);
|
||||
DatePicker fashengriqihsstextField = new DatePicker(this);
|
||||
fashengriqihsstextField.setPattern("yyyy-MM-dd");
|
||||
fashengriqihsstextField.setTimePanleVisible(true);
|
||||
fashengriqihsstextField.setEditorable(false);
|
||||
panel.add(fashengriqihsstextField);
|
||||
|
||||
JLabel fashengfeiyonghsslabel = new JLabel("发生费用");
|
||||
fashengfeiyonghsslabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(fashengfeiyonghsslabel);
|
||||
JTextField fashengfeiyonghsstextField = new JTextField();
|
||||
panel.add(fashengfeiyonghsstextField);
|
||||
|
||||
JLabel huzhuhsslabel = new JLabel("户主");
|
||||
huzhuhsslabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(huzhuhsslabel);
|
||||
|
||||
JComboBox huzhuhsscomboBox = new JComboBox();
|
||||
List<Zhuhu> zhuhuhuzhuhsslist=zhuhuhuzhuhssdao.findAll();
|
||||
huzhuhsscomboBox.addItem("");
|
||||
for (int i = 0; i < zhuhuhuzhuhsslist.size(); i++) {
|
||||
huzhuhsscomboBox.addItem(zhuhuhuzhuhsslist.get(i).getHuzhudxy());
|
||||
}
|
||||
panel.add(huzhuhsscomboBox);
|
||||
|
||||
|
||||
|
||||
panel.setBounds(10, 10, 607, 120);
|
||||
JButton button = new JButton("添加");
|
||||
/**
|
||||
新增按钮触发事件
|
||||
*/
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Zhichuqingkuang bean=new Zhichuqingkuang();
|
||||
bean.setMingxihss(mingxihsstextField.getText());
|
||||
|
||||
bean.setFashengriqihss(fashengriqihsstextField.getText());
|
||||
|
||||
bean.setFashengfeiyonghss(fashengfeiyonghsstextField.getText());
|
||||
|
||||
if(huzhuhsscomboBox.getSelectedItem()!=null){
|
||||
bean.setHuzhuhss(huzhuhsscomboBox.getSelectedItem().toString());
|
||||
}else{
|
||||
bean.setHuzhuhss("");
|
||||
}
|
||||
|
||||
|
||||
dao.create(bean);
|
||||
JOptionPane.showMessageDialog(null, "添加成功");
|
||||
if(mui!=null)
|
||||
mui.refresh(dao.findAll());
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button.setBounds(173, 550, 93, 47);
|
||||
contentPane.add(button);
|
||||
|
||||
JButton button_1 = new JButton("取消");
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button_1.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button_1.setBounds(334, 550, 93, 47);
|
||||
contentPane.add(button_1);
|
||||
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
public String getRadioValue(JPanel panel){
|
||||
for(Component c:panel.getComponents()){
|
||||
if(c instanceof JRadioButton){
|
||||
if(((JRadioButton) c).isSelected()){
|
||||
return ((JRadioButton)c).getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,139 @@
|
||||
package dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dao.ZhichuqingkuangDao;
|
||||
import entity.Zhichuqingkuang;
|
||||
|
||||
public class ZhichuqingkuangImpl implements ZhichuqingkuangDao{
|
||||
|
||||
|
||||
public Zhichuqingkuang findById(String id) {
|
||||
Zhichuqingkuang achss=new Zhichuqingkuang();
|
||||
try {
|
||||
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sqlhss = "select*from zhichuqingkuang where id = ?";
|
||||
PreparedStatement prestm=conn.prepareStatement(sqlhss);
|
||||
prestm.setInt(1, Integer.valueOf(id));
|
||||
ResultSet rs=prestm.executeQuery();
|
||||
|
||||
while(rs.next()) {
|
||||
Zhichuqingkuang zhichuqingkuang=new Zhichuqingkuang();
|
||||
zhichuqingkuang.setId(rs.getInt("id"));
|
||||
zhichuqingkuang.setFashengfeiyonghss(rs.getString("fashengfeiyonghss"));
|
||||
zhichuqingkuang.setFashengriqihss(rs.getString("fashengriqihss"));
|
||||
zhichuqingkuang.setHuzhuhss(rs.getString("huzhuhss"));
|
||||
zhichuqingkuang.setMingxihss(rs.getString("mingxihss"));
|
||||
achss=zhichuqingkuang;
|
||||
}
|
||||
rs.close();
|
||||
prestm.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return achss;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Zhichuqingkuang> findAll() {
|
||||
ArrayList<Zhichuqingkuang> zhushus=new ArrayList<Zhichuqingkuang>();
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
|
||||
String sqlhss ="select *from zhichuqingkuang";
|
||||
Statement stshss =conn.createStatement();
|
||||
ResultSet rs=stshss.executeQuery(sqlhss);
|
||||
|
||||
while(rs.next()) {
|
||||
Zhichuqingkuang zhichuqingkuang=new Zhichuqingkuang();
|
||||
zhichuqingkuang.setId(rs.getInt("id"));
|
||||
zhichuqingkuang.setFashengfeiyonghss(rs.getString("fashengfeiyonghss"));
|
||||
zhichuqingkuang.setFashengriqihss(rs.getString("fashengriqihss"));
|
||||
zhichuqingkuang.setHuzhuhss(rs.getString("huzhuhss"));
|
||||
zhichuqingkuang.setMingxihss(rs.getString("mingxihss"));
|
||||
zhushus.add(zhichuqingkuang);
|
||||
}
|
||||
rs.close();
|
||||
stshss.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// TODO 自动生成的方法存根
|
||||
return zhushus;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int modify(Zhichuqingkuang zhichuqingkuang) {
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
|
||||
String sqlhss ="update zhichuqingkuang set fashengfeiyonghss=?,fashengriqihss=?,huzhuhss=?,mingxihss=? where id=?";
|
||||
PreparedStatement prestmhss=conn.prepareStatement(sqlhss);
|
||||
prestmhss.setString(1,zhichuqingkuang.getFashengfeiyonghss());
|
||||
prestmhss.setString(2,zhichuqingkuang.getFashengriqihss());
|
||||
prestmhss.setString(3,zhichuqingkuang.getHuzhuhss());
|
||||
prestmhss.setString(4,zhichuqingkuang.getMingxihss());
|
||||
prestmhss.setInt(5,zhichuqingkuang.getId());
|
||||
prestmhss.executeUpdate();
|
||||
prestmhss.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int create(Zhichuqingkuang zhichuqingkuang) {
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sqlhss ="Insert into zhichuqingkuang (fashengfeiyonghss,fashengriqihss,huzhuhss,mingxihss) values(?,?,?,?)";
|
||||
PreparedStatement prestmhss=conn.prepareStatement(sqlhss);
|
||||
prestmhss.setString(1,zhichuqingkuang.getFashengfeiyonghss());
|
||||
prestmhss.setString(2,zhichuqingkuang.getFashengriqihss());
|
||||
prestmhss.setString(3,zhichuqingkuang.getHuzhuhss());
|
||||
prestmhss.setString(4,zhichuqingkuang.getMingxihss());
|
||||
prestmhss.executeUpdate();
|
||||
prestmhss.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int remove(Zhichuqingkuang zhichuqingkuang) {
|
||||
int flaghss=0;
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sqlhss ="delete from zhichuqingkuang where id=?";
|
||||
PreparedStatement prestmhss=conn.prepareStatement(sqlhss);
|
||||
prestmhss.setInt(1, zhichuqingkuang.getId());
|
||||
flaghss = prestmhss.executeUpdate();
|
||||
prestmhss.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flaghss;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
public class ZhichuqingkuangManageUI extends JFrame{
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ZhichuqingkuangManageUI().setVisible(true);
|
||||
}
|
||||
public ZhichuqingkuangManageUI() {
|
||||
setTitle("支出情况管理");
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 879, 665);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
add(new ZhichuqingkuangManageUIListPanel(""), BorderLayout.CENTER);
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,175 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import dao.ZhichuqingkuangDao;
|
||||
import dao.ZhuhuDao;
|
||||
import dao.impl.ZhichuqingkuangImpl;
|
||||
import dao.impl.ZhuhuImpl;
|
||||
import entity.Zhichuqingkuang;
|
||||
|
||||
public class ZhichuqingkuangManageUIListPanel extends JPanel implements Tableinter{
|
||||
ZhichuqingkuangDao dao = new ZhichuqingkuangImpl();
|
||||
ZhuhuDao zhuhuhuzhuhssdao = new ZhuhuImpl();
|
||||
private JPanel contentPane;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static String[] columnCount = { "id","明细","发生日期","发生费用","户主" };
|
||||
public JTable table;
|
||||
private static DefaultTableModel tableModel;
|
||||
private String mainid;
|
||||
|
||||
public ZhichuqingkuangManageUIListPanel(String mainid) {
|
||||
this.mainid=mainid;
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
add(contentPane);
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
contentPane.add(scrollPane, BorderLayout.CENTER);
|
||||
table = new JTable();
|
||||
scrollPane.setViewportView(table);
|
||||
JPanel toppanel = new JPanel();
|
||||
contentPane.add(toppanel, BorderLayout.NORTH);
|
||||
toppanel.setLayout(new GridLayout(2, 1, 0, 0));
|
||||
JPanel btnpanel = new JPanel();
|
||||
btnpanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
|
||||
toppanel.add(btnpanel);
|
||||
|
||||
|
||||
JButton button = new JButton("添加");
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
new ZhichuqingkuangAddUI(me()).setVisible(true);
|
||||
}
|
||||
});
|
||||
btnpanel.add(button);
|
||||
|
||||
JButton button_1 = new JButton("删除");
|
||||
/**
|
||||
删除操作
|
||||
*/
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int row = table.getSelectedRow();
|
||||
if (row == -1) {
|
||||
JOptionPane.showMessageDialog(null, "请选择一行进行删除");
|
||||
return;
|
||||
}
|
||||
String keyvalue = (String) table.getValueAt(row, 0);
|
||||
/**
|
||||
根据主键进行查询,如果查询到则删除
|
||||
*/
|
||||
Zhichuqingkuang zx=new Zhichuqingkuang();
|
||||
zx.setId(Integer.valueOf(keyvalue));
|
||||
dao.remove(zx);
|
||||
JOptionPane.showMessageDialog(null, "删除成功");
|
||||
refresh(dao.findAll());
|
||||
}
|
||||
});
|
||||
btnpanel.add(button_1);
|
||||
|
||||
JButton button_2 = new JButton("修改");
|
||||
/**
|
||||
修改操作
|
||||
*/
|
||||
button_2.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int row = table.getSelectedRow();
|
||||
if (row == -1) {
|
||||
JOptionPane.showMessageDialog(null, "请选择一行进行修改");
|
||||
return;
|
||||
}
|
||||
//跳转到修改页面
|
||||
new ZhichuqingkuangUpdateUI(me()).setVisible(true);
|
||||
}
|
||||
|
||||
});
|
||||
btnpanel.add(button_2);
|
||||
refresh(dao.findAll());
|
||||
}
|
||||
public ZhichuqingkuangManageUIListPanel me(){
|
||||
return this;
|
||||
}
|
||||
//刷新表格列表
|
||||
public void refresh(List list){
|
||||
|
||||
|
||||
tableModel = new DefaultTableModel(transferList(list), columnCount){
|
||||
public Class getColumnClass(int column) {
|
||||
Vector<?> v = (Vector<?>) dataVector.elementAt(0);
|
||||
if(v.elementAt(column)!=null){
|
||||
return v.elementAt(column).getClass();
|
||||
}else{
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
Class<?> columnClass = getColumnClass(col);
|
||||
return columnClass != ImageIcon.class;
|
||||
}
|
||||
};
|
||||
table.setModel(tableModel);
|
||||
|
||||
|
||||
updateRowHeights();
|
||||
}
|
||||
//自动调整列高
|
||||
private void updateRowHeights()
|
||||
{
|
||||
for (int row = 0; row < table.getRowCount(); row++)
|
||||
{
|
||||
int rowHeight = table.getRowHeight();
|
||||
|
||||
for (int column = 0; column < table.getColumnCount(); column++)
|
||||
{
|
||||
Component comp = table.prepareRenderer(table.getCellRenderer(row, column), row, column);
|
||||
rowHeight = Math.max(rowHeight, comp.getPreferredSize().height);
|
||||
}
|
||||
table.setRowHeight(row, rowHeight);
|
||||
}
|
||||
}
|
||||
//将实体列表转换为表格实体
|
||||
public static Object[][] transferList(List<Zhichuqingkuang> list) {
|
||||
Object[][] olist = new Object[list.size()][];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Object str[] = {list.get(i).getId().toString(), list.get(i).getMingxihss(),list.get(i).getFashengriqihss(),list.get(i).getFashengfeiyonghss(),list.get(i).getHuzhuhss() };
|
||||
//如果包含图片格式则以图片形式显示
|
||||
for (int j = 0; j < str.length; j++) {
|
||||
if(str[j]!=null&&(str[j].toString().contains("png")||str[j].toString().contains("jpg")||str[j].toString().contains("gif"))){
|
||||
str[j]=new ImageIcon(new ImageIcon(str[j].toString()).getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT));
|
||||
}
|
||||
}
|
||||
olist[i] = str;
|
||||
}
|
||||
|
||||
return olist;
|
||||
}
|
||||
public JTable getTable() {
|
||||
return table;
|
||||
}
|
||||
public String getMainid(){
|
||||
return mainid;
|
||||
}
|
||||
}
|
||||
@ -1,163 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import com.eltima.components.ui.DatePicker;
|
||||
|
||||
import dao.ZhichuqingkuangDao;
|
||||
import dao.ZhuhuDao;
|
||||
import dao.impl.ZhichuqingkuangImpl;
|
||||
import dao.impl.ZhuhuImpl;
|
||||
import entity.Zhichuqingkuang;
|
||||
import entity.Zhuhu;
|
||||
public class ZhichuqingkuangUpdateUI extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
|
||||
|
||||
ZhichuqingkuangDao dao = new ZhichuqingkuangImpl();
|
||||
ZhuhuDao zhuhuhuzhuhssdao = new ZhuhuImpl();
|
||||
public ZhichuqingkuangUpdateUI() {
|
||||
init(null);
|
||||
}
|
||||
public ZhichuqingkuangUpdateUI(Tableinter mui) {
|
||||
init(mui);
|
||||
}
|
||||
public void init(Tableinter mui) {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 643, 646);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
Zhichuqingkuang zhichuqingkuang = dao.findById( (String) mui.getTable().getValueAt(mui.getTable().getSelectedRow(), 0));
|
||||
JPanel panel = new BackgroundPanel();
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(new GridLayout(0, 2, 0, 0));
|
||||
JLabel idlabel = new JLabel("id");
|
||||
idlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(idlabel);
|
||||
JTextField idtextField = new JTextField(zhichuqingkuang.getId().toString());
|
||||
idtextField.setEnabled(false);
|
||||
panel.add(idtextField);
|
||||
JLabel mingxihsslabel = new JLabel("明细");
|
||||
mingxihsslabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(mingxihsslabel);
|
||||
JTextField mingxihsstextField = new JTextField(zhichuqingkuang.getMingxihss());
|
||||
panel.add(mingxihsstextField);
|
||||
|
||||
JLabel fashengriqihsslabel = new JLabel("发生日期");
|
||||
fashengriqihsslabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(fashengriqihsslabel);
|
||||
DatePicker fashengriqihsstextField = new DatePicker(this);
|
||||
fashengriqihsstextField.setPattern("yyyy-MM-dd");
|
||||
fashengriqihsstextField.setTimePanleVisible(true);
|
||||
fashengriqihsstextField.setEditorable(false);
|
||||
try {
|
||||
fashengriqihsstextField.setDate(new SimpleDateFormat("yyyy-MM-dd").parse(zhichuqingkuang.getFashengriqihss()));
|
||||
} catch (ParseException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
panel.add(fashengriqihsstextField);
|
||||
|
||||
JLabel fashengfeiyonghsslabel = new JLabel("发生费用");
|
||||
fashengfeiyonghsslabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(fashengfeiyonghsslabel);
|
||||
JTextField fashengfeiyonghsstextField = new JTextField(zhichuqingkuang.getFashengfeiyonghss());
|
||||
panel.add(fashengfeiyonghsstextField);
|
||||
|
||||
JLabel huzhuhsslabel = new JLabel("户主");
|
||||
huzhuhsslabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(huzhuhsslabel);
|
||||
|
||||
JComboBox huzhuhsscomboBox = new JComboBox();
|
||||
List<Zhuhu> zhuhuhuzhuhsslist=zhuhuhuzhuhssdao.findAll();
|
||||
huzhuhsscomboBox.addItem("");
|
||||
for (int i = 0; i < zhuhuhuzhuhsslist.size(); i++) {
|
||||
huzhuhsscomboBox.addItem(zhuhuhuzhuhsslist.get(i).getHuzhudxy());
|
||||
}
|
||||
huzhuhsscomboBox.setSelectedItem(zhichuqingkuang.getHuzhuhss());
|
||||
panel.add(huzhuhsscomboBox);
|
||||
|
||||
|
||||
|
||||
panel.setBounds(10, 10, 607, 150);
|
||||
JButton button = new JButton("修改");
|
||||
/**
|
||||
修改按钮触发事件
|
||||
*/
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
||||
Zhichuqingkuang bean=new Zhichuqingkuang();
|
||||
bean.setMingxihss(mingxihsstextField.getText());
|
||||
|
||||
bean.setFashengriqihss(fashengriqihsstextField.getText());
|
||||
|
||||
bean.setFashengfeiyonghss(fashengfeiyonghsstextField.getText());
|
||||
|
||||
if(huzhuhsscomboBox.getSelectedItem()!=null){
|
||||
bean.setHuzhuhss(huzhuhsscomboBox.getSelectedItem().toString());
|
||||
}else{
|
||||
bean.setHuzhuhss("");
|
||||
}
|
||||
|
||||
bean.setId(Integer.valueOf(idtextField.getText()));
|
||||
|
||||
|
||||
dao.modify(bean);
|
||||
JOptionPane.showMessageDialog(null, "修改成功");
|
||||
//刷新主界面列表
|
||||
if(mui!=null)
|
||||
mui.refresh(dao.findAll());
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button.setBounds(173, 550, 93, 47);
|
||||
contentPane.add(button);
|
||||
|
||||
JButton button_1 = new JButton("取消");
|
||||
/**
|
||||
取消按钮触发事件
|
||||
*/
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button_1.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button_1.setBounds(334, 550, 93, 47);
|
||||
contentPane.add(button_1);
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
public String getRadioValue(JPanel panel){
|
||||
for(Component c:panel.getComponents()){
|
||||
if(c instanceof JRadioButton){
|
||||
if(((JRadioButton) c).isSelected()){
|
||||
return ((JRadioButton)c).getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -1,112 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import dao.ZhuhuDao;
|
||||
import dao.impl.ZhuhuImpl;
|
||||
import entity.Zhuhu;
|
||||
|
||||
|
||||
public class ZhuhuAddUI extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
ZhuhuDao dao = new ZhuhuImpl();
|
||||
public ZhuhuAddUI() {
|
||||
init(null);
|
||||
}
|
||||
public ZhuhuAddUI(Tableinter mui) {
|
||||
init(mui);
|
||||
}
|
||||
public void init(Tableinter mui) {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 643, 646);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
JPanel panel = new JPanel();
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(new GridLayout(0, 2, 0, 0));
|
||||
JLabel huzhudxylabel = new JLabel("户主");
|
||||
huzhudxylabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(huzhudxylabel);
|
||||
JTextField huzhudxytextField = new JTextField();
|
||||
panel.add(huzhudxytextField);
|
||||
|
||||
JLabel dizhidxylabel = new JLabel("地址");
|
||||
dizhidxylabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(dizhidxylabel);
|
||||
JTextField dizhidxytextField = new JTextField();
|
||||
panel.add(dizhidxytextField);
|
||||
|
||||
JLabel lianxidianhuadxylabel = new JLabel("联系电话");
|
||||
lianxidianhuadxylabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(lianxidianhuadxylabel);
|
||||
JTextField lianxidianhuadxytextField = new JTextField();
|
||||
panel.add(lianxidianhuadxytextField);
|
||||
|
||||
|
||||
|
||||
panel.setBounds(10, 10, 607, 90);
|
||||
JButton button = new JButton("添加");
|
||||
/**
|
||||
新增按钮触发事件
|
||||
*/
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Zhuhu bean=new Zhuhu();
|
||||
bean.setHuzhudxy(huzhudxytextField.getText());
|
||||
|
||||
bean.setDizhidxy(dizhidxytextField.getText());
|
||||
|
||||
bean.setLianxidianhuadxy(lianxidianhuadxytextField.getText());
|
||||
|
||||
|
||||
dao.create(bean);
|
||||
JOptionPane.showMessageDialog(null, "添加成功");
|
||||
if(mui!=null)
|
||||
mui.refresh(dao.findAll());
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button.setBounds(173, 550, 93, 47);
|
||||
contentPane.add(button);
|
||||
|
||||
JButton button_1 = new JButton("取消");
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button_1.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button_1.setBounds(334, 550, 93, 47);
|
||||
contentPane.add(button_1);
|
||||
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
public String getRadioValue(JPanel panel){
|
||||
for(Component c:panel.getComponents()){
|
||||
if(c instanceof JRadioButton){
|
||||
if(((JRadioButton) c).isSelected()){
|
||||
return ((JRadioButton)c).getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,134 @@
|
||||
package dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dao.ZhuhuDao;
|
||||
import entity.Zhuhu;
|
||||
|
||||
public class ZhuhuImpl implements ZhuhuDao{
|
||||
|
||||
public Zhuhu findById(String id) {
|
||||
Zhuhu acyc=new Zhuhu();
|
||||
try {
|
||||
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sql = "select*from zhuhu where id = ?";
|
||||
PreparedStatement prestm=conn.prepareStatement(sql);
|
||||
prestm.setInt(1, Integer.valueOf(id));
|
||||
ResultSet rs=prestm.executeQuery();
|
||||
|
||||
while(rs.next()) {
|
||||
Zhuhu zhushu=new Zhuhu();
|
||||
zhushu.setId(rs.getInt("id"));
|
||||
zhushu.setDizhidxy(rs.getString("dizhidxy"));
|
||||
zhushu.setHuzhudxy(rs.getString("huzhudxy"));
|
||||
zhushu.setLianxidianhuadxy(rs.getString("lianxidianhuadxy"));
|
||||
acyc=zhushu;
|
||||
}
|
||||
rs.close();
|
||||
prestm.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return acyc;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Zhuhu> findAll() {
|
||||
ArrayList<Zhuhu> zhushus=new ArrayList<Zhuhu>();
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
|
||||
String sqlyc ="select *from zhuhu";
|
||||
Statement stsyc =conn.createStatement();
|
||||
ResultSet rsyc=stsyc.executeQuery(sqlyc);
|
||||
|
||||
while(rsyc.next()) {
|
||||
Zhuhu zhushu=new Zhuhu();
|
||||
zhushu.setId(rsyc.getInt("id"));
|
||||
zhushu.setDizhidxy(rsyc.getString("dizhidxy"));
|
||||
zhushu.setHuzhudxy(rsyc.getString("huzhudxy"));
|
||||
zhushu.setLianxidianhuadxy(rsyc.getString("lianxidianhuadxy"));
|
||||
zhushus.add(zhushu);
|
||||
}
|
||||
rsyc.close();
|
||||
stsyc.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return zhushus;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int modify(Zhuhu zhuhu) {
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
|
||||
String sqlyc ="update zhuhu set huzhudxy=?,dizhidxy=?,lianxidianhuadxy=? where id=?";
|
||||
PreparedStatement prestmyc=conn.prepareStatement(sqlyc);
|
||||
prestmyc.setString(1,zhuhu.getHuzhudxy());
|
||||
prestmyc.setString(2,zhuhu.getDizhidxy());
|
||||
prestmyc.setString(3,zhuhu.getLianxidianhuadxy());
|
||||
prestmyc.setInt(4,zhuhu.getId());
|
||||
prestmyc.executeUpdate();
|
||||
prestmyc.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int create(Zhuhu zhuhu) {
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sqlyc ="Insert into zhuhu (huzhudxy,dizhidxy,lianxidianhuadxy) values(?,?,?)";
|
||||
PreparedStatement prestmyc=conn.prepareStatement(sqlyc);
|
||||
prestmyc.setString(1,zhuhu.getHuzhudxy());
|
||||
prestmyc.setString(2,zhuhu.getDizhidxy());
|
||||
prestmyc.setString(3,zhuhu.getLianxidianhuadxy());
|
||||
prestmyc.executeUpdate();
|
||||
prestmyc.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int remove(Zhuhu zhuhu) {
|
||||
int flagyc=0;
|
||||
try {
|
||||
Connection conn = JDBCUtil.getConnection();
|
||||
String sqlyc ="delete from zhuhu where id=?";
|
||||
PreparedStatement prestmyc=conn.prepareStatement(sqlyc);
|
||||
prestmyc.setInt(1, zhuhu.getId());
|
||||
flagyc = prestmyc.executeUpdate();
|
||||
prestmyc.close();
|
||||
conn.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flagyc;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
public class ZhuhuManageUI extends JFrame{
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ZhuhuManageUI().setVisible(true);
|
||||
}
|
||||
public ZhuhuManageUI() {
|
||||
setTitle("住户管理");
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 879, 665);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
add(new ZhuhuManageUIListPanel(""), BorderLayout.CENTER);
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,172 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import dao.ZhuhuDao;
|
||||
import dao.impl.ZhuhuImpl;
|
||||
import entity.Zhuhu;
|
||||
|
||||
public class ZhuhuManageUIListPanel extends JPanel implements Tableinter{
|
||||
ZhuhuDao dao = new ZhuhuImpl();
|
||||
private JPanel contentPane;
|
||||
|
||||
|
||||
|
||||
|
||||
private static String[] columnCount = { "id","户主","地址","联系电话" };
|
||||
public JTable table;
|
||||
private static DefaultTableModel tableModel;
|
||||
private String mainid;
|
||||
|
||||
public ZhuhuManageUIListPanel(String mainid) {
|
||||
this.mainid=mainid;
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
add(contentPane);
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
contentPane.add(scrollPane, BorderLayout.CENTER);
|
||||
table = new JTable();
|
||||
scrollPane.setViewportView(table);
|
||||
JPanel toppanel = new JPanel();
|
||||
contentPane.add(toppanel, BorderLayout.NORTH);
|
||||
toppanel.setLayout(new GridLayout(2, 1, 0, 0));
|
||||
JPanel btnpanel = new JPanel();
|
||||
btnpanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
|
||||
toppanel.add(btnpanel);
|
||||
|
||||
|
||||
JButton button = new JButton("添加");
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
new ZhuhuAddUI(me()).setVisible(true);
|
||||
}
|
||||
});
|
||||
btnpanel.add(button);
|
||||
|
||||
JButton button_1 = new JButton("删除");
|
||||
/**
|
||||
删除操作
|
||||
*/
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int row = table.getSelectedRow();
|
||||
if (row == -1) {
|
||||
JOptionPane.showMessageDialog(null, "请选择一行进行删除");
|
||||
return;
|
||||
}
|
||||
String keyvalue = (String) table.getValueAt(row, 0);
|
||||
/**
|
||||
根据主键进行查询,如果查询到则删除
|
||||
*/
|
||||
Zhuhu zh=new Zhuhu();
|
||||
zh.setId(Integer.valueOf(keyvalue));
|
||||
dao.remove(zh);
|
||||
JOptionPane.showMessageDialog(null, "删除成功");
|
||||
refresh(dao.findAll());
|
||||
}
|
||||
});
|
||||
btnpanel.add(button_1);
|
||||
|
||||
JButton button_2 = new JButton("修改");
|
||||
/**
|
||||
修改操作
|
||||
*/
|
||||
button_2.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int row = table.getSelectedRow();
|
||||
if (row == -1) {
|
||||
JOptionPane.showMessageDialog(null, "请选择一行进行修改");
|
||||
return;
|
||||
}
|
||||
//跳转到修改页面
|
||||
new ZhuhuUpdateUI(me()).setVisible(true);
|
||||
}
|
||||
|
||||
});
|
||||
btnpanel.add(button_2);
|
||||
System.out.println(dao.findAll().size());
|
||||
refresh(dao.findAll());
|
||||
}
|
||||
public ZhuhuManageUIListPanel me(){
|
||||
return this;
|
||||
}
|
||||
//刷新表格列表
|
||||
public void refresh(List list){
|
||||
|
||||
|
||||
tableModel = new DefaultTableModel(transferList(list), columnCount){
|
||||
public Class getColumnClass(int column) { /*方法*/ /*返回列*/
|
||||
Vector<?> v = (Vector<?>) dataVector.elementAt(0);
|
||||
if(v.elementAt(column)!=null){
|
||||
return v.elementAt(column).getClass();
|
||||
}else{
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
Class<?> columnClass = getColumnClass(col);
|
||||
return columnClass != ImageIcon.class;
|
||||
}
|
||||
};
|
||||
table.setModel(tableModel);
|
||||
|
||||
|
||||
updateRowHeights();
|
||||
}
|
||||
//自动调整列高
|
||||
private void updateRowHeights()
|
||||
{
|
||||
for (int row = 0; row < table.getRowCount(); row++)
|
||||
{
|
||||
int rowHeight = table.getRowHeight();
|
||||
|
||||
for (int column = 0; column < table.getColumnCount(); column++)
|
||||
{
|
||||
Component comp = table.prepareRenderer(table.getCellRenderer(row, column), row, column);
|
||||
rowHeight = Math.max(rowHeight, comp.getPreferredSize().height);
|
||||
}
|
||||
table.setRowHeight(row, rowHeight);
|
||||
}
|
||||
}
|
||||
//将实体列表转换为表格实体
|
||||
public static Object[][] transferList(List<Zhuhu> list) {
|
||||
Object[][] olist = new Object[list.size()][];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Object str[] = {list.get(i).getId().toString(), list.get(i).getHuzhudxy(),list.get(i).getDizhidxy(),list.get(i).getLianxidianhuadxy() };
|
||||
//如果包含图片格式则以图片形式显示
|
||||
for (int j = 0; j < str.length; j++) {
|
||||
if(str[j]!=null&&(str[j].toString().contains("png")||str[j].toString().contains("jpg")||str[j].toString().contains("gif"))){
|
||||
str[j]=new ImageIcon(new ImageIcon(str[j].toString()).getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT));
|
||||
}
|
||||
}
|
||||
olist[i] = str;
|
||||
}
|
||||
|
||||
return olist;
|
||||
}
|
||||
public JTable getTable() {
|
||||
return table;
|
||||
}
|
||||
public String getMainid(){
|
||||
return mainid;
|
||||
}
|
||||
}
|
||||
@ -1,126 +0,0 @@
|
||||
package view;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import dao.ZhuhuDao;
|
||||
import dao.impl.ZhuhuImpl;
|
||||
import entity.Zhuhu;
|
||||
public class ZhuhuUpdateUI extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
|
||||
|
||||
ZhuhuDao dao = new ZhuhuImpl();
|
||||
public ZhuhuUpdateUI() {
|
||||
init(null);
|
||||
}
|
||||
public ZhuhuUpdateUI(Tableinter mui) {
|
||||
init(mui);
|
||||
}
|
||||
public void init(Tableinter mui) {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 643, 646);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
Zhuhu zhuhu = dao.findById((String) mui.getTable().getValueAt(mui.getTable().getSelectedRow(), 0));
|
||||
JPanel panel = new BackgroundPanel();
|
||||
contentPane.add(panel);
|
||||
panel.setLayout(new GridLayout(0, 2, 0, 0));
|
||||
JLabel idlabel = new JLabel("id");
|
||||
idlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(idlabel);
|
||||
JTextField idtextField = new JTextField(zhuhu.getId().toString());
|
||||
idtextField.setEnabled(false);
|
||||
panel.add(idtextField);
|
||||
JLabel huzhudxylabel = new JLabel("户主");
|
||||
huzhudxylabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(huzhudxylabel);
|
||||
JTextField huzhudxytextField = new JTextField(zhuhu.getHuzhudxy());
|
||||
panel.add(huzhudxytextField);
|
||||
|
||||
JLabel dizhidxylabel = new JLabel("地址");
|
||||
dizhidxylabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(dizhidxylabel);
|
||||
JTextField dizhidxytextField = new JTextField(zhuhu.getDizhidxy());
|
||||
panel.add(dizhidxytextField);
|
||||
|
||||
JLabel lianxidianhuadxylabel = new JLabel("联系电话");
|
||||
lianxidianhuadxylabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(lianxidianhuadxylabel);
|
||||
JTextField lianxidianhuadxytextField = new JTextField(zhuhu.getLianxidianhuadxy());
|
||||
panel.add(lianxidianhuadxytextField);
|
||||
|
||||
|
||||
|
||||
panel.setBounds(10, 10, 607, 120);
|
||||
JButton button = new JButton("修改");
|
||||
/**
|
||||
修改按钮触发事件
|
||||
*/
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
||||
Zhuhu bean=new Zhuhu();
|
||||
bean.setHuzhudxy(huzhudxytextField.getText());
|
||||
|
||||
bean.setDizhidxy(dizhidxytextField.getText());
|
||||
|
||||
bean.setLianxidianhuadxy(lianxidianhuadxytextField.getText());
|
||||
|
||||
bean.setId(Integer.valueOf(idtextField.getText()));
|
||||
|
||||
|
||||
dao.modify(bean);
|
||||
JOptionPane.showMessageDialog(null, "修改成功");
|
||||
//刷新主界面列表
|
||||
if(mui!=null)
|
||||
mui.refresh(dao.findAll());
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button.setBounds(173, 550, 93, 47);
|
||||
contentPane.add(button);
|
||||
|
||||
JButton button_1 = new JButton("取消");
|
||||
/**
|
||||
取消按钮触发事件
|
||||
*/
|
||||
button_1.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
button_1.setFont(new Font("宋体", Font.PLAIN, 20));
|
||||
button_1.setBounds(334, 550, 93, 47);
|
||||
contentPane.add(button_1);
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
public String getRadioValue(JPanel panel){
|
||||
for(Component c:panel.getComponents()){
|
||||
if(c instanceof JRadioButton){
|
||||
if(((JRadioButton) c).isSelected()){
|
||||
return ((JRadioButton)c).getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue