• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need SERIOUS HELP!!

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am making a java version of BlackJack for a project. I have a text version
running perfectly except I am trying to convert it to a GUI. I decided to use a JSlider object to use as a way to enter the "Bet". I made a JFrame that runs and works as intended. The problem arises when I try to load this frame from an Applet. The applet loads the frame as an applet window and the JFrame is incapable of dealing with that. I have included the code for the JFrame. Please advise on how I should load the frame from an Applet.

/--------------------BEGIN CODE--------------------------------------------
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class SliderExampleextends JFrame implements ChangeListener
{
privateJSliderscrollerB;

private JLabellabelB;
private JLabel textField;
private JPaneltopPanel;
private JButton okButton;
public static boolean condition = false;
private static int amountBet;
private SliderExample closer = this;


public SliderExample(int money)
{
setTitle( "Betting Booth" );

setSize( 330, 330 );
setBackground( Color.gray );

topPanel = new JPanel();
topPanel.setLayout( null );
topPanel.setDoubleBuffered( false );
getContentPane().add( topPanel );

textField = new JLabel ("$0");
textField.setBounds(20, 135 , 100, 20);
topPanel.add(textField);

scrollerB = new JSlider( SwingConstants.HORIZONTAL,
0, money, 0 );
scrollerB.setBounds( 20, 155, 290, 40 );
scrollerB.setMajorTickSpacing( money/4 );
scrollerB.setMinorTickSpacing( money/10 );
scrollerB.setPaintTicks( true );
scrollerB.setPaintLabels( true );
scrollerB.addChangeListener( this );
topPanel.add( scrollerB );


okButton = new JButton ("Bet");
okButton.setBounds (20, 200, 100, 20);
topPanel.add(okButton);
okButton.setVisible(true);
okButton.addActionListener (new ButtonListener());


}


// Watch for scroll bar adjustments
public void stateChanged( ChangeEvent event )
{
// The event came from our scrollers handle it.
int bet = scrollerB.getValue();


// Update the color chip
textField.setText("$" + bet);
}


public static void main( String args[] )
{
// Create an instance of the test application
//For Testing Purposes
SliderExample mainFrame= new SliderExample(2000);
mainFrame.setVisible( true );
}

public static int getAmount ()
{
return amountBet;
}

public static boolean condition ()
{
return condition;
}

private class ButtonListener implements ActionListener
{

public void actionPerformed (ActionEvent event)
{
amountBet = scrollerB.getValue();
okButton.setText("Bet Accepted");
condition = true;


}

public int getAmount ()
{
return amountBet;
}
}


}
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not clearly understand whether you want to load the SliderExample component into the applet or open it in its own separate top–level container (such as JFrame or JDialog). The second option seems like the easier of the two so I'll suggest a way to load the SliderExample component into the applet.
 
Raghav Puranmalka
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for responding. I was trying to open the SliderExample component as its own window so that when the user clicks on a button to load the SliderExample, a new window pops up and the user can input the bet and then the window closes. Having another container, although a good idea, complicates things as I have images displayed on the applet. Please advise on how I could open a new window. Thanks
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic