zoukankan      html  css  js  c++  java
  • 使用List集合传递传递学生信息

    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.JScrollPane;
    import javax.swing.UIManager;
    import javax.swing.JTable;
    
    public class ClassInfo extends JFrame {
        
        private JPanel contentPane;
        private JTable table;
        
        /**
         * Launch the application.
         */
        public static void main(String[] args) {
            try {
                UIManager
                        .setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            } catch (Throwable e) {
                e.printStackTrace();
            }
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try {
                        ClassInfo frame = new ClassInfo();
                        frame.setVisible(true);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        
        /**
         * Create the frame.
         */
        public ClassInfo() {
            setTitle("u7528Listu96C6u5408u4F20u9012u5B66u751Fu4FE1u606F");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setBounds(100, 100, 392, 223);
            contentPane = new JPanel();
            contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
            contentPane.setLayout(new BorderLayout(0, 0));
            setContentPane(contentPane);
            
            JScrollPane scrollPane = new JScrollPane();
            contentPane.add(scrollPane, BorderLayout.CENTER);
            scrollPane.setViewportView(getTable());
        }
        
        private JTable getTable() {
            if (table == null) {
                table = new JTable();// 创建表格控件
                table.setRowHeight(23);// 设置行高度
                String[] columns = { "姓名", "性别", "出生日期" };// 创建列名数组
                // 创建表格模型
                DefaultTableModel model = new DefaultTableModel(columns, 0);
                table.setModel(model);// 设置表格模型
                List<String> students = getStudents();// 调用方法传递list集合对象
                for (String info : students) {// 遍历学生集合对象
                    String[] args = info.split(",");// 把学生信息拆分为数组
                    model.addRow(args);// 把学生信息添加到表格的行
                }
            }
            return table;
        }
        
        private List<String> getStudents() {
            // 创建List集合对象
            List<String> list = new ArrayList<String>();
            list.add("李哥,男,1981-1-1");// 添加数据到集合对象
            list.add("小陈,女,1981-1-1");
            list.add("小刘,男,1981-1-1");
            list.add("小张,男,1981-1-1");
            list.add("小董,男,1981-1-1");
            list.add("小吕,男,1981-1-1");
            return list;
        }
    }

    关键:

      Java的Swing类的基础使用。

  • 相关阅读:
    小、快、简、易、强的“银弹”— fastm
    使用Creative suite 3和Flex Builder3实现Flex 3的换肤
    Apache HTTP Server 与 Tomcat 的三种连接方式介绍
    iframe自动适应付窗口的大小变换
    Flash网络游戏开发入门经验共享
    比较详细的 Linux Top 命令解析
    HttpContext是干什么的
    asp.net,cookie,写cookie,取cookie 的方法
    为什么我们不要 .NET 程序员
    在Ubuntu上安装使用深度影音&深度音乐(推荐)
  • 原文地址:https://www.cnblogs.com/mr-wuxiansheng/p/12257494.html
Copyright © 2011-2022 走看看