java答题软件_答题小软件

packagetouzi;importjava.awt.EventQueue;importjava.awt.Image;importjavax.swing.JFrame;importjavax.swing.JPanel;importjava.awt.BorderLayout;importjavax.swing.JButton;importjava.awt.event.ActionListener;importjava.util.Scanner;importjava.awt.event.ActionEvent;importjavax.swing.JTextField;importjavax.swing.JEditorPane;importjava.awt.Canvas;importjavax.swing.JLabel;importjavax.swing.ImageIcon;public classDiceGUI {privateJFrame frame;public static voidmain(String[] args) {

EventQueue.invokeLater(newRunnable() {public voidrun() {try{

DiceGUI window= newDiceGUI();

window.frame.setVisible(true);

}catch(Exception e) {

e.printStackTrace();

}

}

});

}publicDiceGUI() {

initialize();

}private voidinitialize() {

Dice fdice=newDice();

Dice tdice=newDice();

frame=newJFrame();

frame.setTitle("提问软件");

frame.setResizable(false);

frame.setBounds(100, 100, 450, 300);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

ImageIcon[] image= new ImageIcon[7];

image[0] = new ImageIcon("D:\\touzi\\0.gif");

image[1] = new ImageIcon("D:\\touzi\\1.png");

image[2] = new ImageIcon("D:\\touzi\\2.png");

image[3] = new ImageIcon("D:\\touzi\\3.png");

image[4] = new ImageIcon("D:\\touzi\\4.png");

image[5] = new ImageIcon("D:\\touzi\\5.png");

image[6] = new ImageIcon("D:\\touzi\\6.png");

JPanel panel= newJPanel();

frame.getContentPane().add(panel, BorderLayout.CENTER);

panel.setLayout(null);

JLabel[] JDice= new JLabel[2];

JDice[0] = new JLabel(" ");

JDice[0].setIcon(new ImageIcon("D:\\touzi\\0.gif"));

JDice[0].setBounds(68, 104, 117, 111);

panel.add(JDice[0]);

JDice[1] = new JLabel(" ");

JDice[1].setIcon(new ImageIcon("D:\\touzi\\0.gif"));

JDice[1].setBounds(257, 104, 117, 111);

panel.add(JDice[1]);

JLabel pLabel= new JLabel(" ");

pLabel.setVisible(false);

pLabel.setBounds(189, 69, 255, 128);

panel.add(pLabel);

JButton usebutton= new JButton("抽取学生");

usebutton.addActionListener(newActionListener() {public voidactionPerformed(ActionEvent arg0) {

Dice[] Dice= new Dice[2];int sum = 0;for(int i= 0;i < 2;i++){

Dice[i]= newDice();

Dice[i].Roll();

System.out.println(Dice[i].getFaceValue());

sum= sum +Dice[i].getFaceValue();switch(Dice[i].getFaceValue()){case(1):JDice[i].setIcon(image[1]);break;case(2):JDice[i].setIcon(image[2]);break;case(3):JDice[i].setIcon(image[3]);break;case(4):JDice[i].setIcon(image[4]);break;case(5):JDice[i].setIcon(image[5]);break;case(6):JDice[i].setIcon(image[6]);break;

}

}

System.out.println(sum+ " 号同学上台回答问题");

}

});

usebutton.setBounds(18, 225, 93, 23);

panel.add(usebutton);

JButton retbutton= new JButton("重置");

retbutton.addActionListener(newActionListener() {public voidactionPerformed(ActionEvent e) {

JDice[0].setIcon(image[0]);

JDice[1].setIcon(image[0]);

JDice[1].setVisible(true);

pLabel.setVisible(false);

}

});

retbutton.setBounds(121, 225, 93, 23);

panel.add(retbutton);

JLabel lblNewLabel_1= new JLabel(" ");

ImageIcon title= new ImageIcon("D:\\touzi\\1.jpg");

title.setImage(title.getImage().getScaledInstance(300,80,Image.SCALE_DEFAULT));

lblNewLabel_1.setIcon(title);

lblNewLabel_1.setBounds(67, 10, 307, 75);

panel.add(lblNewLabel_1);

JButton awbutton= new JButton("抽奖品");

awbutton.addActionListener(newActionListener() {public voidactionPerformed(ActionEvent e) {

JDice[1].setVisible(false);

pLabel.setVisible(true);

fdice.Roll();switch(fdice.getFaceValue()){case(1):JDice[0].setIcon(image[1]);pLabel.setText("你获得了风扇");break;case(2):JDice[0].setIcon(image[2]);pLabel.setText("你获得了作业");break;case(3):JDice[0].setIcon(image[3]);pLabel.setText("你获得了零食");break;case(4):JDice[0].setIcon(image[4]);pLabel.setText("你获得了桌子");break;case(5):JDice[0].setIcon(image[5]);pLabel.setText("你获得了椅子");break;case(6):JDice[0].setIcon(image[6]);pLabel.setText("你获得了电脑");break;

}

}

});

awbutton.setBounds(224, 225, 93, 23);

panel.add(awbutton);

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值