Java课程设计----仿头歌系统(educoder)闯关小程序,附课程设计报告册和源码

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

这是java语言的课程设计,主要采用的java swing图形界面编程。
源码和报告册在我的下载内容里面。
有需要的同学可自行前往免费下载


一、任务概述

编程要求

设计一个闯关型实训任务,为该任务起一个恰当的名字作为课程设计题目,表明该任务主要涉及的Java知识点;实训任务至少包含三关,每关的名称要能直观的表明该关所对应的任务,每一关包含六个方面的内容:
面的内容:
1.任务概述
2.相关知识
3.编程要求
4.测试说明
5.题目代码
6.参考答案及程序运行截图
实训任务所对应的知识点从以下内容中任选:
1.基本数据类型与数组
2.运算符、表达式和语句
3.类与对象
4.子类与继承
5.接口与实现
6.内部类与异常类
7.常用实用类

运行界面

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

二、代码实现

1.BackGround组件类

package Component;
import javax.swing.*;
import java.awt.*;
public class BackGround extends JPanel {
    Image image;
    public BackGround(Image image) {
        this.image = image;
    }
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(image,0,0,this.getWidth(),this.getHeight(),null);
    }
}

2.欢迎界面

代码如下(示例):

package WIndows;
import Component.BackGround;
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;
public class Welcome {
    private int WIDTH = 1024;//定义窗口的宽度
    private int HEIGHT = 612;//定义窗口的高度
    JFrame win = new JFrame("头歌教学实践平台");//初始化一个窗口
    JButton enter;//定义一个开始按钮
    JLabel titile;//定义一个标题标签
    BackGround backGround;//定义一个背景面板对象

    //定义类的构造方法
    public Welcome() throws IOException {
        //初始化背景面板对象
        backGround =  new BackGround(ImageIO.read(new File("images\\welcome.jpg")));
        backGround.setLayout(null);//设置背景面板的布局模式
        backGround.setSize(WIDTH,HEIGHT);//设置背景面板的大小
        titile = new JLabel("欢迎进入JAVA实训");//初始化标签组件
        titile.setBounds((WIDTH-200)/2,130,300,40);//设置标签组件的大小及位置
        titile.setFont(new Font("微软雅黑",Font.PLAIN,25));//设置JLable中字体的属性
        titile.setForeground(Color.BLACK);//设置JLable中字体的颜色
        enter = new JButton("开始闯关");//初始化开始按钮
        //给按钮注册监听器
        enter.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    new Question_1();
                    win.dispose();
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
            }
        });
        enter.setBounds((WIDTH-100)/2,HEIGHT/2,100,40);//设置开始按钮的位置及大小
        //把组件添加到背景面板中进行绘制
        backGround.add(enter);//把开始按钮添加到背景面板容器中
        backGround.add(titile);//把标题标签添加到背景面板容器中
        win.add(backGround);
        //设置窗口的各个属性
        win.setIconImage(ImageIO.read(new File("images\\app.jpg")));
        win.setSize(WIDTH,HEIGHT);
        win.setBounds((Toolkit.getDefaultToolkit().getScreenSize().width - WIDTH)/2,(Toolkit.getDefaultToolkit().getScreenSize().height - HEIGHT)/2,WIDTH,HEIGHT);
        win.setLayout(new BorderLayout());
        win.setVisible(true);
        win.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    public static void main(String[] args) {
        try {
            new Welcome();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

3.关卡1

package WIndows;
import Component.BackGround;
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;
public class Question_1 {
    private int WIDTH = 1024;//定义窗口的宽度
    private int HEIGHT = 612;//定义窗口的高度
    JFrame win = new JFrame("Java小实训");//初始化一个窗口
    BackGround backGroundtotal;//定义一个背景面板对象
    //设置右侧组件
    BackGround backGround_RIGHT = new BackGround(ImageIO.read(new File("images\\guanka1.png")));
    JTextField answer1 = new JTextField();
    JTextField answer2 = new JTextField();
    JTextField answer3 = new JTextField();
    JTextField answer4 = new JTextField();
    JLabel label1 = new JLabel("语句1:");
    JLabel label2 = new JLabel("语句2:");
    JLabel label3 = new JLabel("语句3:");
    JLabel label4 = new JLabel("语句4:");
    JButton enter = new JButton();//评测按钮
    JButton next = new JButton("下一关");//下一关按钮
    String input1 = "System.out.println(\"姓名:张三\");";
    String input2 = "System.out.println(\"年龄:25\");";
    String input3 = "System.out.println(\"职业:JAVA高级工程师\");";
    String input4 = "System.out.println(\"薪资:15K\");";
    //设置左侧组件
    JPanel left_screen = new JPanel();
    JLabel title = new JLabel("第一关:Java输出语句");
    JTextArea jTextArea = new JTextArea();
    JTextArea jTextArea1 = new JTextArea();
    JLabel jLabel = new JLabel();
    JScrollPane jScrollPane;
    //构造方法
     public Question_1() throws IOException {
        backGroundtotal =  new BackGround(ImageIO.read(new File("images\\welcome.jpg")));
        backGroundtotal.setLayout(null);
        backGroundtotal.setBounds(0,0,WIDTH,HEIGHT);
        left_screen.setBounds(0,0,300,612);
        //左侧组件,设置各组件的属性
        title.setBounds(0, 0, 250, 50);
        title.setFont(new Font("楷体", Font.BOLD, 25));
        title.setForeground(Color.BLACK);
        left_screen.add(title);
        jTextArea.setLineWrap(true);
        jTextArea.setEditable(false);
        jTextArea.setText("(1)任务概述:"+"\n"+"编写你的第一个Java程序,能正确使用Java的输出语句;" + "\n" +
                "(2)相关知识:"+"\n"+"Java中输出语句格式为System.out.println();" + "\n" +
                "(3)编程要求:"+"\n"+"在Begin-End区域内编辑器中编写代码输出如下结果:"+"\n"+"(4)测试说明:"+"\n"+"平台会对你的代码进行运行测试,如果实际输出与预期相同,则算通关."+
                "\n"+"开始你的任务吧,祝你成功!"+"\n"+"-----------------------------"+"\n"+"(5)参考答案:"+"\n"+
                "语句1:System.out.println(\"姓名:张三\");"+"\n"+"语句2:System.out.println(\"年龄:25\");"+"\n"+
                "语句3:System.out.println(\"职业:JAVA高级工程师\");"+"\n"+"语句4:System.out.println(\"薪资:15K\");");
        jTextArea.setBounds(0, 50, 300, 100);
        jTextArea.setFont(new Font("宋体",Font.BOLD,18));
        //
        jLabel.setIcon(new ImageIcon("images\\question1.jpg"));
        jLabel.setBounds(50, 120, 300, 140);
        //给滚动面板设置大小
        jScrollPane = new JScrollPane(jTextArea) {
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(300,400);
            }
        };
        left_screen.add(jScrollPane);
        left_screen.add(jLabel);
        win.add(left_screen);
//右侧组件
        enter.setIcon(new ImageIcon("images\\enter.png"));
        //给评测按钮注册监听器
        enter.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String text1 = answer1.getText();
                String text2 = answer2.getText();
                String text3 = answer3.getText();
                String text4 = answer4.getText();
                if (text1.equals(input1) && text2.equals(input2) && text3.equals(input3) && text4.equals(input4)) {
                    JOptionPane.showMessageDialog(null, "测试通过,将自动进入下一关", "通关提示框", JOptionPane.INFORMATION_MESSAGE);
                    try {
                        new Question_2();
                        win.dispose();
                    } catch (IOException ioException) {
                        ioException.printStackTrace();
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "评测失败", "失败提示框", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        //给下一关按钮注册监听器
        next.setBounds(710,535,70,35);
        next.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    JOptionPane.showMessageDialog(null, "即将进入第二关", "消息提示框", JOptionPane.INFORMATION_MESSAGE);
                    new Question_2();
                    win.dispose();
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
            }
        });

        //进行右侧组件的排版
        enter.setBounds(600, 535, 80, 35);
        label1.setBounds(500, 360, 50, 25);
        answer1.setBounds(550, 360, 250, 25);
        label2.setBounds(500, 385, 50, 25);
        answer2.setBounds(550, 385, 250, 25);
        label3.setBounds(500, 410, 50, 25);
        answer3.setBounds(550, 410, 250, 25);
        label4.setBounds(500, 435, 50, 25);
        answer4.setBounds(550, 435, 250, 25);
        backGround_RIGHT.setBounds(300, 0, 993, 355);
        //添加组件到窗口中去
        backGroundtotal.add(left_screen);
        backGroundtotal.add(next);
        backGroundtotal.add(backGround_RIGHT);
        backGroundtotal.add(enter);
        backGroundtotal.add(label1);
        backGroundtotal.add(label3);
        backGroundtotal.add(label4);
        backGroundtotal.add(answer1);
        backGroundtotal.add(answer2);
        backGroundtotal.add(answer3);
        backGroundtotal.add(answer4);
        backGroundtotal.add(label2);
        win.add(backGroundtotal);
        //设置窗口的各属性
        win.setIconImage(ImageIO.read(new File("images\\logo.jpeg")));
        win.setSize(WIDTH, HEIGHT);
        win.setBounds((Toolkit.getDefaultToolkit().getScreenSize().width - WIDTH) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - HEIGHT) / 2, WIDTH, HEIGHT);
        win.setLayout(null);
        win.setVisible(true);
        win.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    //主测试函数
    public static void main(String[] args) throws IOException {
        new Question_1();
    }
}

关卡2

package WIndows;
import Component.BackGround;
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;
public class Question_2 {
    private int WIDTH = 1024;//定义窗口的宽度
    private int HEIGHT = 612;//定义窗口的高度
    JFrame win = new JFrame("Java小实训");//初始化一个窗口
    BackGround backGroundtotal;//定义一个背景面板对象
    //设置右侧组件
    BackGround backGround = new BackGround(ImageIO.read(new File("images\\guanka2.png")));
    JTextField answer1 = new JTextField();
    JTextField answer2 = new JTextField();
    JTextField answer3 = new JTextField();
    JTextField answer4 = new JTextField();
    JLabel label1 = new JLabel("语句1:");
    JLabel label2 = new JLabel("语句2:");
    JLabel label3 = new JLabel("语句3:");
    JLabel label4 = new JLabel("语句4:");
    JButton enter = new JButton();
    JButton last = new JButton();//上一关按钮
    JButton next = new JButton("下一关");//下一关按钮
    String input1 = "Dog wuhuarou = new Dog();";
    String input2 = "wuhuarou.name = \"五花肉\";";
    String input3 = "wuhuarou.color = \"棕色\";";
    String input4 = "wuhuarou.variety = \"阿拉斯加\";";
    //设置左侧组件
    JPanel left_screen = new JPanel();
    JLabel title = new JLabel("第二关:Java类与对象");
    JTextArea jTextArea = new JTextArea();
    JLabel jLabel = new JLabel();
    JScrollPane jScrollPane;
    public Question_2() throws IOException {
        backGroundtotal =  new BackGround(ImageIO.read(new File("images\\welcome.jpg")));
        backGroundtotal.setLayout(null);
        backGroundtotal.setBounds(0,0,WIDTH,HEIGHT);
        left_screen.setBounds(0,0,300,612);
        //左侧组件
        title.setBounds(0, 0, 250, 50);
        title.setFont(new Font("楷体", Font.BOLD, 25));
        title.setForeground(Color.BLACK);
        left_screen.add(title);
        jTextArea.setLineWrap(true);
        jTextArea.setEditable(false);
        jTextArea.setText("(1)任务概述:"+"\n"+"学习Java中类与对象的概念,并学会创建对象和调用方法;" + "\n" +"-----------------------------"+"\n"+
                "(2)相关知识:"+"\n"+"为了完成本关任务,你需要掌握:1、什么是类和对象;2、怎么创建对象并使用对象的属性和方法。" + "\n" +
                "1.什么是类:"+"\n"+"类:类是一个模板,它描述一类对象的行为和属性。"+"\n"+"对象:对象是类的一个实例,有 属性 和 行为。 "+"\n"+
                "举个例子:"+"\n"+"人是一个 “类”,小明就是人的 “对象” ,女生/男生是一个类,你的女朋友/男朋友就是一个对象,这个对象的属性有:名字,性别,年龄;行为有:吃饭、睡觉、学习等。"+"\n"+
                "我们可以发现创建对象使用的公式就是:"+"\n"+"  类名 对象名 = new 类名();"+"\n"+"给对象的属性赋值:"+"\n"+"  对象名.属性名 = 值;"+"\n"+"使用对象的属性:"+"\n"+
                "  对象名.属性名"+"\n"+"调用对象的方法:"+"\n"+"  对象名.方法名();"+"\n"+
                "-----------------------------"+"\n"+
                "(3)编程要求:"+"\n"+"我已经为你创建了一个Dog类,如下图所示,你只需要补全右侧图片中的语句1-语句4,共四条语句,使得输出结果如下:"+"\n"+
                "名字:五花肉,毛色:棕色,品种:阿拉斯加"+"\n"+
                "-----------------------------"+"\n"+
                "(4)测试说明:"+"\n"+"平台会对你的代码进行运行测试,如果实际输出与预期相同,则算通关."+"\n"+
                "注意:赋值运算符两侧需加空格,例如name = libai是正确的,而name=libai是错误的。"+"\n"+
                "\n"+"开始你的任务吧,祝你成功!"+"\n"+"-----------------------------"+"\n"+"(5)参考答案:"+"\n"+
                "语句1:Dog wuhuarou = new Dog();"+"\n"+"语句2:wuhuarou.name = \"五花肉\";"+"\n"+
                "语句3:wuhuarou.color = \"棕色\";"+"\n"+"语句4:wuhuarou.variety = \"阿拉斯加\";");
        jTextArea.setBounds(0, 50, 300, 100);
        jTextArea.setFont(new Font("宋体",Font.BOLD,18));
        //设置滚动面板的大小
        jScrollPane = new JScrollPane(jTextArea) {
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(300,400);
            }
        };
        left_screen.add(jScrollPane);
        jLabel.setIcon(new ImageIcon("images\\Dog2.png"));
        jLabel.setBounds(50, 170, 200, 10);
        left_screen.add(jLabel);
        win.add(left_screen);
//右侧组件
        enter.setIcon(new ImageIcon("images\\enter.png"));
        last.setIcon(new ImageIcon("images\\last.png"));
        //给上一关按钮注册监听器
        last.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    JOptionPane.showMessageDialog(null, "即将进入第一关", "消息提示框", JOptionPane.INFORMATION_MESSAGE);
                    new Question_1();
                    win.dispose();
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
            }
        });
        //给下一关按钮注册监听器
        next.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    JOptionPane.showMessageDialog(null, "即将进入第三关", "消息提示框", JOptionPane.INFORMATION_MESSAGE);
                    new Question_3();
                    win.dispose();
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
            }
        });
        //给评测按钮注册监听器
        enter.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String text1 = answer1.getText();
                String text2 = answer2.getText();
                String text3 = answer3.getText();
                String text4 = answer4.getText();
                if (text1.equals(input1) && text2.equals(input2) && text3.equals(input3) && text4.equals(input4)) {
                    JOptionPane.showMessageDialog(null, "测试通过,将自动进入下一关", "通关提示框", JOptionPane.INFORMATION_MESSAGE);
                    try {
                        new Question_3();
                        win.dispose();
                    } catch (IOException ioException) {
                        ioException.printStackTrace();
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "评测失败", "失败提示框", JOptionPane.ERROR_MESSAGE);
                }
            }
        });

        //进行组件的排版
        enter.setBounds(600, 535, 80, 35);
        last.setBounds(500,535,70,35);
        next.setBounds(710,535,70,35);
        label1.setBounds(500, 360, 50, 25);
        answer1.setBounds(550, 360, 250, 25);
        label2.setBounds(500, 385, 50, 25);
        answer2.setBounds(550, 385, 250, 25);
        label3.setBounds(500, 410, 50, 25);
        answer3.setBounds(550, 410, 250, 25);
        label4.setBounds(500, 435, 50, 25);
        answer4.setBounds(550, 435, 250, 25);
        backGround.setBounds(300, 0, 750, 355);
        //添加组件到窗口中去
        backGroundtotal.add(last);
        backGroundtotal.add(next);
        backGroundtotal.add(backGround);
        backGroundtotal.add(enter);
        backGroundtotal.add(label1);
        backGroundtotal.add(label3);
        backGroundtotal.add(label4);
        backGroundtotal.add(answer1);
        backGroundtotal.add(answer2);
        backGroundtotal.add(answer3);
        backGroundtotal.add(answer4);
        backGroundtotal.add(label2);
        win.add(backGroundtotal);
        //设置窗口的各属性
        win.setIconImage(ImageIO.read(new File("images\\logo.jpeg")));
        win.setSize(WIDTH, HEIGHT);
        win.setBounds((Toolkit.getDefaultToolkit().getScreenSize().width - WIDTH) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - HEIGHT) / 2, WIDTH, HEIGHT);
        win.setLayout(null);
        win.setVisible(true);
        win.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    //主测试函数
    public static void main(String[] args) throws IOException {
        new Question_2();
    }
}

关卡3

package WIndows;
import Component.BackGround;
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;
public class Question_3 {
    private int WIDTH = 1024;//定义窗口的宽度
    private int HEIGHT = 612;//定义窗口的高度
    JFrame win = new JFrame("Java小实训");//初始化一个窗口
    BackGround backGroundtotal =  new BackGround(ImageIO.read(new File("images\\welcome.jpg")));;//定义一个背景面板对象
    //定义右侧组件
    BackGround problem_pic = new BackGround(ImageIO.read(new File("images\\guanka3.1.png")));
    JTextField answer1 = new JTextField();
    JTextField answer2 = new JTextField();
    JLabel label1 = new JLabel("语句1:");
    JLabel label2 = new JLabel("语句2:");
    JButton enter = new JButton();//评测按钮
    JButton last = new JButton();//上一关按钮
    String input1 = "Person p1 = new Person();";//答案1
    String input2 = "Person p2 = new Person(name,sex);";//答案2
    //定义左侧组件
    JPanel left_screen = new JPanel();//承载左侧组件的面板
    JLabel title = new JLabel("第三关:类的构造方法");
    JTextArea jTextArea = new JTextArea();
    JTextArea jTextArea1 = new JTextArea();
    JLabel jLabel = new JLabel();
    JScrollPane jScrollPane;
    public Question_3() throws IOException {
        //设置最底层面板的属性
        backGroundtotal.setLayout(null);
        backGroundtotal.setBounds(0,0,WIDTH,HEIGHT);
        left_screen.setBounds(0,0,300,612);
        //左侧组件
        title.setBounds(0, 0, 250, 50);
        title.setFont(new Font("楷体", Font.BOLD, 25));
        title.setForeground(Color.BLACK);
        left_screen.add(title);
        jTextArea.setLineWrap(true);
        jTextArea.setEditable(false);
        jTextArea.setText("(1)任务概述:"+"\n"+"学习Java中类的构造方法的概念,并学会定义和使用构造方法;" + "\n" +"-----------------------------"+"\n"+
                "(2)相关知识:"+"\n"+"为了完成本关任务,你需要掌握:1.什么是构造方法,2.如何定义和调用构造方法。" + "\n" +
                "1.什么是构造方法:"+"\n"+"构造方法:对象被创建的时候会调用的方法,对象在被创建的时候,也就是被new的时候,会自动调用构造方法。"+"\n"+"怎么定义和使用构造方法: "+"\n"+
                "举个例子:"+"\n"+"有一个Student类,则可定义构造方法public Student() {}。"+"\n"+
                "总结一下:"+"\n"+"  *构造方法可以有参数,也可以无参数。"+"\n"+"  *构造方法无返回值,也不需要声明void关键字。"+"\n"+
                "  *构造方法名必须和类名相同。"+"\n"+"  *构造方法可以重载。"+"\n"+
                "-----------------------------"+"\n"+
                "(3)编程要求:"+"\n"+"我已经为你创建了一个Person类并创建了两个构造方法,如下图所示,你只需要补全右侧图片中的语句1-语句2,共两条语句。"+"\n"+
                "-----------------------------"+"\n"+
                "(4)测试说明:"+"\n"+"平台会对你的代码进行运行测试,如果实际输出与预期相同,则算通关."+"\n"+
                "注意:赋值运算符两侧需加空格,例如name = libai是正确的,而name=libai是错误的。"+"\n"+
                "\n"+"开始你的任务吧,祝你成功!"+"\n"+"-----------------------------"+"\n"+"(5)参考答案:"+"\n"+
                "语句1:Person p1 = new Person();"+"\n"+"语句2:Person p2 = new Person(name,sex);");
        jTextArea.setBounds(0, 50, 300, 100);
        jTextArea.setFont(new Font("宋体",Font.BOLD,18));
        //设置滚动面板的大小
        jScrollPane = new JScrollPane(jTextArea) {
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(300,350);
            }
        };
        left_screen.add(jScrollPane);
        jLabel.setIcon(new ImageIcon("images\\person3.png"));
        jLabel.setBounds(50, 120, 200, 10);
        left_screen.add(jLabel);
        win.add(left_screen);
//右侧组件
        enter.setIcon(new ImageIcon("images\\enter.png"));
        last.setIcon(new ImageIcon("images\\last.png"));
        //给上一关按钮注册监听器
        last.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    JOptionPane.showMessageDialog(null, "即将进入第二关", "消息提示框", JOptionPane.INFORMATION_MESSAGE);
                    new Question_2();
                    win.dispose();
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
            }
        });
        //给评测按钮注册监听器
        enter.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String text1 = answer1.getText();
                String text2 = answer2.getText();
                if (text1.equals(input1) && text2.equals(input2)) {
                    JOptionPane.showMessageDialog(null, "测试通过,恭喜你全部通关!", "通关提示框", JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(null, "评测失败", "失败提示框", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        //进行右侧组件的排版
        enter.setBounds(600, 535, 80, 35);
        last.setBounds(500,535,70,35);
        label1.setBounds(500, 360, 50, 25);
        answer1.setBounds(550, 360, 250, 25);
        label2.setBounds(500, 385, 50, 25);
        answer2.setBounds(550, 385, 250, 25);
        problem_pic.setBounds(300, 0, 750, 355);
        //添加组件到窗口中去
        backGroundtotal.add(problem_pic);
        backGroundtotal.add(enter);
        backGroundtotal.add(last);
        backGroundtotal.add(label1);
        backGroundtotal.add(answer1);
        backGroundtotal.add(answer2);
        backGroundtotal.add(label2);
        win.add(backGroundtotal);
        //设置窗口的各属性
        win.setIconImage(ImageIO.read(new File("images\\logo.jpeg")));
        win.setSize(WIDTH, HEIGHT);
        win.setBounds((Toolkit.getDefaultToolkit().getScreenSize().width - WIDTH) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - HEIGHT) / 2, WIDTH, HEIGHT);
        win.setLayout(null);
        win.setVisible(true);
        win.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    //主测试函数
    public static void main(String[] args) throws IOException {
        new Question_3();
    }

}

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李小枫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值