Swing/AWT/SWT :: Slot Machine - GUI Exit Button
Mar 13, 2014
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");
[Code] .....
View Replies
ADVERTISEMENT
Nov 22, 2014
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
[Code] ....
View Replies
View Related
May 18, 2014
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) {
int count = 0;
while (count<3)
[code]....
View Replies
View Related
Nov 13, 2014
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
{
[Code]......
View Replies
View Related
Jan 2, 2015
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);
[code]....
View Replies
View Related
Nov 19, 2014
Here are the errors I am getting:
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?
[code]....
View Replies
View Related
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++)
[Code] ....
Button "SPIN" is created in createbottom();.
View Replies
View Related
Nov 16, 2014
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;
[Code] .....
View Replies
View Related
Apr 22, 2014
I have a Single Frame Application and I simply want to prompt the user with a dialog confirming they really want to close before they actually close the program, specifically when they click the X in the upper right. I THOUGHT it was like any other java application, with the slight added complexity of having to target the program-created-JFrame with: ".getApplication().getMainFrame()".
MyApp.getApplication().getMainFrame().setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
With that code, DO_NOTHING_ON_CLOSE is set on the JFrame, yet the program closes anyways. Which I don't understand.So I did some reading and found this: URL....That lead me to the configureWindow override, where I successfully tried this:
root.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// write your code here
System.out.println("Window Closing");
}
});
But as far as I can tell that will only let me react to the window closing, not to the command to close it, where I could then kill the command in the dialog if they so "no I'm not ready to quit yet", if that makes sense. So, how to give a prompt before closing?I am using netbeans IDE to create this app - not sure if that is relevant, since maybe it is an oddity with the IDE and not Single Frame Applications.
View Replies
View Related
Apr 11, 2014
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
[Code] ....
JAVA Code
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
public void setAuthenticationInfo(String hostname, String username,String password) {
this.host = hostname;
this.userid = username;
this.password = password;
this.recentCommand = "";
System.out.println("setting authentication info completed for host=" + host );
[Code] .....
View Replies
View Related
Feb 28, 2014
I have a requirement where I have to send a file from a local system to unix box(present on client side) using java code.I have developed a code that is successfully sending the file from local system to client side unix box (I am connecting to client side unix box using VPN) provided I run the code in my eclipse IDE present in local system. But when I am running the same code in the unix box it is throwing null pointer exception.Might be the unix system is not recognising the local system. Please find the code.
package abc;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Properties;
import com.jcraft.jsch.Channel;
[Code] ....
Error on unix box which I am getting is :-
Inside sftpConnection method
llllllll
fffffffffffff
Connection Successfull
Channel Connection Succesfull
aaaaa
Inside findFile method
Exception in thread "main" java.lang.NullPointerException
at abc.TranferFile.sftpConnection(TranferFile.java:58)
at abc.TranferFile.main(TranferFile.java:21)
View Replies
View Related
Nov 29, 2014
I am creating a mad libs type program. This section of code is for the user to be able to make their own mad lib template (that people will be able to fill out later). The normal blanks in a mad lib are for verb, noun, adjective, adverb, etc. I cam up with 13 or so of these buttons, but it would be nice that if the user wants to add a button that they think we missed, such as 'Person in the Room' or 'Silly Location'...that the user would be able to do this. I sort of pictured there being a button that says 'add button' or something like that. Is there a ways to do this with the way I've set things up?
public class MadLibs {
public static void main(String[] args) throws IOException {
////////////////////
//TEXT PANE WINDOW//
////////////////////
//Set up a JTextPane object : The JTextPane is a specialized form of the JEditorPane
//designed especially for the editing (and display) of styled text.
final JTextPane pane = new JTextPane();
[Code] ....
View Replies
View Related
Jan 30, 2015
what I needed to know to complete the lesson, but now it just tells me what the output should be and I have to research the information on my own. anyways, here is my code from the previous lesson:
import java.util.Random;
import java.util.Scanner;
public class tnArray {
public static void main(String[] args) {
int [] array;
[code]....
Now I have to change it so that instead of counting the number of times a number will appear in the array, I must output which slot in the array the number is in.
View Replies
View Related
Apr 8, 2014
I'd like open a second GUI when I press a button that's on the first GUI, like a link in a website.
What I want to do is:
1- Open GUI_1;
2- Press a button on GUI_1; this button close GUI_1 and open another GUI (GUI_2).
How can I do it?
View Replies
View Related
Jan 26, 2015
I have a program I wrote long ago. I change colors of buttons at times. Here is the code:
for(int Player=0; Player < 8; Player++){
//make them all background
dealerLabels[Player].setBackground(new java.awt.Color(212,208,200));
}
//Now make the new dealer green
dealerLabels[dl].setBackground(new java.awt.Color(51, 255, 0));
The color of the buttons has always changed under XP but when I run the program on Windows 8 only the edges of the buttons change.
View Replies
View Related
Sep 19, 2014
How to save in array or arraylist when i click the jbutton
View Replies
View Related
Jul 3, 2014
I am trying to add buttons in a loop to my but when i compile my program i can`t see my buttons. I can see other stuff that added to jpanel ...
static JButton blocks[][];
for (int i = 0; i < block.length; i++) {
for (int j = 0; j < block[i].length; j++) {
block[i][j] = new Block(i, j);
blocks[i][j] = new JButton(i+"");
blocks[i][j].setLayout(new GridLayout((i+1) * 10, (i+1) * 10, 10, 10));
pageAxisPanel.add(blocks[i][j]);
}
}
View Replies
View Related
Mar 5, 2014
For the following code.When I run it ,I am getting the image and Login written along with it , but not getting the preselected radio button
import javax.swing.*;
public class MyJFrameWithJRadioButton extends JFrame
{
JRadioButton rdButton;
public MyJFrameWithJRadioButton()
{
setTitle("This is a JFrame");
setBounds(0, 0, 200, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
rdButton =new JRadioButton("Login",new ImageIcon(ClassLoader.getSystemResource("Login.png")),true);
add(rdButton);
setVisible(true);
[code]....
View Replies
View Related
Feb 27, 2015
The class does get compiled but the submit button doesn't work?
/**
* Orchestration class for Account
*/
import java.awt.*; //Importing the java.awt.* class
import java.awt.event.*;//Importing the java.awt.event.* class
import javax.swing.*;//Importing the javax.swing. class
public class AccountDemo extends JFrame
{
/// initializes the variables in the container
[Code] ....
View Replies
View Related
Mar 6, 2014
so i'm supposed to create a jframe with only 1 button. each time you push the button it is supposed to go from red to green to blue to gray and back to red starting over. i can get is the background to change on the first click, then the button is useless for eternity. here is my code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Exercise2_59 extends JFrame implements ActionListener
{
JButton change;
[code].....
View Replies
View Related
Mar 19, 2014
how to make this restart button work. This is what I have so far. I have put the restart button code in red and bold...
package Game;
public class Buttons extends javax.swing.JPanel {
private GameWorld world;
private int restart;
[code]....
View Replies
View Related
Mar 7, 2014
Can I add actionListener to a button component without creating a reference to it? Look at my code below:
public void init() {
setBackground(Color.red);
//Create the layout
setLayout(new BorderLayout(20, 5));
//Add buttons
add("North", new Button("Red"));
add("South", new Button("Yellow"));
add("East", new Button("Cyan"));
add("West", new Button("Magenta"));
add("Center", new Button("White"));
}
Or should I just do the usual instance.addActionListener(this) like myButton.addActionListener(this)?
View Replies
View Related
Feb 18, 2014
I'm trying to can make right button event to show a popup of copy/paste in a jtable but I put these code and doesn't works:
public class UI implements ActionListener, DocumentListener, MouseListener{
private JFrame ventana;
private JTable table;
private JPanel panel;
private JScrollPane tableScrollPane;
[Code] .....
View Replies
View Related
Mar 22, 2014
I have been reading some java guides here [URL] .... and was trying to put a bit of what I have learnt into practice but am having some difficulty. Basically, using netbeans IDE I have created a new jFrameform so that I can place swing components in design mode. What I want to create isnt overly complicated but I just cant seem to get it. In design I have simply added a panel and a button. When I press the button I want to display an image I have located at:
/resources/images/numbers/1.png.
This is my code so far (most of it has been automatically generated from me adding things via design mode:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package test;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
[Code] ....
I assume I need something like below somewhere , do i need to create a draw method? if so how do I call it as it is expecting graphics2d as a parameter, what would I pass into it?
BufferedImage img = null;
try {
img = ImageIO.read(new File("/resources/images/numbers/1.png"));
} catch (IOException e) {
}
View Replies
View Related
Oct 10, 2014
I tried a few things and I was unsuccessful at removing the border around my image button. It seemed simple enough when reading on StackOverflow but I'm still getting errors : s
ImageIcon cardIcon_1_1 = new ImageIcon("../images/empty.png");
JLabel cardImg_1_1 = new JLabel(cardIcon_1_1);
cardImg_1_1.setBorder(BorderFactory.createEmptyBorder());
cardImg_1_1.setContentAreaFilled(false);
Errors:
Multiple markers at this line
- Syntax error on token ";", @ expected
- Syntax error on token ".", @ expected after this token
Multiple markers at this line
- Syntax error, insert "Identifier (" to complete
MethodHeaderName
- Syntax error, insert "SimpleName" to complete
QualifiedName
- Syntax error, insert ")" to complete MethodDeclaration
I'm using an applet it had to be in the initialize part of my program...
View Replies
View Related
Nov 12, 2014
make this button:
look more like this one:
I'm using GridLayout for my main JFrame.
View Replies
View Related