登录界面的实现

例程实现的界面如下

                        




设计这个界面应该比较的简单,只需要一些基本的布局知识就可以了,这里主要是TextView中的跑马灯的效果,用到的属性是:android:ellipsize="marquee"

android:marqueeRepeatLimit="marquee_forever",下面就直接介绍布局文件layout:

<pre name="code" class="html"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <!-- 通过 android:text实现TextView显示的文本 -->
    <!-- 通过android:ellipsize实现跑马灯效果 -->
    <!-- 通过 android:textSize实现控制字体大小 -->
    <!-- 通过android:marqueeRepeatLimit设置跑马灯效果循环无限次 -->



    <TextView
        android:id="@+id/firstView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="欢 迎 您 登 录 成 绩 查 询 系 统,祝 您好 运  !!!!!"
        android:textSize="20sp" />


    <LinearLayout
        android:id="@+id/linear1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >


        <!-- 通过android:textColor设置字体颜色 -->
        <!-- 通过android:textStyle设置字形 -->


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="学    号:"
            android:textColor="#ff0000"
            android:textSize="20sp"
            android:textStyle="bold" />
        <!-- 通过android:hint设置输入提示信息 -->
        <!-- 通过android:inputType设置数字输入格式 -->


        <EditText
            android:id="@+id/numberET"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="请输入学号"
            android:inputType="number" />
    </LinearLayout>


    <LinearLayout
        android:id="@+id/linear2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="姓    名:"
            android:textColor="#ff0000"
            android:textSize="20sp"
            android:textStyle="bold" />


        <EditText
            android:id="@+id/nameET"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="请输入姓名" />
    </LinearLayout>


    <LinearLayout
        android:id="@+id/linear3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密    码:"
            android:textColor="#ff0000"
            android:textSize="20sp"
            android:textStyle="bold" />
        <!-- 通过password属性设置输入文本以点显示 -->


        <EditText
            android:id="@+id/passwordET"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="请输入密码"
            android:password="true" />
    </LinearLayout>


    <Button
        android:id="@+id/loginBtn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="登 录"
        android:textSize="20sp" />


</LinearLayout>


 

mainactivity中的功能代码如下:


<pre name="code" class="java">package com.toby.chap3_2_1;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
	private TextView firstView;
	private EditText numberET, nameET, passwordET;
	private Button loginBtn;
	private String number, name, password;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		firstView = (TextView) findViewById(R.id.firstView);// 根据ID获取到TextView对象
		numberET = (EditText) findViewById(R.id.numberET);// 根据ID获取到EditText对象
		nameET = (EditText) findViewById(R.id.nameET);
		passwordET = (EditText) findViewById(R.id.passwordET);
		loginBtn = (Button) findViewById(R.id.loginBtn);// 根据ID获取到Button对象
		loginBtn.setOnClickListener(new OnClickListener() {// 对Button实现点击事件监听
			@Override
			public void onClick(View v) {// 设置点击Button后要执行的操作
				number = numberET.getText().toString();// 获取文本框输入的内容
				name = nameET.getText().toString();
				password = passwordET.getText().toString();
				if (number.equals("001") && name.equals("001")
						&& password.equals("001")) {
					firstView.setText(name + "同学您已经登录成绩查询系统!");
				} else {
					firstView.setText("您的输入有误,请重新输入!!!");
				}
			}
		});
	}
}


 

以下是一个简单的Java代码示例,用于实现一个GUI登录界面: ``` import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class LoginGUI extends JFrame { private JTextField usernameTextField; private JPasswordField passwordField; private JButton loginButton; private JButton resetButton; public LoginGUI() { setTitle("登录界面"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300, 200); setLocationRelativeTo(null); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(3, 2)); JLabel usernameLabel = new JLabel("用户名:"); JLabel passwordLabel = new JLabel("密码:"); usernameTextField = new JTextField(); passwordField = new JPasswordField(); loginButton = new JButton("登录"); resetButton = new JButton("重置"); panel.add(usernameLabel); panel.add(usernameTextField); panel.add(passwordLabel); panel.add(passwordField); panel.add(loginButton); panel.add(resetButton); loginButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String username = usernameTextField.getText(); String password = new String(passwordField.getPassword()); if (username.equals("admin") && password.equals("123456")) { JOptionPane.showMessageDialog(null, "登录成功"); } else { JOptionPane.showMessageDialog(null, "用户名或密码错误"); } } }); resetButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { usernameTextField.setText(""); passwordField.setText(""); } }); add(panel); setVisible(true); } public static void main(String[] args) { new LoginGUI(); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值