首页 > 其他分享 >每日总结-23.11.27

每日总结-23.11.27

时间:2023-11-27 20:34:41浏览次数:42  
标签:总结 Box 23.11 27 JCheckBox add new JLabel createHorizontalStrut

package Interface;
import gongneng.BackGroundPanel;
import gongneng.FileTest;
import gongneng.selfData;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import static java.awt.Toolkit.getDefaultToolkit;
public class Introduction {
    FileTest f = new FileTest();
    JFrame jf = new JFrame("编辑资料");
    static final int WIDTH = 800;
    static final int HEIGHT = 650;
    //组装视图
    public void init() throws IOException {
        Toolkit kit = getDefaultToolkit();
        Dimension screenSize;
        screenSize = kit.getScreenSize();
        int width = screenSize.width;
        int height = screenSize.height;
        int x = (width - WIDTH) / 2;
        int y = (height - HEIGHT) / 2;
        jf.setBounds(x, y, WIDTH, HEIGHT);
        jf.setResizable(false);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        jf.setIconImage(ImageIO.read(new File("images/beijing.jpg")));
        BackGroundPanel bgPanel = new BackGroundPanel(ImageIO.read(new File("images/beijing.jpg")));
        //组装登录相关的内容
        Box userBox = Box.createVerticalBox();
        //昵称和QQ、
        Box nickBox = Box.createHorizontalBox();
        JLabel nickLabel = new JLabel("昵称");
        nickLabel.setFont(new Font("华文行楷",Font.BOLD,30));
        JTextField nickField = new JTextField("",15);
        JLabel qqLabel = new JLabel("qq");
        qqLabel.setFont(new Font("华文行楷",Font.BOLD,30));
        JTextField qqField = new JTextField("",15);
        nickBox.add(nickLabel);
        nickBox.add(Box.createHorizontalStrut(50));
        nickBox.add(nickField);
        nickBox.add(Box.createHorizontalStrut(10));
        nickBox.add(qqLabel);
        nickBox.add(Box.createHorizontalStrut(20));
        nickBox.add(qqField);
        //性别、微信
        Box sexBox = Box.createHorizontalBox();
        JLabel sexLabel = new JLabel("性别");
        sexLabel.setFont(new Font("华文行楷",Font.BOLD,30));
        JRadioButton male = new JRadioButton("男",false);
        JRadioButton female = new JRadioButton("女",false);
        ButtonGroup group = new ButtonGroup();
        group.add(male);
        group.add(female);
        JLabel weiXinLabel = new JLabel("微信");
        nickLabel.setFont(new Font("华文行楷",Font.BOLD,30));
        JTextField weiXinField = new JTextField("",15);
        sexBox.add(sexLabel);
        sexBox.add(Box.createHorizontalStrut(50));
        sexBox.add(male);
        sexBox.add(Box.createHorizontalStrut(50));
        sexBox.add(female);
        sexBox.add(Box.createHorizontalStrut(90));
        sexBox.add(weiXinLabel);
        sexBox.add(Box.createHorizontalStrut(30));
        sexBox.add(weiXinField);
        //生日
        Box birthBox = Box.createHorizontalBox();
        JLabel birthLabel =new JLabel("生日");
        birthLabel.setFont(new Font("华文行楷",Font.BOLD,30));
        JLabel yearLabel =new JLabel("年");
        JLabel monthLabel =new JLabel("月");
        JLabel dayLabel =new JLabel("日");
        String year[] = {"1987","1988","1989","1990","1991","1992","1993","1994","1995",
                "1996","1997","1998","1999","2000","2001","2002","2003","2004","2005"};
        JComboBox cb1 = new JComboBox(year);
        String month[] = {"1","2","3","4","5","6","7","8","9","10","11","12"};
        JComboBox cb2 = new JComboBox(month);
        String day[] = {"1","2","3","4","5","6","7","8","9","10",
                "11","12","13","14","15","16","17","18","19","20",
                "21","22","23","24","25","26","27","28","29","30","31"};
        JComboBox cb3 = new JComboBox(day);
        birthBox.add(birthLabel);
        birthBox.add(Box.createHorizontalStrut(50));
        birthBox.add(cb1);
        birthBox.add(Box.createHorizontalStrut(10));
        birthBox.add(yearLabel);
        birthBox.add(Box.createHorizontalStrut(10));
        birthBox.add(cb2);
        birthBox.add(Box.createHorizontalStrut(10));
        birthBox.add(monthLabel);
        birthBox.add(Box.createHorizontalStrut(10));
        birthBox.add(cb3);
        birthBox.add(Box.createHorizontalStrut(10));
        birthBox.add(dayLabel);
        //职业
        Box jobBox = Box.createHorizontalBox();
        JLabel jobLabel = new JLabel("职业");
        jobLabel.setFont(new Font("华文行楷",Font.BOLD,30));
        JTextField jobField = new JTextField("",15);
        jobBox.add(jobLabel);
        jobBox.add(Box.createHorizontalStrut(50));
        jobBox.add(jobField);
        //爱好
        Box hobbyBox = Box.createHorizontalBox();
        JLabel hobbyLabel = new JLabel("爱好");
        hobbyLabel.setFont(new Font("华文行楷",Font.BOLD,30));
        JCheckBox sing =  new JCheckBox("唱歌");
        JCheckBox dance = new JCheckBox("跳舞");
        JCheckBox basketball = new JCheckBox("打篮球");
        JCheckBox draw = new JCheckBox("画画");
        JCheckBox play = new JCheckBox("打游戏");
        JCheckBox read = new JCheckBox("阅读");
        JCheckBox act = new JCheckBox("表演");
        JCheckBox eat = new JCheckBox("吃");
        JCheckBox design = new JCheckBox("设计");
        hobbyBox.add(hobbyLabel);
        hobbyBox.add(Box.createHorizontalStrut(50));
        JCheckBox[] hobbyCheck = {basketball,play,read,act,dance,sing,eat,draw,design};
        for(int i = 0;i<9;i++){
            hobbyBox.add(hobbyCheck[i]);
        }
        //签名
        Box signBox = Box.createHorizontalBox();
        JLabel signLabel = new JLabel("签名");
        signLabel.setFont(new Font("华文行楷",Font.BOLD,30));
        JTextField signField = new JTextField("",15);
        signBox.add(signLabel);
        signBox.add(Box.createHorizontalStrut(50));
        signBox.add(signField);
        //个人说明
        Box pgBox  = Box.createHorizontalBox();
        JLabel pgLabel = new JLabel("个人说明");
        pgLabel.setFont(new Font("华文行楷",Font.BOLD,30));
        JTextArea pg=new JTextArea("",4,4);
        pg.setLineWrap(true);    //设置文本域中的文本为自动换行
        pgBox.add(pgLabel);
        signBox.add(Box.createHorizontalStrut(20));
        pgBox.add(pg);
        //按钮
        Box annvBox = Box.createHorizontalBox();
        JButton addButton = new JButton("添  加");
        addButton.setFont(new Font("华文行楷",Font.BOLD,25));
        JButton shanchuButton = new JButton("删  除");
        shanchuButton.setFont(new Font("华文行楷",Font.BOLD,25));
        JButton checkButton = new JButton("查看");
        checkButton.setFont(new Font("华文行楷",Font.BOLD,25));
        annvBox.add(addButton);
        annvBox.add(Box.createHorizontalStrut(50));
        annvBox.add(shanchuButton);
        annvBox.add(Box.createHorizontalStrut(50));
        annvBox.add(checkButton);
        Box jianjieBox = Box.createHorizontalBox();
        JTextArea jianjie = new JTextArea();
        jianjie.setVisible(false);
        jianjieBox.add(jianjie);
        selfData data = new selfData();

        class myListener implements ActionListener{
            @Override
            public void actionPerformed(ActionEvent e) {
                String sex = "";
                Object source = e.getSource();
                if(source == addButton){
                    if(f.find(nickField.getText())!=-1){
                        JOptionPane.showMessageDialog(null,"已存在!");
                        nickField.setText("");
                        qqField.setText("");
                        sex = "";
                        weiXinField.setText("");
                        signField.setText("");
                        pg.setText("");
                        return ;
                    }
                     if(male.isSelected()){
                         sex = "男";
                     }
                     if(female.isSelected()){
                         sex = "女";
                     }
                     String hobby = "";
                     if(draw.isSelected()) hobby += "画画";
                     if(basketball.isSelected()) hobby += "打篮球";
                     if(act.isSelected()) hobby += "表演";
                     if(eat.isSelected()) hobby += "吃";
                     if(play.isSelected()) hobby += "打游戏";
                     if(dance.isSelected()) hobby += "跳舞";
                     if(sing.isSelected()) hobby += "唱歌";
                     if(design.isSelected()) hobby += "设计";
                     if(read.isSelected()) hobby += "阅读";
                    String c1,c2,c3,job;
                    c1=(String)cb1.getSelectedItem();
                    c2=(String)cb2.getSelectedItem();
                    c3=(String)cb3.getSelectedItem();
                    String birth = c1+"年"+c2+"月"+c3+"日";

                    String nick = nickField.getText();
                    String qq = qqField.getText();
                    String weiXin = weiXinField.getText();
                    String Job = jobField.getText();
                    String sign = signField.getText();
                    String PG = pg.getText();
                    if (nick.equals(""))
                        nick = null;
                    if (sex.equals(""))
                        sex = null;
                    if (qq.equals(""))
                        qq = null;
                    if (weiXin.equals(""))
                        weiXin = null;
                    if (birth.equals(""))
                        birth = null;
                    if (Job.equals(""))
                        Job = null;
                    if (hobby.equals(""))
                        hobby = null;
                    if (sign.equals(""))
                        sign = null;
                    if (PG.equals(""))
                        PG = null;
                    data.setNick(nick);
                    data.setSex(sex);
                    data.setQq(qq);
                    data.setWeixin(weiXin);
                    data.setBirth(birth);
                    data.setJob(Job);
                    data.setHobby(hobby);
                    data.setSign(sign);
                    data.setPg(PG);
                    f.add(data);
                    f.writefile();
                    JOptionPane.showMessageDialog(jf,"保存成功!");
                }
                if(source == shanchuButton){
                    String nick = nickField.getText();
                    int flag = f.find(nick);
                    if(flag == -1){
                        JOptionPane.showMessageDialog(null,"没有找到该昵称的人!");
                    }
                    else{
                        f.delete(nick);
                        f.writefile();
                        JOptionPane.showMessageDialog(null,"删除成功!");
                    }
                }
                if(source == checkButton){
                    new chazhao();
                    jf.dispose();
                }
            }
        }
        myListener my = new myListener();
        addButton.addActionListener(my);
        //删除监听事件
        shanchuButton.addActionListener(my);
        //查找监听事件
        checkButton.addActionListener(my);
        createVStruct(userBox, nickBox, sexBox, birthBox, jobBox);
        createVStruct(userBox, hobbyBox, signBox, pgBox, annvBox);
        userBox.add(jianjieBox);
        bgPanel.add(userBox);
        jf.add(bgPanel);
        jf.setVisible(true);
    }
    private void createVStruct(Box userBox, Box hobbyBox, Box signBox, Box pgBox, Box annvBox) {
        userBox.add(Box.createVerticalStrut(30));
        userBox.add(hobbyBox);
        userBox.add(Box.createVerticalStrut(30));
        userBox.add(signBox);
        userBox.add(Box.createVerticalStrut(30));
        userBox.add(pgBox);
        userBox.add(Box.createVerticalStrut(30));
        userBox.add(annvBox);
    }
    public static void main(String[] args) throws IOException {
        new Introduction().init();
    }
}

 

标签:总结,Box,23.11,27,JCheckBox,add,new,JLabel,createHorizontalStrut
From: https://www.cnblogs.com/laobing6214/p/17860374.html

相关文章

  • 2023-11-27 记录react拖拽组件——react-draggable试用方法
    安装:yarnaddreact-draggable注:如果你用npm安装失败可以尝试使用yarm,我就是npmi react-draggable报错了,用yarn装才好普通使用://引入importDraggablefrom'react-draggable';constDraggableCore:any=Draggable;//使用<div><DraggableCore><div>666&l......
  • linux基础总结
    Linux操作系统作为一种开源、强大且灵活的操作系统,广泛用于服务器、嵌入式设备以及个人计算机。对于初学者来说,了解Linux的基础知识是踏上学习Linux之旅的第一步。1.Linux的文件系统在Linux中,一切皆文件。文件系统是Linux的核心组成部分之一,它以层次结构的方式组织文件和目录。......
  • 2023-2024-1 20232301《网络》第4周总结
    教材学习内容总结教材学习中的问题和解决过程问题1:没有明白安全生态系统和自然生态系统的联系问题1解决方案:询问chatgpt,其给出了详细的回答,如下:安全生态系统(CybersecurityEcosystem)和自然生态系统(NaturalEcosystem)之间的联系主要体现在借鉴自然生态系统的原则和概念,以加强......
  • Weblogic < 10.3.6 'wls-wsat' XMLDecoder 反序列化漏洞(CVE-2017-10271)
    Weblogic<10.3.6'wls-wsat'XMLDecoder反序列化漏洞(CVE-2017-10271)Weblogic的WLSSecurity组件对外提供webservice服务,其中使用了XMLDecoder来解析用户传入的XML数据,在解析的过程中出现反序列化漏洞,导致可执行任意命令。环境搭建cdweblogic/CVE-2017-10271docker-compose......
  • 总结
    今天修改了一下C/S作业,然后改了一下flash动画。                  ......
  • UVA11275 3D Triangles 题解
    LinkUVA112753DTrianglesQuestion给你三维空间中的两个三角形,请判断它们是否有公共点。Solution如果在三维空间中相交,那么,肯定有一个三角形的某一条边穿过了另外一个三角形Code#include<bits/stdc++.h>usingnamespacestd;constdoubleeps=1e-9;structPoint3{......
  • 前缀和算法总结
    前缀和思维导图:一维前缀和算法模版:1#include<iostream>23usingnamespacestd;45constintN=100010;67intn,m;8ints[N];910intmain()11{12scanf("%d%d",&n,&m);13for(inti=1;i<=n;i++)14......
  • 每日总结11.27
    观察者模式通过本次实验掌握以下内容:1、理解观察者模式的动机,掌握该模式的结构;2、能够利用观察者模式解决实际问题。实验任务:股票提醒当股票的价格上涨或下降5%时,会通知持有该股票的股民,当股民听到价格上涨的消息时会买股票,当价格下降时会大哭一场。 Client.java:publiccl......
  • 【Python进阶】第6篇:Python的死锁和IP地址详解。总结md文档集合(已分享,附代码)
    本文从14大模块展示了python高级用的应用。分别有Linux命令,多任务编程、网络编程、Http协议和静态Web编程、html+css、JavaScript、jQuery、MySql数据库的各种用法、python的闭包和装饰器、mini-web框架、正则表达式等相关文章的详细讲述。全套笔记和代码自取地址:请移步这里感......
  • 11月27日每日学习
    完成将生成的加减乘除算术添加到数据库中,并且将算数从数据库取出来运行结果源代码packagedao;importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.util.Random;importjava.util.Scanner;importutil.DBUtil;......