mirror of
https://github.com/Dichgrem/Java.git
synced 2026-02-05 05:51:57 -05:00
update:demo12
This commit is contained in:
38
com/study/demo12/VerifyCodeFrame.java
Normal file
38
com/study/demo12/VerifyCodeFrame.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.study.demo12;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class VerifyCodeFrame extends Frame {
|
||||
private Label codeLabel;
|
||||
|
||||
public VerifyCodeFrame() {
|
||||
setTitle("验证码生成窗口");
|
||||
setSize(300, 150);
|
||||
setLayout(new FlowLayout());
|
||||
|
||||
Button codeButton = new Button("获取验证码");
|
||||
codeLabel = new Label("点击按钮获取验证码");
|
||||
|
||||
codeButton.addActionListener(e -> {
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
String last4Digits = timestamp.substring(timestamp.length() - 4);
|
||||
codeLabel.setText("CODE" + last4Digits);
|
||||
});
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
add(codeButton);
|
||||
add(codeLabel);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new VerifyCodeFrame();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user