JavaFX :: Slot Machine In Netbeans - Scene / Stage
Oct 21, 2014
I want to create a slot machine in NetBeans, with JavaFX library (without using JavaFX Scene Builder) but i have some problems to create UI.
I created algorithm already but without visuals.
Now my code is:
public class BEST extends Application {
private ImageView var; //init imageview of images
public static void main(String[] args) {
launch(args);
[Code] ....
createbottom(); and creategr(); i wrote already (and my program creates grid pane of random images with double dimension array, random and imageview) and program runs, but i don t know how to keep track of credits balance,in the same time to create new random gridpane of images and to get rid of every gridpane.
Here is creategr();
private GridPane creategr(){
final GridPane creategr = new GridPane();
int[][] newarray=new int[3][3];
int w=100;
for(int i=0; i<3; i++){
for(int j=0; j<3;j++)
I am looking for a way to find a resize animation for an application I'm developing. I found this answer but I figure there could be a better method out there,
Java - How do I create a Resize animation for JavaFX stage? - Stack Overflow
I am just looking to select something in a list, then press a button which would enable the animation and enlarge the stage. This will happen twice.
I noticed that all my stages can be resized to zero size regardless of their contained scene, which is very ugly. How do I keep them from doing that? Is there some sort of intelligent way to bind the stage's min size to the size of the scene so that no part of the scene is cut off?
I pulled off an all nighter in order to finish off this project for my computer studies class but i keep getting an error cannot find symbol at line 96?
import java.io.*; import java.util.*; import java.util.Random; public class SlotMachine { //Generates 3 random numbers for slot machine public static void main(ArrayList<Integer> slotMachine) {
I am designing a program that generates 3 random numbers from 1-5 and if 2 match, the user wins $1. If 3 match, the user wins respectively:
All 1s - $5 2s - $10 3s - $25 4s - $50 5s - $100
I first used a loop to run until the user runs out of money or wishes to stop. Then I made 2 methods. 1 to generate the random numbers and 1 to see if the user won any money. I am storing the random numbers in an array called slotnumber.
This is what I have so far but I am getting compiling errors at while (cont == 'y') {
import java.util.Scanner; import java.util.Random; public class SlotMachine {
I've spent ages trying to implement an exit button into this code. Its the start of a GUI for a slot machine, the actual machine code is in a separate class and I haven't linked them yet. My question is where/how would the exit button be added? I've tried and failed a lot of times....
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SlotMachineGUI { public static void main (String[] args) { //create new jframe JFrame frame = new JFrame ("Slot Machine");
I'm trying to fix this logic error in my slot machine game where no matter what slot combo comes up, it says you have won $10 and proceeds to add that amount to the balance and subtract the bet amount to the balance, even though it is not a winning combo! I've been trying to solve that and when doing so, I commented out Slot1.randNum1 == 0, Slot2.randNum2 ==0, and Slot3.randNum3 ==0 and anything relating to see if that was the problem, and it seemed like it was, because after that, the logic error described above was gone, but in doing so, the loss/win counter didn't increment, nor did the program pick up on the winning combos. However, I do not know why commenting out anything relating to randNum ==0 would cause that.
Here is the code for the processing (as you can see, some parts are commented in attempt to fix the logic error, but right now the code below is for the logic error that keeps on telling that the user has won):
public void askData () { title (); int betAmount; while (true) { try { c.setCursor (3, 1);
SlotMachine.java:21: error: illegal start of expression public static void getNums(int [] slots) ^ SlotMachine.java:21: error: illegal start of expression public static void getNums(int [] slots)
[code]....
i keep fixing small things and cannot get it to compile. Below is the original code,
import java.util.Scanner; import java.util.Random; public class SlotMachine { public static void main (String args[]) { int userMoney; Scanner input = new Scanner(System.in); System.out.print("How much money to start with?
Working with the winnings and how to spin again or exit.
import java.util.*; class Wksht5Q1{ public static void main(String[] args){ Scanner in = new Scanner(System.in);//For user input Random rand = new Random();//For number generator //Variables for user input
For this program, I have to run a slot machine. It runs until right before the do while loop and then I receive the error: Exception in thread "main" java.util.InputMismatch.Exception. Searching around, someone said it was a scanner error and adding a call keyboard.nextLine(); fixes the problem- however with that I receive the same error.
Code : import java.util.Scanner; import java.util.Random; import java.io.*; public class SlotMachineSimulation { public static void main(String[] args) throws IOException { int number;
I am developing JavaFX application. I have requirement like that javafx application should be always on top. I could not find an option to make it always on top.
I'm trying to set up a splash screen where a native splash screen is shown initially and then replaced with the stage from my preloader. This is fairly simple to do. I use the below code to get everything lined up properly.
private void alignStage(Stage stage) { SplashScreen splashScreen = SplashScreen.getSplashScreen(); if (splashScreen != null) { // Align the stage based on the current splash location Rectangle bounds = splashScreen.getBounds(); stage.setX(bounds.getX()); stage.setY(bounds.getY());
[Code] ....
The problem I'm having is that my Stage isn't actually shown by the time the commented event gets fired. The API for onShown says:
Called just after the Window is shown.
My guess is the window has transitioned to being shown, but there's a slight delay until it gets rendered on screen. If that's a decent assumption, is there a reliable way I can make sure my preloader stage is visible on screen before I hide the native splash?
The best option I can think of so far is to delay hiding the native splash until the preloader gets the BEFORE_START notification. This works (no flicker), but, since both splash screens are actually visible for a while, using a transparent splash doesn't work very well (which actually isn't too big of a deal).
I develop a desktop soft use javafx8, and remove default border (e.g. title and close/min/max button), now use mouse left key click the taskbar icon is nothing,i want click the taskbar icon,if stage it's show then hidden, if stage it's hidden then show it,the problem is I can't capture any mouse click event,so i can't show or hidden my stage.
I would like to ask you about possibility to restore javafx 8 app from iconified mode (setIconified(true)) to regular size via shorcut for example: Ctrl + Shift + Ins I use Windows 7 and jdk 1.8.0_40 beta.
Have have just started working with JavaFX and SceneBuilder having been a long time Swing developer.
My first foray into the world of JavaFX involves building a rather simple desktop application to parse text based log files with regular expressions.
Currently I am working on the main window for this application. I built a scene in SceneBuilder using a BorderPane for my root.
I placed a TitledPane which contains a TableView in the center section of the BorderPane and a VBox which contains several Buttons in the right section of the BorderPane. When I view the layout in SceneBuilder using the Preview menu item to show the preview in a Window, SceneBuilder shows the scene laid out exactly as it is in the work are and as I would like it laid out.
When I close SceneBuilder and go back to my IDE (Eclipse) and build and run the application the scene is displayed in a window differently than in SceneBuilder preview. When the application executes the scene is laid out as if there has been something placed in the top section of the BorderPane, the TitledPane containing the TableView is centered in the window and the VBox containing the buttons are not aligned with the top of the TitledPane containing the TableView because it is as if there is a "null control" in the top section of the BorderPane.
Why is there a difference in the way SceneBuilder displays the scene and the way the executed application displays the scene?
Also, I recently made some changes to the layout of the controls in SceneBuilder (e.g. changed some padding and location of some controls in their containers and again the scene looks perfect in SceneBuilder but when I execute the application now some components in the container where I made the changes are truncated when the scene is displayed when the application executes.
It is almost as if SceneBuilder is interpreting the FXML one way and the JavaFX API during run time is interpreting the FXML another way.
My problem is simple. Just set busy cursor on a scene. The scenarios is like this: I have simple application with a button on it. When I click the button, I will:
1. Set mouse cursor to BUSY 2. Do some work 3. Set mouse cursor back to DEFAULT.
I search the web and found some sample codes to set cursor. But they don't satisfy my need. So I wrote a simple application:
public class MainFormApp extends Application { @Override public void start(Stage stage) throws Exception { stage.initStyle(StageStyle.DECORATED); Pane root = new Pane(); root.setPrefSize(500, 300); Button btn = new Button("Click me");
[Code] ....
When I run application and click the button, cursor does not change to BUSY. I also tried to use Platform.runLater() but no luck.
I am new to javafx and my goal is to basically just test if my java code works with Mysql. What I'm planning to do is to display one data of the sakila database into a Label named greetingLabel. And I can't seem to find where i went wrong so i'll show you my whole code.
Here is the main code for my controller class from scene builder:
Here is the error displayed when pressing the button
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source) at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
I have following methods, which I call from the Event Dispatcher Thread:
public void setTitle(String title) { Platform.runLater(() -> stage.setTitle(title));} public String getTitle() { return stage.getTitle(); // <- Access from outside JFX App Thread ok?}
Is it thread-safe, when the getter-Method just return the value like the example show? Or must I create a Runnable, so stage.getTitle() is called inside the Java Application Thread? How I return the value then?
I think this might be the reason as this comboBox is not recognized at the import to the scene builder library. I can show up the import dialog of custom controls, but my custom ComboBox is not showing up. All other implementations are there correctly as they are loaded from my customControl.jar file
I use the ComboBoxListViewSkin for the functionality to scroll to an item in the combo as a user types a letter on the keyboard.
I do this by:
/** * This method scrolls the itemView of the items to the first item starting * with the given char or string * * @param pressedKey */ public void scrollToChar(String pressedKey) { String value = pressedKey.toUpperCase(); for (Object userEntry : getItems()) {
[Code] ....
I really need to show up my custom Combo in the scenebuilder, as otherwise the rest of my fxml is not editable in sceneBuilder 2.0 ....
The idea is pretty simple; extend StackPane, add an active property, bind the visible and managed properties of the pane to the active property, and, whenever the active property is changed to true, iterate sibling nodes de-activating any siblings that are also of the type Card.
However, this doesn't work with Scene Builder. While trying to debug, I created an ExtStackPane:
import javafx.collections.ListChangeListener; import javafx.scene.Node; import javafx.scene.layout.StackPane; public class ExtStackPane extends StackPane { { getChildren().addListener((ListChangeListener<Node>) c -> { System.out.println("ExtStackPane children change: " + c.toString()); }); } }
All this does is log list change events. However, I was very surprised by the output when working in Scene Builder. I added both controls to Scene Builder and did the following:
0) Added an ExtStackPane 1) Added a Card to the ExtStackPane 2) Added another Card to the ExtStackPane 3) Added a Label to the first Card 4) Added a Label to the second Card 5) Changed the text of the first Label to Hello 6) Changed the text of the second Label to World 7) Set the first Card to active 8) Set the second Card to active
I get the following output:
1) ExtStackPane children change: { [Card@5b9067b3] added at 0 }
2) ExtStackPane children change: { [Card@6b6328bd] added at 0 } ExtStackPane children change: { [Card@6aca8cc5] added at 1 }
[Code] ....
This is what things look like in Scene Builder:
Does Scene Builder recreate the entire hierarchy every time I make a small change? Here's an application that does the same as the manual steps I performed in Scene Builder:
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.stage.Stage; public class CardApplication extends Application {
[Code] ....
The output when running the above is:
1) ExtStackPane children change: { [Card@6dfaa767] added at 0 }
2) ExtStackPane children change: { [Card@6aa2c411] added at 1 }
[Code] ....
The behavior is obviously a lot different than when I'm working with the control in Scene Builder. What Scene Builder is doing to change the behavior of my Card control so much? Does my Card control break some rule(s) I'm not aware of?
Lets say I have a desire to convert and entered value to Centigrade or Fahrenheit and that I have two Radio Buttons to designate the type of conversion with the Answer posted to a TextField on Scene Two from a button click event on Scene One ok Now I would like to convert the value in the TextField on Scene Two to Kelvin and reflect the value on Scene Three in a TextField by clicking a button on Scene Two
lets say I have 4 FXML files sceneONE sceneTWO and scenMain and I created 4 controllers ControllerONE and MasterController
So far I can navigate to the different scens with just the MasterController code below...
BUT because I have two FXML files I can not capture the value in the first FXML file and pass it to the second scene
This project is my attempt to adapt the FXML style code from this web site
Switching to Different Screens in JavaFX and FXML | JavaFXTutorials
Which uses this code to switch scenes
//get reference to the button's stage stage=(Stage) btnS1.getScene().getWindow(); //load up OTHER FXML document root = FXMLLoader.load(getClass().getResource("ATTwo.fxml"));
But will not permit variable transfer due to scope of variables which reside in two different FXML files
public class MasterController implements Initializable{@FXML public Button btnS1; @FXML public Button btnS2; @FXML public Label lblS1; @FXML public Label lblS2; @FXML public TextField txfS1; @FXML public TextField txfS2; @FXML public AnchorPane root;
I'm trying to implement a scene with a ScrollPane in which the user can drag a node around and scale it dynamically. I have the dragging and scaling with the mouse wheel working as well as a reset zoom.
Here's my issue:
I'm having trouble with the calculations to fit the node to the width of the parent. If I zoom in or out, the fit to width does not work. If I change the window size after running fitWidth() once, the fit to width does not work the second time.
Here is my code as an SSCCE and how it works...
1. (works) Mouse wheel will zoom in and out around the mouse pointer 2. (works) Left or right mouse press to drag the rectangle around 3. (works) Left double-click to reset the zoom 4. (doesn't work) Right double-click to fit the width
My calculations to re-position the rectangle to the upper left of the pane and fit it (i.e. scale it up or down) to the width of the parent are incorrect.
I'm using Scene Builder 2.0 and have added an ImageView to the parent AnchorPane. I've added my PNG files for the app icon and the various buttons. I select the ImageView in Scene Builder and then crawl the filesystem to the project package folder and select the PNG for the Image. The assigned image is displayed in the Imageview in Scene Builder in both design mode and Preview mode.
While everything else shows up properly when the app is executed, the image assigned to the ImageView does not display.
I have developed a code to connecting remote windows M/C from local M/C by using SSH2 (ganymed-ssh2-build209.jar) API. when I run the code its giving below error. Is there any other way to connect remote windows system using java code.
Exception.
java.io.IOException: There was a problem while talking to <host name>:22 at ch.ethz.ssh2.Connection.connect(Connection.java:642) at ch.ethz.ssh2.Connection.connect(Connection.java:460) at Connect.RemoteServer.ConnectWindowsServer.runCommand(ConnectWindowsServer.java:55) at Connect.RemoteServer.ConnectWindowsServer.main(ConnectWindowsServer.java:27) Caused by: java.net.ConnectException: Connection refused: connect