how2j.cn

-->
下载区
文件名 文件大小
请先登录 2m
增值内容 2m
2m

解压rar如果失败,请用5.21版本或者更高版本的winrar

点击下载 winrar5.21

增值内容,请先登录
完整的J2SE桌面项目,从无到有完整的开发流程,涵盖全部52个知识点,154个开发步骤, 一共36个讲解视频,累计时长3小时10分59秒,大小1.94G,充实J2SE项目经验,为简历加上一个有吸引力的砝码
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢


HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。


问答区域    
2022-01-13 我成功完成站长的修改要求啦!
Alex97




一个类中有静态变量、静态方法、静态代码块、成员变量、成员方法、非静态代码块、构造器,那么他们执行的顺序是什么呢?如果该类继承了父类,那么执行顺序又是什么样的呢? 正常情况下:超类的静态变量和代码块 - - - > 父类的静态变量和代码块 - - - > 子类的静态变量和代码块 - - - > 超类的非静态变量和代码块- - - > 超类的构造器 - - - > 父类的非静态变量和代码块 - - - > 父类的构造器 - - - > 子类的非静态变量和代码块 - - - > 子类的构造器 ———————————————— 基础不牢,地动山摇 public class DetailByCategoryTableModel implements TableModel { int cid; public List<Record> rs = new ArrayList<>(); String[] columnNames = new String[]{"花费¥", "分类","备注","日期"}; // 使用从Service返回的List作为TableModel的数据 public DetailByCategoryTableModel(int cid) { this.cid = cid; rs = new RecordService().list(cid); } 之前是 public List<Record> rs=new RecordService().list(cid); rs.size一直是0,弄了一个多小时.
加载中
package gui.listener;

import entity.Category;
import gui.panel.*;
import service.RecordService;
import util.GUIUtil;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

public class DetailEditListener implements ActionListener{
    @Override
    public void actionPerformed(ActionEvent e) {
       DetailEdit p =DetailEdit.instance;
        if (0==p.cbModel.cs.size()){
            JOptionPane.showMessageDialog(p,"暂无消费分类,无法添加,请先增加消费分类");
            MainPanel.instance.workingPanel.show(CategoryPanel.instance);
            return;
        }

        if (!GUIUtil.checkZero(p.tfSpend,"花费金额"))
            return;

        int spend = Integer.parseInt(p.tfSpend.getText());
        Category c =p.getSelectedCategory();
        String comment = p.tfComment.getText();
        Date d = p.datepick.getDate();
        new RecordService().update(p.id,spend,c,comment,d);
        JOptionPane.showMessageDialog(p,"修改成功");

        p.setVisible(false);
        MainPanel.instance.workingPanel.show(DetailPanel.instance);

    }
}
___________________________________________________________________________
package gui.listener;

import entity.Category;
import entity.Record;
import gui.model.DetailByCategoryTableModel;
import gui.panel.DetailEdit;
import gui.panel.DetailPanel;
import service.CategoryService;
import service.RecordService;

import javax.swing.*;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.List;

public class DetailListener implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {
        DetailPanel p = DetailPanel.instance;
        JButton b = (JButton) e.getSource();

        if (b == p.bEdit) {
            Record r = p.getSelectedRecord();
            DetailEdit de = DetailEdit.instance;
            de.setVisible(true);
            de.setRecord(r);

        }
        if (b == p.bDelete) {
            Record r = p.getSelectedRecord();
            if (JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(p, "确认要删除?"))
                return;

            int id = r.id;
            new RecordService().delete(id);
        }

        if (b==p.bSelect){
            Category selectedItem=(Category)p.cbCategory.getSelectedItem();
            int cid =selectedItem.id;
            DetailByCategoryTableModel dbctm=new DetailByCategoryTableModel(cid);
            JTable t = new JTable(dbctm);
            t.setVisible(true);
            JDialog jDialog = new JDialog();
            jDialog.add(t);
            jDialog.setBounds(100,100,400,300);
            jDialog.setVisible(true);

        }

        p.updateData();
    }
}
_______________________________________________________________________
package gui.model;

import com.sun.org.apache.xpath.internal.SourceTree;
import entity.Record;
import service.CategoryService;
import service.RecordService;

import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class DetailByCategoryTableModel implements TableModel {
    int cid;
    public List<Record> rs = new ArrayList<>();
    String[] columnNames = new String[]{"花费¥", "分类","备注","日期"};
    // 使用从Service返回的List作为TableModel的数据
    public DetailByCategoryTableModel(int cid) {
        this.cid = cid;
        rs = new RecordService().list(cid);
    }



    @Override
    public int getRowCount() {
        return rs.size();
    }


    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return columnNames[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if (columnIndex==0){return Integer.class;}
        if (columnIndex==1){return String.class;}
        if (columnIndex==2){return String.class;}
        if (columnIndex==3){return Date.class;}
        return null;
    }


    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    // 先通过cs.get(rowIndex)获取行对应的Category对象
    // 然后根据columnIndex返回对应的属性
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Record h = rs.get(rowIndex);
        if (0 == columnIndex)
            return h.spend;
        if (1 == columnIndex){
            CategoryService cs  = new CategoryService();
            return cs.get(h.cid).name;}
        if (2 == columnIndex)
            return h.comment;
        if (3 == columnIndex)
            return h.date;
        return null;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {

    }

    @Override
    public void addTableModelListener(TableModelListener l) {

    }

    @Override
    public void removeTableModelListener(TableModelListener l) {

    }
}
________________________________________________________________
package gui.model;


import entity.Record;

import service.CategoryService;
import service.RecordService;

import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import java.util.Date;
import java.util.List;

public class DetailTableModel implements TableModel {

    String[] columnNames = new String[]{"花费¥", "分类","备注","日期"};
    // 使用从Service返回的List作为TableModel的数据
    public List<Record> rs = new RecordService().list();


    @Override
    public int getRowCount() {
        return rs.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return columnNames[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if (columnIndex==0){return Integer.class;}
        if (columnIndex==1){return String.class;}
        if (columnIndex==2){return String.class;}
        if (columnIndex==3){return Date.class;}
        return null;
    }


    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    // 先通过cs.get(rowIndex)获取行对应的Category对象
    // 然后根据columnIndex返回对应的属性
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Record h = rs.get(rowIndex);
        if (0 == columnIndex)
            return h.spend;
        if (1 == columnIndex){
            CategoryService cs  = new CategoryService();
            return cs.get(h.cid).name;}
        if (2 == columnIndex)
            return h.comment;
        if (3 == columnIndex)
            return h.date;
        return null;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {

    }

    @Override
    public void addTableModelListener(TableModelListener l) {

    }

    @Override
    public void removeTableModelListener(TableModelListener l) {

    }

}
__________________________________________________________________
package gui.panel;

import entity.Category;
import entity.Record;
import gui.listener.DetailEditListener;

import gui.model.CategoryComboBoxModel;

import jdk.management.resource.internal.inst.SocketOutputStreamRMHooks;
import org.jdesktop.swingx.JXDatePicker;

import util.ColorUtil;
import util.GUIUtil;

import javax.swing.*;
import java.awt.*;
import java.util.Date;

public class DetailEdit extends JDialog{
    static {
        GUIUtil.useLNF();
    }

    public static DetailEdit instance = new DetailEdit();

   public int id ;
    JLabel lSpend = new JLabel("花费(¥)");
    JLabel lCategory = new JLabel("分类");
    JLabel lComment = new JLabel("备注");
    JLabel lDate = new JLabel("日期");

    public JTextField tfSpend = new JTextField("0");
    public CategoryComboBoxModel cbModel = new CategoryComboBoxModel();
    public JComboBox<Category> cbCategory = new JComboBox<>(cbModel);
    public JTextField tfComment = new JTextField();
    public JXDatePicker datepick = new JXDatePicker(new Date());
    JButton bSubmit = new JButton("确认修改");

    public DetailEdit() {
        GUIUtil.setColor(ColorUtil.grayColor, lSpend, lCategory, lComment, lDate);
        GUIUtil.setColor(ColorUtil.blueColor, bSubmit);
        JPanel pInput = new JPanel();
        JPanel pSubmit = new JPanel();
        int gap = 40;
        pInput.setLayout(new GridLayout(4, 2, gap, gap));
        pInput.add(lSpend);
        pInput.add(tfSpend);
        pInput.add(lCategory);
        pInput.add(cbCategory);
        pInput.add(lComment);
        pInput.add(tfComment);
        pInput.add(lDate);
        pInput.add(datepick);
        pSubmit.add(bSubmit);

        this.setLayout(new BorderLayout());
        this.add(pInput, BorderLayout.NORTH);
        this.add(pSubmit, BorderLayout.CENTER);

        this.setBounds(100,100,300,300);
        addListener();
    }

    public static void main(String[] args) {
        DetailEdit de = new DetailEdit();
        de.setVisible(true);
    }

    public void setRecord(Record record) {
        tfSpend.setText(""+record.spend);
        cbCategory.setSelectedIndex(0);
        tfComment.setText(record.comment);
        datepick.setDate(record.date);
        id = record.id;
    }

    public Category getSelectedCategory(){
        return (Category)cbCategory.getSelectedItem();
    }
    public void addListener() {
        DetailEditListener listener = new DetailEditListener();
        bSubmit.addActionListener(listener);
    }
}

_________________________________________________________
package gui.panel;

import entity.Category;
import entity.Record;
import gui.listener.DetailListener;
import gui.model.CategoryComboBoxModel;
import gui.model.DetailTableModel;
import service.RecordService;
import util.ColorUtil;
import util.GUIUtil;

import javax.swing.*;
import java.awt.*;

public class DetailPanel extends WorkingPanel {
    static {
        GUIUtil.useLNF();
    }

    public static DetailPanel instance = new DetailPanel();

    public JButton bEdit = new JButton("编辑");
    public JButton bDelete = new JButton("删除");
    public JButton bSelect = new JButton("筛选");
    public CategoryComboBoxModel cbModel = new CategoryComboBoxModel();
    public JComboBox<Category> cbCategory = new JComboBox<>(cbModel);

    String columNames[] = new String[]{"花费¥", "分类", "备注", "日期"};

    public DetailTableModel dtm = new DetailTableModel();
    public JTable t = new JTable(dtm);

    public DetailPanel() {
        GUIUtil.setColor(ColorUtil.blueColor, bEdit, bDelete,bSelect);
        JScrollPane sp = new JScrollPane(t);
        JPanel pSubmit = new JPanel();
        pSubmit.add(bEdit);
        pSubmit.add(bDelete);
        pSubmit.add(bSelect);
        pSubmit.add(cbCategory);

        this.setLayout(new BorderLayout());
        this.add(sp, BorderLayout.CENTER);
        this.add(pSubmit, BorderLayout.SOUTH);
        addListener();
    }

    public static void main(String[] args) {
        GUIUtil.showPanel(DetailPanel.instance);
    }

    public Record getSelectedRecord() {
        int index = t.getSelectedRow();
        return dtm.rs.get(index);
    }

    @Override
    public void updateData() {
        dtm.rs = new RecordService().list();
        t.updateUI();
        t.getSelectionModel().setSelectionInterval(0,0);

        if (0==dtm.rs.size()) {
            bEdit.setEnabled(false);
            bDelete.setEnabled(false);
        }else {
            bEdit.setEnabled(true);
            bDelete.setEnabled(true);
        }

    }

    @Override
    public void addListener() {
        DetailListener listener = new DetailListener();
        bEdit.addActionListener(listener);
        bDelete.addActionListener(listener);
        bSelect.addActionListener(listener);
    }
}

							


1 个答案

how2j
答案时间:2022-02-02
666



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2021-06-06 用了eclispe下载导入后还是有Bug,img里的图片显示不了
一叶秋梦




怎么办,是什么的原因
加载中

							

							


1 个答案

how2j
答案时间:2021-06-20
“没学的同学,老老实实地把本项目从头学过来,不然拿到源码都不知道怎么运行的。”



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2021-06-02 下载了完整项目,却出现了很多错误,怎么办
2021-03-08 如何将项目打包成exe项目
2020-05-14 下载源码


提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 6 条以前的提问,请 点击查看

提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 实践项目-一本糊涂账-完整项目下载 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 578362961
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: https://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图