表白 java

表白 java

  1. 导入javax maven依赖
  2. 新建类继承JFrame

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;

public class Love extends Frame {

    public static void main(String[] args) {
        EventQueue.invokeLater(() -> {
            try {
                Love frame = new Love();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }

    /**
     * Create the frame.
     */
    public Love() {
        JFrame f = new JFrame("一个简单窗口");
        //设置窗体左上角与显示屏左上角的坐标,     
        f.setLocation(300, 300); //离显示屏上边缘300像素,里显示屏左边缘300像素
        f.setSize(300, 200); //设置窗体的大小为300*200像素大小
        f.setResizable(false);//设置窗体是否可以调整大小,参数为布尔值
        //设置窗体可见,没有该语句,窗体将不可见,此语句必须有,否则没有界面就没有如何意义了
        f.setVisible(true);
        //用户单击窗口的关闭按钮时程序执行的操作
        f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
        f.setBounds(100, 100, 450, 300);
        JPanel contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        f.setContentPane(contentPane);
        contentPane.setLayout(null);

        JLabel label = new JLabel("小姐姐处对象吗?");
        label.setFont(new Font("幼圆", Font.PLAIN, 18));
        label.setBounds(147, 20, 211, 41);
        contentPane.add(label);

        JButton button = new JButton("好的");
        button.addActionListener(arg0 -> JOptionPane.showMessageDialog(null, "恭喜!成功拿下!", "表白幺~", JOptionPane.PLAIN_MESSAGE));
        button.setBounds(98, 179, 93, 23);
        contentPane.add(button);

        JButton button_1 = new JButton("不行");
        button_1.addActionListener(e -> {
            boolean flag = false;
            int isDone = JOptionPane.showConfirmDialog(null, "房子写你名", "表白~", JOptionPane.YES_NO_OPTION);
            if (isDone == JOptionPane.NO_OPTION) {
                isDone = JOptionPane.showConfirmDialog(null, "我会做饭", "表白~", JOptionPane.YES_NO_OPTION);
                if (isDone == JOptionPane.NO_OPTION) {
                    isDone = JOptionPane.showConfirmDialog(null, "我会洗衣服", "表白~", JOptionPane.YES_NO_OPTION);
                    if (isDone == JOptionPane.NO_OPTION) {
                        JOptionPane.showMessageDialog(null, "现在可以成为我女票吗?", "表白幺~", JOptionPane.PLAIN_MESSAGE);
                    } else {
                        flag = true;
                    }
                } else {
                    flag = true;
                }
            } else {
                flag = true;
            }

            if (flag) {
                JOptionPane.showMessageDialog(null, "恭喜!成功拿下!", "表白幺~", JOptionPane.PLAIN_MESSAGE);
            }

        });
        button_1.setBounds(251, 179, 93, 23);
        contentPane.add(button_1);

        JLabel lblNewLabel = new JLabel("");
        lblNewLabel.setIcon(new ImageIcon("love.png"));
        lblNewLabel.setBounds(157, 57, 114, 98);
        contentPane.add(lblNewLabel);
    }

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

转发:https://blog.csdn.net/xqnode/article/details/106243064?utm_medium=distribute.pc_feed.none-task-blog-alirecmd-8.nonecase&depth_1-utm_source=distribute.pc_feed.none-task-blog-alirecmd-8.nonecase&request_id=

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值