Java -- 使用Awt、Swing实现一个简历

代码:

package awt.second;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @program: sadd
 * @description:
 * @author: YuleXue
 * @create: 2018-11-21 14:30
 **/

public class MySimpleIntroduce implements ActionListener {
    private JFrame jFrame;//大窗口
    private JPanel jPanel;//标题栏
    private JPanel personal;//个人信息
    private JPanel education;//教育背景
    private JPanel skills;//技能概述
    private JPanel hobbies;//兴趣爱好
    private JPanel self_assessment;//自我评价
    JTextArea jTextAreal1;

    /**
     * 初始化大窗口
     */
    public void initFrame(){
        jFrame = new JFrame();
        jFrame.setLayout(new GridLayout(0,1));
        jFrame.setSize(620,736);
        jFrame.setLocation(400,0);
        jFrame.setTitle("个人简历");
        jFrame.setVisible(true);
    }

    /**
     * 初始化所有 panel
     */
    public void initPanel(){

        jPanel = new JPanel();
        personal = new JPanel();
        education = new JPanel();
        skills = new JPanel();
        hobbies = new JPanel();
        self_assessment = new JPanel();
        //创建具有“浮雕化”外观效果的边框
        Border etched = BorderFactory.createEtchedBorder();
        Border border1 = BorderFactory.createTitledBorder(etched,"个人信息(Personal Info)");
        Border border2 = BorderFactory.createTitledBorder(etched,"教育背景(Education)");
        Border border3 = BorderFactory.createTitledBorder(etched,"技能概述(Skills)");
        Border border4 = BorderFactory.createTitledBorder(etched,"兴趣爱好(Hobbies)");
        Border border5 = BorderFactory.createTitledBorder(etched,"自我评价(Self-assessment)");
        personal.setBorder(border1);
        education.setBorder(border2);
        skills.setBorder(border3);
        hobbies.setBorder(border4);
        self_assessment.setBorder(border5);
        //设置内容窗格,将所有 panel 添加到内容窗格中
        Container pane = jFrame.getContentPane();
        pane.add(jPanel);
        pane.add(education);
        pane.add(skills);
        pane.add(hobbies);
        pane.add(self_assessment);
    }

    /**
     * 初始化标题栏,jPanel 初始化
     */
    public void initJpanel(){

        jPanel.setLayout(new BorderLayout());
        //设置照片
        ImageIcon icon1 = new ImageIcon("C:\\Users\\小玉沉香\\Desktop\\1.png");
        JLabel jLabell = new JLabel(icon1);
        //添加照片
        jPanel.add(jLabell,BorderLayout.WEST);

    }

    /**
     * personal初始化
     */
    public void initPersonal(){

        personal.setLayout(new GridLayout(4,4));
        JPanel sex = new JPanel();
        sex.setLayout(new GridLayout(1,2));
        //设置标签和单选按钮
        JLabel jLabel1 = new JLabel("姓名:");
        JLabel jLabel2 = new JLabel("性别:");
        JRadioButton jRadioButton1 = new JRadioButton("男");
        JRadioButton jRadioButton2 = new JRadioButton("女");
        ButtonGroup buttonGroup1 = new ButtonGroup();
        buttonGroup1.add(jRadioButton1);
        buttonGroup1.add(jRadioButton2);
        JLabel jLabel3 = new JLabel("出生年月:");
        JLabel jLabel4 = new JLabel("民族:");
        JLabel jLabel5 = new JLabel("政治面貌:");
        JLabel jLabel6 = new JLabel("电话:");
        JLabel jLabel7 = new JLabel("住址:");
        JLabel jLabel8 = new JLabel("邮箱:");

        //设置文本框
        JTextField jTextField1 = new JTextField();
        JTextField jTextField2 = new JTextField();
        JTextField jTextField3 = new JTextField();
        JTextField jTextField4 = new JTextField();
        JTextField jTextField5 = new JTextField();
        JTextField jTextField6 = new JTextField();
        JTextField jTextField7 = new JTextField();

        //添加组件
        personal.add(jLabel1);
        personal.add(jTextField1);
        personal.add(jLabel2);
        personal.add(sex);
        sex.add(jRadioButton1);
        sex.add(jRadioButton2);
        personal.add(jLabel3);
        personal.add(jTextField2);
        personal.add(jLabel4);
        personal.add(jTextField3);
        personal.add(jLabel5);
        personal.add(jTextField4);
        personal.add(jLabel6);
        personal.add(jTextField5);
        personal.add(jLabel7);
        personal.add(jTextField6);
        personal.add(jLabel8);
        personal.add(jTextField7);

        //将 personal 添加到 jPanel 中去
        jPanel.add(personal,BorderLayout.CENTER);
    }

    /**
     * education初始化
     */
    public void initEducation(){
        education.setLayout(new GridLayout(2,1));

        //设置 panel
        JPanel eduBackground = new JPanel();
        eduBackground.setLayout(new GridLayout(1,7));
        JPanel majorCourse = new JPanel();
        majorCourse.setLayout(new GridLayout(1,7));
        education.add(eduBackground);
        education.add(majorCourse);

        //设置 label
        JLabel eduLabel = new JLabel("学历:");
        JLabel courseLabel = new JLabel("主修课程:");

        //设置 button 并添加
        JRadioButton primary = new JRadioButton("小学");
        JRadioButton middle = new JRadioButton("初中");
        JRadioButton high = new JRadioButton("高中");
        JRadioButton college = new JRadioButton("大学");
        JRadioButton graduate = new JRadioButton("研究生");
        JRadioButton doctor = new JRadioButton("博士");

        ButtonGroup buttonGroup2 = new ButtonGroup();
        buttonGroup2.add(primary);
        buttonGroup2.add(middle);
        buttonGroup2.add(high);
        buttonGroup2.add(college);
        buttonGroup2.add(graduate);
        buttonGroup2.add(doctor);

        eduBackground.add(eduLabel);
        eduBackground.add(primary);
        eduBackground.add(middle);
        eduBackground.add(high);
        eduBackground.add(college);
        eduBackground.add(graduate);
        eduBackground.add(doctor);

        //设置复选框并添加
        JCheckBox jCheckBox1 = new JCheckBox("Java");
        JCheckBox jCheckBox2 = new JCheckBox("数据结构");
        JCheckBox jCheckBox3 = new JCheckBox("软件工程");
        JCheckBox jCheckBox4 = new JCheckBox("数据库");
        JCheckBox jCheckBox5 = new JCheckBox("汇编语言");
        JCheckBox jCheckBox6 = new JCheckBox("操作系统");

        majorCourse.add(courseLabel);
        majorCourse.add(jCheckBox1);
        majorCourse.add(jCheckBox2);
        majorCourse.add(jCheckBox3);
        majorCourse.add(jCheckBox4);
        majorCourse.add(jCheckBox5);
        majorCourse.add(jCheckBox6);

    }

    /**
     * skills初始化
     */
    public void initSkills(){
        skills.setLayout(new BorderLayout());
        ImageIcon icon2 = new ImageIcon("C:\\Users\\小玉沉香\\Desktop\\2.jpg");
        JLabel jLabelq1 = new JLabel(icon2);
        JLabel jLabelq2 = new JLabel(icon2);
        JLabel jLabelq3 = new JLabel(icon2);
        JLabel jLabelq4 = new JLabel(icon2);

        JPanel s1 = new JPanel();
        JPanel s2 = new JPanel();

        s1.setLayout(new GridLayout(4,1));
        s2.setLayout(new GridLayout(4,1));

        skills.add(s1,BorderLayout.WEST);
        skills.add(s2,BorderLayout.CENTER);

        JLabel sL1 = new JLabel("    精通JAVA/JavaScript,熟悉Java多线程,Socket等;");
        JLabel sL2 = new JLabel("    熟悉常见设计模式,精通Spring,MyBatis等流行开源框架;");
        JLabel sL3 = new JLabel("    熟悉数据库原理和常用性能优化技术;");
        JLabel sL4 = new JLabel("    CET-6,有优秀的听说读写能力,能用英语进行日常交流;");

        s1.add(jLabelq1);s1.add(jLabelq2);s1.add(jLabelq3);s1.add(jLabelq4);
        s2.add(sL1);s2.add(sL2);s2.add(sL3);s2.add(sL4);

    }

    /**
     * hobbies初始化
     */
    public void initHobbies(){

        hobbies.setLayout(new GridLayout(2,1));
        JPanel panel1 =  new JPanel();
        panel1.setLayout(new GridLayout(1,7));
        Border etched = BorderFactory.createEtchedBorder();
        Border border1l1 = BorderFactory.createTitledBorder(etched,"请选择您的兴趣爱好");
        panel1.setBorder(border1l1);
        JPanel panel2 =  new JPanel();

        hobbies.add(panel1);
        hobbies.add(panel2);
        //设置复选框
        JCheckBox jCheckBoxl1 = new JCheckBox("健身");
        JCheckBox jCheckBoxl2 = new JCheckBox("读书");
        JCheckBox jCheckBoxl3 = new JCheckBox("唱歌");
        JCheckBox jCheckBoxl4 = new JCheckBox("跳舞");
        JCheckBox jCheckBoxl5 = new JCheckBox("爬山");
        JCheckBox jCheckBoxl6 = new JCheckBox("做饭");
        JCheckBox jCheckBoxl7 = new JCheckBox("打游戏");
        //设置文本框
        jTextAreal1 = new JTextArea(3,52);
        jTextAreal1.setEditable(false);
        //进行添加
        panel1.add(jCheckBoxl1);
        panel1.add(jCheckBoxl2);
        panel1.add(jCheckBoxl3);
        panel1.add(jCheckBoxl4);
        panel1.add(jCheckBoxl5);
        panel1.add(jCheckBoxl6);
        panel1.add(jCheckBoxl7);
        //设置滚动窗口,并添加文本域
        JScrollPane jScrollPanel1 = new JScrollPane(jTextAreal1);
        jScrollPanel1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        panel2.add(jScrollPanel1);

        //添加事件监听
        jCheckBoxl1.addActionListener(this);
        jCheckBoxl2.addActionListener(this);
        jCheckBoxl3.addActionListener(this);
        jCheckBoxl4.addActionListener(this);
        jCheckBoxl5.addActionListener(this);
        jCheckBoxl6.addActionListener(this);
        jCheckBoxl7.addActionListener(this);

    }

    /**
     * self_assessment初始化
     */
    public void initSelf_assessment(){

        JTextArea jTextArea = new JTextArea(6,52);
        //设置滚动窗口,并添加文本域
        JScrollPane jScrollPane = new JScrollPane(jTextArea);
        jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        self_assessment.add(jScrollPane);

    }

    /**
     * 启动方法
     */
    public void start(){
        initFrame();//窗口初始化
        initPanel();//初始化 panel
        initJpanel();//初始化布局中的第一个面板
        initPersonal();
        initEducation();
        initSkills();
        initHobbies();
        initSelf_assessment();
    }

    /**
     * main() 方法
     * @param args
     */
    public static void main(String[] args) {
        MySimpleIntroduce mySimpleIntroduce = new MySimpleIntroduce();
        mySimpleIntroduce.start();
    }

    /**
     * 重写 actionPerformed(ActionEvent e) 方法
     * @param e
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        JCheckBox source1 = (JCheckBox)e.getSource();
        String str1 = e.getActionCommand();

        if(source1.isSelected() == true) {
            jTextAreal1.append("我喜欢: " + str1 +"\n");
        }else if(source1.isSelected() == false) {
            jTextAreal1.append("我突然不喜欢" + str1 +"了^_^"+"\n");
        }

    }
}

实现结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xyxy66/article/details/84930491
0条评论
添加一条新回复