java怎么写登录界面( 二 )


4.java写一个登录界面import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class login extends JFrame implements ActionListener
{
public JPasswordField password;
public JTextField name;
JButton ok;
login()
{
setSize(300,200);//大小
setLocation(200,100);
JPanel panel = new JPanel();//创建一个面板对象
panel.setLayout(new GridBagLayout());
Container cn = this.getContentPane();
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(5,2,5,5);
c.gridheight = 1;
JLabel user = new JLabel("User:");
c.gridx = 1;
c.gridy = 1;
panel.add(user,c);
name = new JTextField(10);
c.gridx = 2;
panel.add(name,c);
JLabel pass = new JLabel("assword:");
c.gridx = 1;
c.gridy = 2;
panel.add(pass,c);
password = new JPasswordField(10);
c.gridx = 2;
c.gridy = 2;
panel.add(password,c);
c.gridx = 1;
c.gridy = 3;
ok = new JButton("login");
ok.addActionListener(this);
panel.add(ok,c);
cn.add(panel);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == ok)
{
String username = this.name.getText();
String password = this.password.getText();
String message = username + " "+password;
try
{
byte[] b = message.getBytes();
FileOutputStream fos = new FileOutputStream("login.txt");
fos.write(b,0,b.length);
this.dispose();
}catch(Exception ex)
{
}
}
}
public static void main(String args[])
{
new login().show();
}
}
5.怎么用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 B 。
什么都不说了 直接给你代码吧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);}} 。