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

📄 employeelists.java

📁 java编程开发技巧与实例的编译测试通过的所有例程
💻 JAVA
字号:
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.Container;
import javax.swing.*;

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

public class EmployeeLists extends JFrame
{
	protected JButton hire		=	new JButton("Hire");
	protected JButton fire		=	new JButton("Fire");
	protected JButton restore	=	new JButton("Restore");
	protected JTextField name	=	new JTextField();
	protected DefaultListModel peopleData	=	new DefaultListModel();
	protected DefaultListModel toFireData	=	new DefaultListModel();
	protected JList peopleList	=	new JList(peopleData);
	protected JList toFireList	=	new JList(toFireData);
	
	public EmployeeLists()
	{
		super("JList Test");
		JPanel buttons	=	new JPanel(new FlowLayout());
		buttons.add(hire);
		buttons.add(fire);
		buttons.add(restore);
		JPanel input	=	new JPanel(new BorderLayout());
		input.add("Center", new JPanelBox(name, "Employee Name"));
		input.add("East", new JPanelBox(buttons, "Action"));
		JScrollPane peoplePane	=	new JScrollPane(peopleList);
		JScrollPane toFirePane	=	new JScrollPane(toFireList);
		peoplePane.setPreferredSize(new Dimension(200, 200));
		toFirePane.setPreferredSize(new Dimension(200, 200));
		Container content	=	getContentPane();
		content.setLayout(new BorderLayout());
		content.add("North", input);
		content.add("East", new JPanelBox(toFirePane, "Probation List"));
		content.add("West", new JPanelBox(peoplePane, "Employee List"));
		peopleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		toFireList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		validate();
		pack();
		//setSize(500, 300);
		setLocationRelativeTo(this);
		setVisible(true);
		
		EmployeeEventHandler handler	=	new EmployeeEventHandler(this);
		hire.addActionListener(handler);
		fire.addActionListener(handler);
		restore.addActionListener(handler);
		name.addActionListener(handler);
		peopleList.addListSelectionListener(handler);
		addWindowListener(handler);
	}
	public static void styleCtrl(String style)
	{
		try
		{
			String lf_wind	=	"com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
			String lf_unix	=	"com.sun.java.swing.plaf.motif.MotifLookAndFeel";
			String lf_java	=	"javax.swing.plaf.metal.MetalLookAndFeel";
			if (style.equals("java"))
				UIManager.setLookAndFeel(lf_java);
			else if (style.equals("unix"))
				UIManager.setLookAndFeel(lf_unix);
			else if (style.equals("windows"))
				UIManager.setLookAndFeel(lf_wind);
		}
		catch	(Exception e)
		{
			System.err.println("Exception: " + e);
		}
	}
	public static void main(String args[])
	{
		styleCtrl("java");
		EmployeeLists jlt	=	new EmployeeLists();
	}
}

⌨️ 快捷键说明

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