欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

swing(一) 博客分类: java SwingJava 

程序员文章站 2024-03-16 11:06:52
...
/**
 * 
 */
package com.cw.swing;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

public class LoginFrame extends JFrame{

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		javax.swing.JFrame jframe = new javax.swing.JFrame();
		jframe.setTitle("登录窗口");
		jframe.setSize(400, 400);

		// 获取工具箱
		Toolkit toolkit = Toolkit.getDefaultToolkit();

		// 获取Dimension对象,包含屏幕信息
		Dimension dimenson = toolkit.getScreenSize();

		// 让frame居中显示
		jframe.setLocation((dimenson.width - jframe.getWidth()) / 2,
				(dimenson.height - jframe.getHeight()) / 2);
		jframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		jframe.setLayout(new BorderLayout());

		JButton btn = new JButton();
		btn.setName("login");
		btn.setText("登录");
		LoginFrame lf = new LoginFrame();
		btn.addActionListener(lf.new btnClass(lf));
		
		JLabel lblName=new JLabel();
		lblName.setName("lblName");
		lblName.setText("用户名:");
		
		 
		
		JLabel lblPass=new JLabel();
		lblPass.setName("lblPass");
		lblPass.setText("密码:");
		
		//JTextField txtName=new JTextField();
		
		JTextField   txtName=new JTextField(20);
		txtName.setName("txtName");
		
		JTextField   txtPass=new JTextField(20);
		txtPass.setName("txtPass");
		//text.setDocument(new NumberLenghtLimitedDmt(7));

		
		
		
		//txtName.setVisible(true);
		//txtName.setName("txtName");

		JPanel panel = new JPanel();
		panel.add(lblName);
		panel.add(txtName);
		 
		panel.add(lblPass);
		panel.add(txtPass);
		//panel.add("asasas",panel);
		panel.add(btn);
		jframe.getContentPane().add(panel);

		jframe.setResizable(false);
		jframe.setVisible(true);

	}

	class btnClass implements ActionListener {

		LoginFrame lf;

		public btnClass(LoginFrame lf) {
			this.lf = lf;
		}

		public void actionPerformed(ActionEvent event) {
			JOptionPane.showMessageDialog(null, "aaa");
			//lf.setVisible(false);
			
			//Main main=new Main();
			//main.setVisible(true);
		}

	}

}
相关标签: Swing Java