IDEA制作简易登录界面

用户登录界面

新建project
ctrl+shift+alt+s弹出Project Structure
在web-WEB-INF下New Folder两个文件夹classes,lib
在这里插入图片描述设置输入输出path
在这里插入图片描述
选择1.jars or directories 2.library,Apply应用
在这里插入图片描述运行tomcat
在这里插入图片描述
在这里插入图片描述
在index.jsp的同级目录下新建login.jsp 、login.css
在这里插入图片描述
输入网址http://localhost:8080/testproject_war_exploded/login.jsp
成功
在这里插入图片描述

代码

login.jsp代码

<%--
  Created by IntelliJ IDEA.
  User: user
  Date: 2021/7/11
  Time: 14:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Login</title>
    <link rel="stylesheet" type="text/css" href="login.css">
</head>
<body>
<div id="login">
    <h1>Login</h1>
    <form method="post">
        <input type="text" required="required" placeholder="用户名" name="u"></input>
        <input type="password" required="required" placeholder="密码" name="p"></input>
        <button class="but" type="submit">登录</button>
    </form>
</div>
</body>
</html>

login.css代码

html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-style: normal;
}

body {
    width: 100%;
    height: 100%;
    font-family: 'Open Sans', sans-serif;
    margin: 0;
    background-color: #4A374A;
}

#login {
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -150px 0 0 -150px;
    width: 300px;
    height: 300px;
}

#login h1 {
    color: #fff;
    text-shadow: 0 0 10px;
    letter-spacing: 1px;
    text-align: center;
}

h1 {
    font-size: 2em;
    margin: 0.67em 0;
}

input {
    width: 278px;
    height: 18px;
    margin-bottom: 10px;
    outline: none;
    padding: 10px;
    font-size: 13px;
    color: #fff;
    text-shadow: 1px 1px 1px;
    border-top: 1px solid #312E3D;
    border-left: 1px solid #312E3D;
    border-right: 1px solid #312E3D;
    border-bottom: 1px solid #56536A;
    border-radius: 4px;
    background-color: #2D2D3F;
}

.but {
    width: 300px;
    min-height: 20px;
    display: block;
    background-color: #4a77d4;
    border: 1px solid #3762bc;
    color: #fff;
    padding: 9px 14px;
    font-size: 15px;
    line-height: normal;
    border-radius: 5px;
    margin: 0;
}
  • 22
    点赞
  • 218
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
以下是一个简单的 IDEA 登录界面的设计代码示例: ```java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Login extends JFrame implements ActionListener { private JTextField txtUsername; private JPasswordField txtPassword; private JButton btnLogin, btnCancel; public Login() { setTitle("IDEA Login"); setSize(300, 150); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel pnlMain = new JPanel(new BorderLayout()); JPanel pnlInput = new JPanel(new GridLayout(2, 2, 5, 5)); JPanel pnlButtons = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10)); JLabel lblUsername = new JLabel("Username:"); JLabel lblPassword = new JLabel("Password:"); txtUsername = new JTextField(10); txtPassword = new JPasswordField(10); btnLogin = new JButton("Login"); btnCancel = new JButton("Cancel"); pnlInput.add(lblUsername); pnlInput.add(txtUsername); pnlInput.add(lblPassword); pnlInput.add(txtPassword); pnlButtons.add(btnLogin); pnlButtons.add(btnCancel); pnlMain.add(pnlInput, BorderLayout.CENTER); pnlMain.add(pnlButtons, BorderLayout.SOUTH); add(pnlMain); btnLogin.addActionListener(this); btnCancel.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getSource() == btnLogin) { String username = txtUsername.getText(); String password = new String(txtPassword.getPassword()); if (username.equals("admin") && password.equals("password")) { JOptionPane.showMessageDialog(this, "Login successful!"); } else { JOptionPane.showMessageDialog(this, "Invalid username or password."); } } else if (e.getSource() == btnCancel) { dispose(); } } public static void main(String[] args) { Login login = new Login(); login.setVisible(true); } } ``` 这个代码创建了一个简单的登录窗口,其中包含一个文本框和一个密码框,用于输入用户名和密码。它还包括两个按钮,一个用于登录,另一个用于取消。当用户单击“登录”按钮时,它会检查输入的用户名和密码是否正确,并显示相应的消息框。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值