⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentframe.java

📁 学生管理系统,界面布局的示例。主要包含四个类。
💻 JAVA
字号:
/*
 * StudentFrame.java
 *
 * Created on 2008年10月10日, 下午2:35
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package studentmanagement;

import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

/**
 *
 * @author DJ尐舞
 */
public class StudentFrame extends Frame implements ActionListener, WindowListener, ItemListener {

    /** Creates a new instance of StudentFrame */
    //学生管理与用户管理
    UserManage um = new UserManage();
    StudentManage sm = new StudentManage();
    //控件
    TextField userNameTF = new TextField("", 20);
    TextField userPasswordTF = new TextField("", 20);
    TextField studentNoTF = new TextField("", 20);
    TextField studentNameTF = new TextField("", 20);
    Button loginButton = new Button("登陆");
    Button quitButton = new Button("离开");
    TextArea infoTA = new TextArea();
    List studentList = new List();

    public StudentFrame() {
        dataInitial();
        constructGUI();
        this.setVisible(true);
    }

    public StudentFrame(String title) {
        super(title);
        dataInitial();
        constructGUI();
        this.setVisible(true);
    }

    private void dataInitial() {
        um.add("test", "test");
        um.add("admin", "admin");
        sm.add("周杰伦", "00001", "即将发布在10月15日发行《魔杰座》");
        sm.add("周润发", "00002", "赌神");
        sm.add("林俊杰", "00003", "我的《JJ陆》也快发行啦");
        sm.add("S.H.E", "00004", "欢迎收听我的电台FM S.H.E");
    }

    private void constructGUI() {
        //添加事件
        this.addWindowListener(this);
        loginButton.addActionListener(this);
        //searchButton.addActionListener(this);
        quitButton.addActionListener(this);
        studentList.addItemListener(this);
        //窗体创建
        this.setSize(800, 600);
        this.setLocationRelativeTo(null);//设置屏幕中间显示
        //窗体布局
        JPanel pTop = new JPanel(new FlowLayout(FlowLayout.LEFT)),
                pLeft = new JPanel(new GridLayout()),
                pCenter = new JPanel(new BorderLayout()),
                pCenterTop = new JPanel(),
                pCenterCenter = new JPanel(new BorderLayout()),
                pCenterCenterCenter = new JPanel(new GridLayout());

        //顶部布局
        pTop.add(new Label("用户名"));
        pTop.add(userNameTF);
        pTop.add(new Label("密码"));
        pTop.add(userPasswordTF);
        pTop.add(loginButton);
        pTop.add(quitButton);
        pTop.setBackground(Color.LIGHT_GRAY);
        this.add(pTop, BorderLayout.NORTH);
        //左边布局
        studentList.setBackground(Color.lightGray);
        pLeft.add(studentList);
        this.add(pLeft, BorderLayout.WEST);
        pLeft.setBorder(new TitledBorder("学生学号"));
        //中间布局
        pCenterTop.add(new Label("学号"));
        pCenterTop.add(studentNoTF);
        pCenterTop.add(new Label("姓名"));
        pCenterTop.add(studentNameTF);
        //   pCenterTop.add(searchButton);
        //   pCenterTop.setBackground(Color.GRAY);
        pCenter.add(pCenterTop, BorderLayout.NORTH);
        pCenterCenter.add(new Label("详细信息"), BorderLayout.NORTH);
        pCenterCenter.add(pCenterCenterCenter, BorderLayout.CENTER);
        pCenterCenterCenter.add(infoTA);
        pCenter.add(pCenterCenter, BorderLayout.CENTER);
        pCenter.setBorder(new TitledBorder("学生信息"));
        this.add(pCenter, BorderLayout.CENTER);






    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == quitButton) {
            if (JOptionPane.showConfirmDialog(this, "真的要退出么?") == 0) {
                this.dispose();
            }
        } else if (e.getSource() == loginButton) {
            if (um.isRightUser(userNameTF.getText(), userPasswordTF.getText()) == true) {
               // JOptionPane.showMessageDialog(this, "登陆成功");
                for (int i = 0; i < sm.showNo().length; i++) {
                    studentList.add(sm.showNo()[i]);
                }
            } else {
                JOptionPane.showMessageDialog(this, "登陆失败");
            }
        }
    }

    public void windowOpened(WindowEvent e) {
    }

    public void windowClosing(WindowEvent e) {
        if (JOptionPane.showConfirmDialog(this, "真的要退出么?") == 0) {
            System.exit(0);
        }
    }

    public void windowClosed(WindowEvent e) {
    }

    public void windowIconified(WindowEvent e) {
    }

    public void windowDeiconified(WindowEvent e) {
    }

    public void windowActivated(WindowEvent e) {
    }

    public void windowDeactivated(WindowEvent e) {
    }

    public void itemStateChanged(ItemEvent e) {
        if (e.getSource() == studentList) {
            String[] s = sm.getInfo(studentList.getItem((Integer) e.getItem()));
            studentNoTF.setText(s[0]);
            studentNameTF.setText(s[1]);
            infoTA.setText(s[2]);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -