⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loveuaction.java

📁 该程序是用JAVA来实现图形学中的中点算法来画直线
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class loveuAction extends JFrame{
    JTextField Name1,Name2;  //名字输入域
    JTextArea Love;  //显示恋爱信息
    JButton Send;  //发送消息按钮

    public loveuAction(){
        super("恋爱测试程序(注:本程序仅供娱乐,勿信以为真。)");  //调用父类构造函数

        Container container=this.getContentPane();  //得到容器
        JPanel p=new JPanel();  //初始化一个面板
        Name1=new JTextField(10); //初始化名字输入域
        Name2=new JTextField(10);//初始化名字输入域
        p.add(new JLabel("作者:半罐啤酒 QQ:1140113896   "));  //增加程序标签
        p.add(new JLabel("你的姓名:")); //增加姓名标签
        p.add(Name1);  //增加名字输入域
        p.add(new JLabel("他/她的姓名:")); //增加姓名标签
        p.add(Name2);  //增加名字输入域
      container.add(p,BorderLayout.NORTH);  //在容器上增加面板

      Love=new JTextArea();  //初始化恋爱测试信息显示文本框
       container.add(new JScrollPane(Love),BorderLayout.CENTER);  //在容器上增加恋爱测试信息显示文本框

       Box box=new Box(BoxLayout.X_AXIS);  //初始化一个Box
        Send=new JButton();  //初始化发送按钮
        box.add(Send);
     container.add(box,BorderLayout.SOUTH);  //在容器上增加box
     box.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), Send);

       Action sendMessage = new AbstractAction() {  //发送消息Action
           public void actionPerformed(ActionEvent e){
               replaceMessage();  //更新恋爱测试消息显示框
            }
        };

        //jtfName2.getInputMap().put(KeyStroke.getKeyStroke("ENTER"),"send");
        Send.setAction(sendMessage);  //设置命令为发送消息
        Send.setText("确定");  //设置按钮文本

       setSize(650,400);  //设置窗口尺寸
       setVisible(true);  //设置窗口可视
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  //关闭窗口时退出程序
    }

    private void replaceMessage(){
        String message="i love you";
        int temp = (int) (Math.random() * 3);
        //System.out.println(temp);
        if(temp==0)
        {
             message=Name1.getText()+"和"+Name2.getText()+"恋爱测试结果是:"+"\n"+"你很爱她/他。\n";//显示测试结果
        }
    
        if(temp==1)
        {
             message=Name1.getText()+"和"+Name2.getText()+"恋爱测试结果是:"+"\n"+"你们两个不太合适,做个朋友是比较不错的。\n";//显示测试结果
        }
        if(temp==2)
        {
            message=Name1.getText()+"和"+Name2.getText()+"恋爱测试结果是:"+"\n"+"他/她很爱你。\n";//显示测试结果
        }
     Love.insert(message,Love.getDocument().getLength());  //插入消息到显示域未端
     }

   public static void main(String[] args){
      new loveuAction();
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -