联系方式

咨询热线:400-998-6158

点击此处免费预约试听课程»

常见问题
学习资讯
师资介绍
学习资讯

java登陆界面代码怎么写

今天天眼教育老师为大家讲解java登陆界面代码的写

package com.moliying.ui;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login {
	private JFrame frame = new JFrame("登录");
	private Container c = frame.getContentPane();
	private JTextField username = new JTextField();
	private JPasswordField password = new JPasswordField();
	private JButton ok = new JButton("确定");
	private JButton cancel = new JButton("取消");
	public Login() {
		frame.setSize(300, 200);
		frame.setBounds(450, 300, 300, 200);
		c.setLayout(new BorderLayout());
		initFrame();
		frame.setVisible(true);
	}
	private void initFrame() {
		// 顶部
		JPanel titlePanel = new JPanel();
		titlePanel.setLayout(new FlowLayout());
		titlePanel.add(new JLabel("系统管理员登录"));
		c.add(titlePanel, "North");
		// 中部表单
		JPanel fieldPanel = new JPanel();
		fieldPanel.setLayout(null);
		JLabel a1 = new JLabel("用户名:");
		a1.setBounds(50, 20, 50, 20);
		JLabel a2 = new JLabel("密  码:");
		a2.setBounds(50, 60, 50, 20);
		fieldPanel.add(a1);
		fieldPanel.add(a2);
		username.setBounds(110, 20, 120, 20);
		password.setBounds(110, 60, 120, 20);
		fieldPanel.add(username);
		fieldPanel.add(password);
		c.add(fieldPanel, "Center");
		// 底部按钮
		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new FlowLayout());
		buttonPanel.add(ok);
		buttonPanel.add(cancel);
		c.add(buttonPanel, "South");
		
		ok.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println(username.getText().toString());
			}
		});
		
		cancel.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				frame.setVisible(false);
			}
		});
	}
	public static void main(String[] args) {
//		new Login();
		
		String ss = "abbabbbaabbbccba";
		
		System.out.println(ss.split("b").length);

}
}


以上是杭州甲骨文天眼教育老师为大家整理的java登陆界面代码,希望能对你有所帮助,如果您想更好的学好学会JAVA,可咨询我们在线客服,或拔打400-998-6158热线咨询学习事项。 


学校联系方式

更多培训课程,学习资讯,课程优惠等学校信息,请进入 杭州天眼教育咨询有限公司 网站详细了解,免费咨询电话:400-998-6158

相关课程