Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mport java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.SwingConstants;
- import java.awt.Font;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.util.Random;
- import java.awt.event.ActionEvent;
- public class HiLoLottery {
- private JFrame frame;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- HiLoLottery window = new HiLoLottery();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public HiLoLottery() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setBounds(100, 100, 450, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- Random rand = new Random();
- int[] price = { 1500, 2000, 3000, 5000, 7000, 13000, 20000, 35000, 50000, 200000 };
- JLabel numberLbl = new JLabel("");
- numberLbl.setFont(new Font("Tahoma", Font.PLAIN, 25));
- numberLbl.setHorizontalAlignment(SwingConstants.CENTER);
- numberLbl.setBounds(10, 11, 140, 140);
- frame.getContentPane().add(numberLbl);
- JLabel textLbl = new JLabel("Number:");
- textLbl.setFont(new Font("Tahoma", Font.PLAIN, 16));
- textLbl.setHorizontalAlignment(SwingConstants.CENTER);
- textLbl.setBounds(10, 158, 110, 30);
- frame.getContentPane().add(textLbl);
- JLabel sumLbl = new JLabel("<html>Your current <br> sum is: 0<html>");
- sumLbl.setHorizontalAlignment(SwingConstants.CENTER);
- sumLbl.setFont(new Font("Tahoma", Font.PLAIN, 16));
- sumLbl.setBounds(291, 199, 110, 50);
- frame.getContentPane().add(sumLbl);
- JLabel countLbl = new JLabel("");
- countLbl.setHorizontalAlignment(SwingConstants.LEFT);
- countLbl.setFont(new Font("Tahoma", Font.PLAIN, 16));
- countLbl.setBounds(101, 160, 49, 26);
- frame.getContentPane().add(countLbl);
- JButton startBtn = new JButton("Start");
- startBtn.setFont(new Font("Tahoma", Font.PLAIN, 14));
- startBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int num = rand.nextInt(51);
- numberLbl.setText("" + num);
- countLbl.setText("" + 0);
- sumLbl.setText("<html>Your current <br> sum is: " + price[0]);
- }
- });
- startBtn.setBounds(20, 199, 110, 50);
- frame.getContentPane().add(startBtn);
- JButton upBtn = new JButton("UP");
- upBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int num = rand.nextInt(51);
- int prevNum = Integer.parseInt(numberLbl.getText());
- numberLbl.setText("" + num);
- if (num > prevNum) {
- int count = Integer.parseInt(countLbl.getText());
- count++;
- if (count == 9) {
- sumLbl.setText("<htnl> Congratulations! <br> You Won 200 000 <html>");
- } else {
- sumLbl.setText("<html>Your current <br> sum is: <html>" + price[count]);
- countLbl.setText("" + count);
- }
- } else {
- sumLbl.setText("You Lost");
- }
- }
- });
- upBtn.setFont(new Font("Tahoma", Font.PLAIN, 14));
- upBtn.setBounds(291, 11, 84, 65);
- frame.getContentPane().add(upBtn);
- JButton downBtn = new JButton("DOWN");
- downBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int num = rand.nextInt(51);
- int prevNum = Integer.parseInt(numberLbl.getText());
- numberLbl.setText("" + num);
- if (num < prevNum) {
- int count = Integer.parseInt(countLbl.getText());
- count++;
- if (count == 9) {
- sumLbl.setText("<html> Congratulations! <br> You Won 200 000 <html>");
- } else {
- sumLbl.setText("<html>Your current <br> sum is: <html>" + price[count]);
- countLbl.setText("" + count);
- }
- } else {
- sumLbl.setText("You Lost");
- }
- }
- });
- downBtn.setFont(new Font("Tahoma", Font.PLAIN, 14));
- downBtn.setBounds(291, 87, 84, 65);
- frame.getContentPane().add(downBtn);
- JButton moneyBtn = new JButton("Take Money");
- moneyBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int count = Integer.parseInt(countLbl.getText());
- sumLbl.setText("<html> Congratulations! <br> You Won <html>" + price[count]);
- }
- });
- moneyBtn.setFont(new Font("Tahoma", Font.PLAIN, 14));
- moneyBtn.setBounds(144, 199, 110, 50);
- frame.getContentPane().add(moneyBtn);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement