【2】JAVA---地址App小软件(ListPanel.class)(表现层)

这个是表现层的主界面。

/*
 * ListPanel.java
 *
 */

package cn.hncu.addr.ui;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;

import cn.hncu.addr.business.AddrBusiness;

/**
 * 
 * @author __chx__
 */
public class ListPanel extends javax.swing.JPanel {
    /** Creates new form ListPanel */
    private JFrame mainFrame = null;
    private JLabel jlbFindAddress = new javax.swing.JLabel();


    public ListPanel(JFrame mainFrame) {
        this.mainFrame = mainFrame;
        initComponents();
        myInitData();
    }

    public ListPanel(JFrame mainFrame, Object[] objs) {
        this.mainFrame = mainFrame;
        initComponents();
        jListAddress.setListData(objs);

        jlbFindAddress
                .setText("\u67e5\u627e\u5230\u7684\u5730\u5740\u4fe1\u606f\uff1a");
        add(jlbFindAddress);
        jlbFindAddress.setBounds(40, 50, 125, 17);
    }

    private void myInitData() {
        AddrBusiness set = new AddrBusiness();
        Object obj[] = set.getAll();
        jListAddress.setListData(obj);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    private JList<String> getListAddress() {
        return jListAddress;
    }


    private void initComponents() {
        jLabelApp = new javax.swing.JLabel();
        jbtnAdd = new javax.swing.JButton();
        jbtnChange = new javax.swing.JButton();
        jbtnDelete = new javax.swing.JButton();
        jbtnFind = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListAddress = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jToggleButton1 = new javax.swing.JToggleButton();

        setPreferredSize(new java.awt.Dimension(800, 600));
        setLayout(null);

        jLabelApp.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 36));
        jLabelApp.setForeground(new java.awt.Color(255, 0, 0));
        jLabelApp.setText("    \u5730\u5740\u4fe1\u606fApp");
        add(jLabelApp);
        jLabelApp.setBounds(240, 20, 263, 47);

        jbtnAdd.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 14));
        jbtnAdd.setForeground(new java.awt.Color(102, 102, 255));
        jbtnAdd.setText("\u6dfb\u52a0\u5730\u5740");
        jbtnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAddActionPerformed(evt);
            }
        });
        add(jbtnAdd);
        jbtnAdd.setBounds(120, 360, 120, 60);

        jbtnChange.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 14));
        jbtnChange.setForeground(new java.awt.Color(102, 102, 255));
        jbtnChange.setText("\u4fee\u6539\u5730\u5740");
        jbtnChange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnChangeActionPerformed(evt);
            }
        });
        add(jbtnChange);
        jbtnChange.setBounds(120, 460, 120, 60);

        jbtnDelete.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 14));
        jbtnDelete.setForeground(new java.awt.Color(102, 102, 255));
        jbtnDelete.setText("\u5220\u9664\u5730\u5740");
        jbtnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnDeleteActionPerformed(evt);
            }
        });
        add(jbtnDelete);
        jbtnDelete.setBounds(470, 460, 120, 60);

        jbtnFind.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 14));
        jbtnFind.setForeground(new java.awt.Color(102, 102, 255));
        jbtnFind.setText("\u67e5\u627e\u5730\u5740");
        jbtnFind.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnFindActionPerformed(evt);
            }
        });
        add(jbtnFind);
        jbtnFind.setBounds(470, 360, 120, 60);

        jListAddress.setFont(new java.awt.Font("Microsoft YaHei UI", 1, 14));
        jListAddress.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "" };

            public int getSize() {
                return strings.length;
            }

            public Object getElementAt(int i) {
                return strings[i];
            }
        });
        jScrollPane1.setViewportView(jListAddress);

        add(jScrollPane1);
        jScrollPane1.setBounds(40, 70, 700, 270);

        jLabel1.setText(" \u9648\u6d69\u7fd4");
        add(jLabel1);
        jLabel1.setBounds(700, 510, 60, 17);

        jToggleButton1.setText("\u9000\u51fa");
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });
        add(jToggleButton1);
        jToggleButton1.setBounds(680, 410, 80, 50);
    }

    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        System.exit(0);
    }

    private void jbtnFindActionPerformed(java.awt.event.ActionEvent evt) {
        mainFrame.setContentPane(new QueryPanel(mainFrame));
        mainFrame.validate();
    }

    private void jbtnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
        if (jListAddress.getSelectedValue() == null) {
            JOptionPane.showMessageDialog(this, "未选中地址!无法删除,请重新选择!");
        } else {
            mainFrame.setContentPane(new DeletePanel(mainFrame,
                    (String) jListAddress.getSelectedValue()));
            mainFrame.validate();
        }
    }

    private void jbtnChangeActionPerformed(java.awt.event.ActionEvent evt) {
        if (jListAddress.getSelectedValue() == null) {
            JOptionPane.showMessageDialog(this, "未选中地址!无法修改,请重新选择!");
        } else {
            mainFrame.setContentPane(new UpdatePanel(mainFrame,
                    (String) jListAddress.getSelectedValue()));
            mainFrame.validate();
        }
    }

    private void jbtnAddActionPerformed(java.awt.event.ActionEvent evt) {
        // System.out.println("aaa");
        mainFrame.setContentPane(new AddPanel(mainFrame));
        mainFrame.revalidate();
    }

    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelApp;
    private javax.swing.JList jListAddress;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JButton jbtnAdd;
    private javax.swing.JButton jbtnChange;
    private javax.swing.JButton jbtnDelete;
    private javax.swing.JButton jbtnFind;

}
谙忆 CSDN认证博客专家 Java
公众号:程序编程之旅。曾经写过C、C++,使用过Cocos2dx开发过游戏、安卓端、IOS端、PC端页面均开发过。目前专注Java开发,SaaS内核、元数据的研究。偶尔玩玩爬虫
已标记关键词 清除标记
相关推荐
<p> <strong><span style="background-color:#FFFFFF;color:#E53333;font-size:24px;">本页面购买不发书!!!仅为视频课购买!!!</span></strong> </p> <p> <strong><span style="color:#E53333;font-size:18px;">请务必到</span></strong><a href="https://edu.csdn.net/bundled/detail/49?utm_source=banner"><strong><span style="color:#E53333;font-size:18px;">https://edu.csdn.net/bundled/detail/49</span></strong></a><strong><span style="color:#E53333;font-size:18px;">下单购买课+书。</span></strong> </p> <p> <span style="font-size:14px;">本页面,仅为观看视频页面,如需一并购买图书,请</span><span style="font-size:14px;">务必到</span><a href="https://edu.csdn.net/bundled/detail/49?utm_source=banner"><span style="font-size:14px;">https://edu.csdn.net/bundled/detail/49</span></a><span style="font-size:14px;">下单购买课程+图书!!!</span> </p> <p> <br /> </p> <p> <span style="font-size:14px;">疯狂Python精讲课程覆盖《疯狂Python讲义》全书的主体内容。</span> </p> <span style="font-size:14px;">内容包括Python基本数据类型、Python列表、元组和字典、流程控制、函数式编程、面向对象编程、文件读写、异常控制、数据库编程、并发编程与网络编程、数据可视化分析、Python爬虫等。</span><br /> <span style="font-size:14px;"> 全套课程从Python基础开始介绍,逐步步入当前就业热点。将会带着大家从Python基础语法开始学习,为每个知识点都提供对应的代码实操、代码练习,逐步过渡到文件IO、数据库编程、并发编程、网络编程、数据分 析和网络爬虫等内容,本课程会从小案例起,至爬虫、数据分析案例终、以Python知识体系作为内在逻辑,以Python案例作为学习方式,最终达到“知行合一”。</span><br />
©️2020 CSDN 皮肤主题: 代码科技 设计师:Amelia_0503 返回首页
实付 19.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值