2019-08-31 MainWindows extends JFrame

package com.foreknow.view;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;

import com.foreknow.model.User;

public class MainWindows extends JFrame {

    private JPanel contentPane;
    private JTable table_1;
    protected static List list;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    MainWindows frame = new MainWindows(list);
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public MainWindows(List list) {
        setTitle("main");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
        
        JButton btnAdd = new JButton("退出");
        btnAdd.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MainWindows.this.dispose();
            }
        });
        btnAdd.setBounds(44, 213, 93, 23);
        contentPane.add(btnAdd);
        
        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setBounds(75, 90, 304, 40);
        contentPane.add(scrollPane);
        
        table_1 = new JTable();
        scrollPane.setViewportView(table_1);
        
        Object[][] objects = new Object[list.size()][5];
        for (int i = 0; i < list.size(); i++) {
            User user = (User) list.get(i);
            objects[i][0] = user.getId();
            objects[i][1] = user.getUsername();
            objects[i][2] = user.getPassword();
            objects[i][3] = user.getEmail();
            objects[i][4] = user.getPrower();
            table_1.setModel(
                    new DefaultTableModel(objects, new String[] { "人员编号", "姓名", "密码", "email", "是/否管理员" }));
        }
        setVisible(true);
    }
}

 

                            
                        
                    
                    
                    

你可能感兴趣的:(2019-08-31 MainWindows extends JFrame)