import java.awt.TextArea
import java.awt.TextField
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.util.Random
import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JTextArea
import javax.swing.JTextField
import javax.swing.border.EmptyBorder
public class LuckySelect extends JFrame {
private JPanel contentPane
private JTextField textFieldA
private JTextField textFieldB
private JTextField textFieldC
private 闷橘TextField textField
private JTextField textFieldResult
private JTextArea textArea
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LuckySelect frame = new LuckySelect()
frame.setVisible(true)
} catch (Exception e) {
e.printStackTrace()
}
}
})
}
/**
* Create the frame.
*/
public LuckySelect() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
setBounds(100, 100, 450, 251)
contentPane = new JPanel()
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5))
contentPane.setLayout(null)
setContentPane(contentPane)
JLabel lblA = new JLabel("A")
lblA.setBounds(10, 128, 54, 15)
contentPane.add(lblA)
JLabel lblB = new JLabel("B")
lblB.setBounds(124, 128, 缓纳54, 15)
contentPane.add(lblB)
JLabel lblC = new JLabel("C")
lblC.setBounds(254, 128, 54, 15)
contentPane.add(lblC)
textFieldA 蚂哪团= new JTextField()
textFieldA.setBounds(30, 125, 66, 21)
contentPane.add(textFieldA)
textFieldA.setColumns(10)
textFieldB = new JTextField()
textFieldB.setColumns(10)
textFieldB.setBounds(149, 125, 66, 21)
contentPane.add(textFieldB)
textFieldC = new JTextField()
textFieldC.setColumns(10)
textFieldC.setBounds(264, 125, 66, 21)
contentPane.add(textFieldC)
textField = new TextField()
textField.setBounds(98, 167, 157, 21)
contentPane.add(textField)
textField.setColumns(10)
textFieldResult = new JTextField()
textFieldResult.setBounds(280, 167, 66, 21)
contentPane.add(textFieldResult)
textFieldResult.setColumns(10)
textFieldA.setText("10")
textFieldB.setText("10")
textFieldC.setText("10")
JButton button = new JButton("\u62BD\u5956")
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
select()
}
})
button.setBounds(0, 166, 93, 23)
contentPane.add(button)
textArea = new JTextArea()
textArea.setBounds(30, 31, 306, 83)
contentPane.add(textArea)
}
protected void select() {
// TODO Auto-generated method stub
int aNum = Integer.decode(textFieldA.getText())
int bNum = Integer.decode(textFieldB.getText())
int cNum = Integer.decode(textFieldB.getText())
Random r = new Random()
int random = r.nextInt(aNum + bNum + cNum)
if(random <= aNum){
textFieldA.setText(Integer.toString(Integer.decode(textFieldA.getText()) - 1))
textArea.append(Integer.toString(random) + "抽中了A\n")
}else if(random <= aNum + bNum){
textFieldB.setText(Integer.toString(Integer.decode(textFieldB.getText()) - 1))
textArea.append(Integer.toString(random) + "抽中了B\n")
}else if(random <= aNum + bNum + cNum){
textFieldC.setText(Integer.toString(Integer.decode(textFieldC.getText()) - 1))
textArea.append(Integer.toString(random) + "抽中了C\n")
}
}
}
namespace ConsoleApplication1{
class Program
{
static void Main(string[] args)
{
Random r = new Random()
//随机产生0到99直接的一个数,可随机产出100个不同的数
int num = r.Next(0, 100)
if (num>=0&&num<50)//num大于等于0并小于50概率为50/100=50%
{
Console.WriteLine("此时掉落金币")
}
if (num>=50&&num<70)//以搜差盯庆燃下同理
{
Console.WriteLine("此时掉落钱包")
}
if (num>=70&&num<100)
{
Console.WriteLine("此时无东世和西掉落")
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)