From 4c0a3372b7d7f99b3d0547e92bcd9cbfdd5597d0 Mon Sep 17 00:00:00 2001 From: IamEld3st Date: Thu, 24 Sep 2015 21:19:38 +0200 Subject: [PATCH] First Real Commit Commit with all working stuff --- .classpath | 6 + .project | 17 +++ .settings/org.eclipse.jdt.core.prefs | 11 ++ src/com/develd/ranum/Main.java | 183 +++++++++++++++++++++++++++ 4 files changed, 217 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 src/com/develd/ranum/Main.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fceb480 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..f9d928f --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Ranum + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/src/com/develd/ranum/Main.java b/src/com/develd/ranum/Main.java new file mode 100644 index 0000000..db2f5f0 --- /dev/null +++ b/src/com/develd/ranum/Main.java @@ -0,0 +1,183 @@ +package com.develd.ranum; + +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.SwingConstants; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.awt.Color; +import javax.swing.JTextField; + +public class Main { + + public boolean Restarted = true; + public int minval; + public int maxval; + public int arrayCountHolder = 0; + public Random rand = new Random(); + public List genNumList = new ArrayList(); + public boolean genBool = false; + public String resultRand; + + private JFrame frmRanum; + private JTextField textFieldStart; + private JTextField textFieldEnd; + private JTextField textFieldResult; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Main window = new Main(); + window.frmRanum.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the application. + */ + public Main() { + initialize(); + } + + public int randomInteger(int min, int max) { + int randomNum = min + (int)(Math.random() * ((max - min) + 1)); + return randomNum; + } + + /** + * Initialize the contents of the frame. + */ + private void initialize() { + frmRanum = new JFrame(); + frmRanum.getContentPane().setFont(new Font("Arial", Font.PLAIN, 11)); + frmRanum.getContentPane().setBackground(Color.WHITE); + frmRanum.setBackground(Color.WHITE); + frmRanum.setResizable(false); + frmRanum.setTitle("Ranum"); + frmRanum.setBounds(100, 100, 225, 176); + frmRanum.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frmRanum.getContentPane().setLayout(null); + + JLabel lblTitle = new JLabel("Random Number Generator"); + lblTitle.setBackground(Color.WHITE); + lblTitle.setFont(new Font("Arial", Font.BOLD, 14)); + lblTitle.setVerticalAlignment(SwingConstants.TOP); + lblTitle.setHorizontalAlignment(SwingConstants.CENTER); + lblTitle.setBounds(10, 11, 202, 17); + frmRanum.getContentPane().add(lblTitle); + + JLabel lblStart = new JLabel("Start Number:"); + lblStart.setFont(new Font("Arial", Font.PLAIN, 11)); + lblStart.setBounds(20, 39, 78, 14); + frmRanum.getContentPane().add(lblStart); + + JLabel lblEnd = new JLabel("End Number:"); + lblEnd.setFont(new Font("Arial", Font.PLAIN, 11)); + lblEnd.setBounds(20, 64, 66, 14); + frmRanum.getContentPane().add(lblEnd); + + textFieldStart = new JTextField(); + textFieldStart.setBounds(98, 36, 100, 20); + frmRanum.getContentPane().add(textFieldStart); + textFieldStart.setColumns(10); + + textFieldEnd = new JTextField(); + textFieldEnd.setBounds(98, 61, 100, 20); + frmRanum.getContentPane().add(textFieldEnd); + textFieldEnd.setColumns(10); + + textFieldResult = new JTextField(); + textFieldResult.setBounds(98, 92, 100, 20); + frmRanum.getContentPane().add(textFieldResult); + textFieldResult.setColumns(10); + textFieldResult.setEditable(false); + + JButton btnGenerate = new JButton("Generate"); + btnGenerate.setBackground(Color.WHITE); + btnGenerate.setFont(new Font("Arial", Font.PLAIN, 11)); + btnGenerate.setBounds(10, 91, 80, 23); + frmRanum.getContentPane().add(btnGenerate); + + JLabel lblCredits = new JLabel("by Andrzej Szczepaniak"); + lblCredits.setFont(new Font("Arial", Font.PLAIN, 10)); + lblCredits.setBounds(96, 123, 133, 14); + frmRanum.getContentPane().add(lblCredits); + + JButton btnRestart = new JButton("Restart"); + btnRestart.setBackground(Color.WHITE); + btnRestart.setFont(new Font("Arial", Font.PLAIN, 11)); + btnRestart.setBounds(10, 118, 80, 23); + frmRanum.getContentPane().add(btnRestart); + + //Buttons Events + + btnGenerate.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + if( Restarted ) { + int eminval = Integer.parseInt(textFieldStart.getText()); + int emaxval = Integer.parseInt(textFieldEnd.getText()); + if(eminval > emaxval) { + minval = emaxval; + maxval = eminval; + textFieldStart.setText(Integer.toString(minval)); + textFieldEnd.setText(Integer.toString(maxval)); + }else{ + minval = eminval; + maxval = emaxval; + } + textFieldStart.setEditable(false); + System.out.println("Minimal Value: "+minval+" | Locked Min Value!"); + textFieldEnd.setEditable(false); + System.out.println("Maximal Value: "+maxval+" | Locked Max Value!"); + Restarted = false; + arrayCountHolder += 1; + resultRand = Integer.toString(randomInteger(minval, maxval)); + System.out.println("Random Value: "+resultRand+" | Array Usage: "+arrayCountHolder); + arrayCountHolder -= 1; + } + arrayCountHolder += 1; + while(genNumList.contains(resultRand)) { + resultRand = Integer.toString(randomInteger(minval, maxval)); + System.out.println("Random Value: "+resultRand+" | Array Usage: "+arrayCountHolder); + } + genNumList.add(resultRand); + textFieldResult.setText(resultRand); + if(arrayCountHolder == maxval) { + System.out.println("All numbers in range Generated!"); + btnGenerate.setEnabled(false); + } + } + }); + + btnRestart.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + Restarted = true; + arrayCountHolder = 0; + btnGenerate.setEnabled(true); + textFieldStart.setText(null); + textFieldStart.setEditable(true); + textFieldEnd.setText(null); + textFieldEnd.setEditable(true); + textFieldResult.setText(null); + genNumList.clear(); + System.out.println("Restart... | All values returned to null!"); + } + }); + + } +}