File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Need SERIOUS HELP!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Need SERIOUS HELP!!" Watch "Need SERIOUS HELP!!" New topic
Author

Need SERIOUS HELP!!

Raghav Puranmalka
Greenhorn

Joined: May 24, 2004
Posts: 3
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;
}
}


}
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
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

Joined: May 24, 2004
Posts: 3
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

Joined: Jan 14, 2004
Posts: 1535
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Need SERIOUS HELP!!
 
Similar Threads
Prevent resizing of JPanel in BorderLayout
using a bean
Accessing JFrame contents
about setIconImage()
Please help with a simple GUI.