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(); } }