图好玩也是为了检测自己最近所学内容,将以前的程序进行GUI实现
概率模拟部分
package XIangmu;import java.util.Random;public class He_Xin {public static String Gai_lv(){Random r = new Random();int x = r.nextInt(1000);if(x<=12){return "SSR";}else if(x>12 && x <=100 ){return "SR";}else{return "R";}}
}
GUI实现部分
package XIangmu;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;public class YYS1 extends JFrame {public YYS1(){this.setSize(500,300);this.setTitle("YYs抽卡模拟器 v2.0版本");this.setLocationRelativeTo(null);this.setIconImage(new ImageIcon("img.png").getImage());this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//关闭界面图标JPanel jp= new JPanel(new GridLayout(3,1));//主面板JPanel text_panel = new JPanel();//面板1 用来存放文本信息JLabel text_label = new JLabel("欢迎使用YYs抽卡模拟器,请选择单抽或者十连");text_label.setFont(new Font("楷书",Font.BOLD,20));text_panel.add(text_label);JPanel JButton_panel = new JPanel(); //面板2 用来设置按钮Dimension preferredSize = new Dimension(100,50);JPanel fin_panel = new JPanel();//面板3 用来展示结果//暂无 ,, 选择使用另一种方法,即:弹窗 来弹出抽卡结果JLabel text_label2 = new JLabel(" 本版本随作者能力提升而更新...");fin_panel.add(text_label2);JButton jb1 = new JButton("单抽");//单抽代码块jb1.setPreferredSize(preferredSize );jb1.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {
// System.out.println(new He_Xin().Gai_lv());String a = new He_Xin().Gai_lv();JOptionPane.showMessageDialog(null,a,"抽卡结果",JOptionPane.PLAIN_MESSAGE);
// System.out.println(a);}});JButton_panel.add(jb1);JButton jb2 = new JButton("十连");jb2.setPreferredSize(preferredSize );jb2.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {String []b = new String[10];for (int i = 0; i < 10; i++) {b[i] = new He_Xin().Gai_lv();}JOptionPane.showMessageDialog(null,b,"抽卡结果",JOptionPane.PLAIN_MESSAGE);}});JButton_panel.add(jb2);jp.add(text_panel);jp.add(JButton_panel);jp.add(fin_panel);this.add(jp);this.setVisible(true);}
}
启动器部分
package XIangmu;public class Start {public static void main(String[] args) {YYS1 y1 = new YYS1();}
}
程序运行结果
对本程序以后的提升想法
1.加入卡池系统,即抽卡的概率随着抽卡的次数提升而提升
2.加入抽卡次数的记录,每次执行的时候开始记录,记录完成后停止
3.加入图片系统,抽卡结果用图片进行反馈