Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 8th, 2010, 12:02 PM
thor33443 thor33443 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2010
Posts: 3 thor33443 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 20 sec
Reputation Power: 0
Locker Combination with JSpinners

Hello Everyone I'm trying to do a program for my class, but im stuck on one part. I cannot figure out what code I need to add on line 165, which is the private void openJButtonActionPerformed(ActionEvent event line. I have to get the values from the 5 Jspinners. If the number on the JSpinners is 1,2,3,4, and a message dialog box should say the locker is open, but if it is not 1,2,3,4,5 a message box should say locker is not open.

this is the code I have

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;


public class Program4 extends JFrame {



private JLabel nameJLabel;

private JButton resetJButton;

private JButton openJButton;

private JSpinner comb1JSpinner;
private JSpinner comb2JSpinner;
private JSpinner comb3JSpinner;
private JSpinner comb4JSpinner;
private JSpinner comb5JSpinner;





public Program4( )
{
createUserInterface( );
}

private void createUserInterface( )
{
Container contentPane = getContentPane( );
contentPane.setLayout(null);

//
//code to create labels, textfields and buttons goes here
//
nameJLabel = new JLabel();
nameJLabel.setBounds(30,30,300,21);
nameJLabel.setText("Combination Lock");
contentPane.add(nameJLabel);



comb1JSpinner = new JSpinner(
new SpinnerNumberModel(5,1,9,1));
comb1JSpinner.setBounds(10,68,30,30);
contentPane.add(comb1JSpinner);



comb2JSpinner = new JSpinner(
new SpinnerNumberModel(5,1,9,1));
comb2JSpinner.setBounds(50,68,30,30);
contentPane.add(comb2JSpinner);



comb3JSpinner = new JSpinner(
new SpinnerNumberModel(5,1,9,1));
comb3JSpinner.setBounds(90,68,30,30);
contentPane.add(comb3JSpinner);



comb4JSpinner = new JSpinner(
new SpinnerNumberModel(5,1,9,1));
comb4JSpinner.setBounds(130,68,30,30);
contentPane.add(comb4JSpinner);



comb5JSpinner = new JSpinner(
new SpinnerNumberModel(5,1,9,1));
comb5JSpinner.setBounds(170,68,30,30);
contentPane.add(comb5JSpinner);


openJButton = new JButton ();
openJButton.setText( "Open" );
openJButton.setBounds( 13, 120, 70, 25 );
openJButton.setFont(
new Font( "Arial", Font.PLAIN, 14 ) );
contentPane.add( openJButton );
openJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// called when subtractJButton is pressed
public void actionPerformed( ActionEvent event )
{
openJButtonActionPerformed(event);
}

} // end anonymous inner class

); // end call to addActionListener



resetJButton = new JButton ();
resetJButton.setText( "Reset" );
resetJButton.setBounds( 120, 120, 80, 25 );
resetJButton.setFont(
new Font( "Arial", Font.PLAIN, 14 ) );
contentPane.add( resetJButton );
resetJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// called when divideJButton is pressed
public void actionPerformed( ActionEvent event )
{
resetJButtonActionPerformed(event);
}

} // end anonymous inner class

); // end call to addActionListener

































setTitle("Locker");
setSize(225, 200);
setVisible(true);
}

//
// Put code for displayJButtonActionPerformed
//
private void openJButtonActionPerformed(ActionEvent event)
{

Integer comb1 = (Integer)comb1JSpinner.getValue();
Integer comb2 = (Integer)comb2JSpinner.getValue();
Integer comb3 = (Integer)comb3JSpinner.getValue();
Integer comb4 = (Integer)comb4JSpinner.getValue();
Integer comb5 = (Integer)comb5JSpinner.getValue();














}

private void resetJButtonActionPerformed(ActionEvent event)
{


comb1JSpinner.setValue(new Integer(5));
comb2JSpinner.setValue(new Integer(5));
comb3JSpinner.setValue(new Integer(5));
comb4JSpinner.setValue(new Integer(5));
comb5JSpinner.setValue(new Integer(5));


}

public static void main(String[] args)
{
Program4 application = new Program4();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}

Reply With Quote
  #2  
Old March 1st, 2013, 08:59 AM
CompSciStudent7 CompSciStudent7 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 1 CompSciStudent7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 47 sec
Reputation Power: 0
Lightbulb your missing a "checker"

**Read the bottom message**
Quote:
Originally Posted by thor33443
Hello Everyone I'm trying to do a program for my class, but im stuck on one part. I cannot figure out what code I need to add on line 165, which is the private void openJButtonActionPerformed(ActionEvent event line. I have to get the values from the 5 Jspinners. If the number on the JSpinners is 1,2,3,4, and a message dialog box should say the locker is open, but if it is not 1,2,3,4,5 a message box should say locker is not open.

this is the code I have

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;


public class Program4 extends JFrame {



private JLabel nameJLabel;

private JButton resetJButton;

private JButton openJButton;

private JSpinner comb1JSpinner;
private JSpinner comb2JSpinner;
private JSpinner comb3JSpinner;
private JSpinner comb4JSpinner;
private JSpinner comb5JSpinner;





public Program4( )
{
createUserInterface( );
}

private void createUserInterface( )
{
Container contentPane = getContentPane( );
contentPane.setLayout(null);

//
//code to create labels, textfields and buttons goes here
//
nameJLabel = new JLabel();
nameJLabel.setBounds(30,30,300,21);
nameJLabel.setText("Combination Lock");
contentPane.add(nameJLabel);



comb1JSpinner = new JSpinner(
new SpinnerNumberModel(5,1,9,1));
comb1JSpinner.setBounds(10,68,30,30);
contentPane.add(comb1JSpinner);



comb2JSpinner = new JSpinner(
new SpinnerNumberModel(5,1,9,1));
comb2JSpinner.setBounds(50,68,30,30);
contentPane.add(comb2JSpinner);



comb3JSpinner = new JSpinner(
new SpinnerNumberModel(5,1,9,1));
comb3JSpinner.setBounds(90,68,30,30);
contentPane.add(comb3JSpinner);



comb4JSpinner = new JSpinner(
new SpinnerNumberModel(5,1,9,1));
comb4JSpinner.setBounds(130,68,30,30);
contentPane.add(comb4JSpinner);



comb5JSpinner = new JSpinner(
new SpinnerNumberModel(5,1,9,1));
comb5JSpinner.setBounds(170,68,30,30);
contentPane.add(comb5JSpinner);


openJButton = new JButton ();
openJButton.setText( "Open" );
openJButton.setBounds( 13, 120, 70, 25 );
openJButton.setFont(
new Font( "Arial", Font.PLAIN, 14 ) );
contentPane.add( openJButton );
openJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// called when subtractJButton is pressed
public void actionPerformed( ActionEvent event )
{
openJButtonActionPerformed(event);
}

} // end anonymous inner class

); // end call to addActionListener



resetJButton = new JButton ();
resetJButton.setText( "Reset" );
resetJButton.setBounds( 120, 120, 80, 25 );
resetJButton.setFont(
new Font( "Arial", Font.PLAIN, 14 ) );
contentPane.add( resetJButton );
resetJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// called when divideJButton is pressed
public void actionPerformed( ActionEvent event )
{
resetJButtonActionPerformed(event);
}

} // end anonymous inner class

); // end call to addActionListener

































setTitle("Locker");
setSize(225, 200);
setVisible(true);
}

//
// Put code for displayJButtonActionPerformed
//
private void openJButtonActionPerformed(ActionEvent event)
{

Integer comb1 = (Integer)comb1JSpinner.getValue();
Integer comb2 = (Integer)comb2JSpinner.getValue();
Integer comb3 = (Integer)comb3JSpinner.getValue();
Integer comb4 = (Integer)comb4JSpinner.getValue();
Integer comb5 = (Integer)comb5JSpinner.getValue();

if((combo1==1)&&(combo2==1)&&(combo3==1)&&(combo4==1)&&(combo5==1))
System.out.println("Got It");

}

private void resetJButtonActionPerformed(ActionEvent event)
{


comb1JSpinner.setValue(new Integer(5));
comb2JSpinner.setValue(new Integer(5));
comb3JSpinner.setValue(new Integer(5));
comb4JSpinner.setValue(new Integer(5));
comb5JSpinner.setValue(new Integer(5));


}

public static void main(String[] args)
{
Program4 application = new Program4();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}



After looking at your code i found out that you are simply missing an "if-statement". I have tried it and it works. here it is:
if((combo1==1)&&(combo2==1)&&(combo3==1)&&(combo4==1)&&(combo5==1))
System.out.println("You Got the Combo!");
I put it in your code so all you have to do is copy and paste!
Just make sure you change the combo so its not 1-1-1-1-1

Hope this helped!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Locker Combination with JSpinners

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap