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;
}
}
}