🔍 登录 注册

java之password组件的使用

大 大苹果 2017-06-01 linux 👁 4533 ⏱ 12min

java之password组件的使用

frames.java

package passwd;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2017</p>
 * <p>Company: </p>
 * @author smart
 * @version 1.0
 */

public class Frames extends JFrame {
	JPanel contentPane;
	XYLayout xYLayout1 = new XYLayout();
	Panel panel1 = new Panel();
	Panel panel2 = new Panel();
	Panel panel3 = new Panel();
	Panel panel4 = new Panel();
	TextField textField1 = new TextField();
	CheckboxGroup checkboxGroup1 = new CheckboxGroup();
	Checkbox checkbox1 = new Checkbox();
	Checkbox checkbox2 = new Checkbox();
	Label label1 = new Label();
	TextField textField2 = new TextField();
	Label label2 = new Label();
	TextField textField3 = new TextField();
	Button button1 = new Button();

	//Construct the frame
	public Frames() 
	{
	    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
	    try {
	    	jbInit();
	    } catch(Exception e) {
	    	e.printStackTrace();
	    }
	}
	//Component initialization
	private void jbInit() throws Exception  
	{
	    //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
	    contentPane = (JPanel) this.getContentPane();
	    contentPane.setLayout(xYLayout1);
	    this.setSize(new Dimension(400, 300));
	    this.setTitle("Frame Title");
	    textField1.setText("                   ");
	    checkbox1.setCheckboxGroup(checkboxGroup1);
	    checkbox1.setLabel("high");
	    checkbox1.setState(true);
	    checkbox2.setCheckboxGroup(checkboxGroup1);
	    checkbox2.setLabel("low");
	    label1.setText("user");
	    textField2.setEchoChar('*');
	    textField2.setText("                  ");
	    label2.setText("passwd");
	    textField3.setText("                                       ");
	    button1.setLabel("Check");
	    button1.addActionListener(new java.awt.event.ActionListener() {
	    	public void actionPerformed(ActionEvent e) {
	    		button1_actionPerformed(e);
	    	}
	    });
	    panel1.add(checkbox1, null);
	    panel1.add(checkbox2, null);
	    contentPane.add(panel2,   new XYConstraints(116, 62, 209, 23));
	    panel2.add(label1, null);
	    panel2.add(textField1, null);
	    contentPane.add(panel3,   new XYConstraints(108, 101, 227, -1));
	    panel3.add(label2, null);
	    panel3.add(textField2, null);
	    contentPane.add(panel4,    new XYConstraints(248, 194, 88, 33));
	    panel4.add(button1, null);
	    contentPane.add(textField3,   new XYConstraints(41, 201, -1, -1));
	    contentPane.add(panel1, new XYConstraints(14, 52, 64, 89));
	}
	//Overridden so we can exit when window is closed
	protected void processWindowEvent(WindowEvent e) 
	{
	    super.processWindowEvent(e);
	    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
	    	System.exit(0);
	    }
	}

	void button1_actionPerformed(ActionEvent e) 
	{
		String s1,s2;
	    s1=String.valueOf(textField1.getText());
	    s2=String.valueOf(textField2.getText());
	    if(checkbox1.getState()){
		    if((s1 == "smart") && (s2 == "323232"))
		    	textField3.setText ("You input correctly");
		    else
		    	textField3.setText ("You input not correctly");
	    } else {
	    	if((s1 == "tom") && (s2 == "323232"))
	    		textField3.setText ("You input correctly");
	        else
	        	textField3.setText ("You input not correctly");
	    }
	}
}

passwd.java

package passwd;

import javax.swing.UIManager;
import java.awt.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: </p>
 * @author Smart
 * @version 1.0
 */

public class Passwd {
	boolean packFrame = false;

	//Construct the application
	public Passwd() 
	{
	    Frames frame = new Frames();
	    //Validate frames that have preset sizes
	    //Pack frames that have useful preferred size info, e.g. from their layout
	    if (packFrame) {
	    	frame.pack();
	    } else {
	    	frame.validate();
	    }
	    //Center the window
	    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	    Dimension frameSize = frame.getSize();
	    if (frameSize.height > screenSize.height) {
	    	frameSize.height = screenSize.height;
	    }
	    if (frameSize.width > screenSize.width) {
	    	frameSize.width = screenSize.width;
	    }
	    frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
	    frame.setVisible(true);
	}
  //Main method
	public static void main(String[] args) 
	{
	    try {
	    	UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	    } catch(Exception e) {
	    	e.printStackTrace();
	    }
	    new Passwd();
	}
}

jbcl的使用可以参考:http://blog.okgoes.com/index/index/detail?id=9&type=blog&k=MkTxKNjspe&t=1496288987

读完了?给作者一点支持

本文采用 CC BY 4.0 协议转载 · © 大苹果

评论(0)

登录 后参与评论。

  • 还没有评论,来抢沙发。

🔗 相关文章

Mysql 表被标记为崩溃,最后一次自动化修复失败

当 MySQL 日志中出现“表被标记为崩溃且自动修复失败”的提示时,通常表示 MySQL 在启动过程中检测到某个表的文件系统或存储引擎层出现了问题。这种情况通常会导致表无法正常使用,需要手动进行修复。以下是处理这种情况的一些步骤和方法: ### 1. **查看具体错误信息** 首先,需要查看 MySQL 错误日志以获取更多的错误信息。这可以帮助确定崩溃的表和具体的问题。 ```bash # 查看 MySQL 错误日志 tail -f /var/log/mysql/error.log ``` ### 2. **修复表** 不同的存储引擎有不同的修复工具,以下是常用的修复方法: #### **使用 `myisamchk` 修复 MyISAM 表** 如果崩溃的表使用的是 MyISAM 存储引擎,可以使用 `myisamchk` 工具来修复表。 1. 停止 MySQL 服务: ```bash sudo systemctl stop mysql ``` 2. 使用 `myisamchk` 修复表:

2024/8/11👍 0

mermaid.min.js的使用及介绍

`mermaid.min.js` 是一个 JavaScript 库,用于在浏览器中轻松绘制复杂的图表和流程图。Mermaid 通过使用简单的标记语言来描述图表,使得用户无需深入学习图表绘制的底层技术即可创建专业的图形。 在这篇文章中,我们将介绍 `mermaid.min.js` 的功能、应用场景、如何在项目中使用,以及一些常用的示例。 ## Mermaid 的功能 Mermaid 支持多种类型的图表,包括但不限于: 1. **流程图(Flowchart)**: - 用于表示流程或过程中的步骤。 - 支持各种节点和连线风格。 2. **序列图(Sequence Diagram)**: - 用于表示对象之间的交互。 - 展示消息的发送和接收过程。 3. **类图(Class Diagram)**: - 用于表示类及其关系。 - 支持类的属性和方法定义。 4. **状态图(State Diagram)**: - 用于描述系统状态及其转换。 - 适用于复杂的状态机建模。 5. **甘

2024/8/9👍 0

docker之Dockerfile及docker compose配置文件的说明及使用

Docker 的配置文件对于镜像构建和容器化应用的管理至关重要。在 Docker 中,主要的配置文件是 Dockerfile 和 docker-compose.yml。Dockerfile 用于构建镜像,而 docker-compose.yml 用于定义多容器应用。下面将详细介绍这两个文件的配置选项和用法。 ## Dockerfile 配置详解 **Dockerfile** 是一个文本文件,其中包含一组指令,用于定义如何构建 Docker 镜像。以下是 Dockerfile 中常用的指令及其用法: ### FROM `FROM` 指令用于指定基础镜像,是 Dockerfile 中的第一条指令。 ```dockerfile FROM node:14 ``` 上例中,`node:14` 是官方的 Node.js 版本 14 的镜像。 ### LABEL `LABEL` 用于为镜像添加元数据,以键值对形式存在。 ```dockerfile LABEL maintainer="your-email@example.com" LABE

2024/8/9👍 0