Java Help Please - JPANELS!!!
Results 1 to 2 of 2

Thread: Java Help Please - JPANELS!!!

Hybrid View

  1. #1
    Junior Member
    Join Date
    Nov 2006
    Posts
    2

    Java Help Please - JPANELS!!!

    Well, I need help aligning my Jpanels, and if someone would be so kid, check my code to make sure its good.

    Here is how I want it to look but I can't get the alignment of the JPanels



    Here is my code so far..

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

    public class Paintball extends JFrame
    {


    // Title
    setTitle( "Paintball Item Calculator" );
    setSize( 272, 364 );
    setVisible( true );


    // Header
    private JLabel paintballFormJLabel;


    // JPanel for Fills
    private JPanel fillsJPanel



    // Fills
    private JRadioButton 1fillJRadioButton
    private JRadioButton 5fillsJRadioButton
    private JRadioButton alldayairJRadioButton


    // JPanel for Paint
    private JPanel paintJPanel


    // Paint
    private JCheckBox marballizerJCheckBox;
    private JLabel marballizerJLabel;
    private JCheckBox evilJCheckBox;
    private JLabel evilJLabel;
    private JCheckBox premiumJCheckBox;
    private JLabel premiumJLabel;
    private JCheckBox rampageJCheckBox;
    private JLabel rampageJLabel;
    private JCheckBox shrapnelJCheckBox;
    private JLabel shrapnelJLabel;


    // JPanel for Misc
    private JPanel miscJPanel


    // Misc
    private JCheckBox 6AABattJCheckBox;
    private JLabel 6AABattJLabel;
    private JCheckBox 9VBattJCheckBox;
    private JLabel 9VBattJLabel;
    private JCheckBox tankOringJCheckBox;
    private JLabel tankOringJLabel;
    private JCheckBox 5TankOringJCheckBox;
    private JLabel 5TankOringJLabel;
    private JCheckBox minorJCheckBox;
    private JLabel minorJLabel;
    private JCheckBox majorJCheckBox;
    private JLabel majorJLabel;


    // Calculate Button
    private JButton calculateJButton;


    // Reset Button
    private JButton resetJButton;


    // Final Price Area
    private JLabel totalJLabel;
    private JTextField totalJTextField;


    public Paintball()
    {
    createUserInterface();
    }


    private void createUserInterface()
    {

    Container contentPane = getContentPane();


    contentPane.setLayout( null );


    // Title
    paintballJLabel = new JLabel();
    paintballJLabel.setBounds( 19, 19, 235, 28 );
    paintballJLabel.setText( "Paintball Item Calculator" );
    paintballJLabel.setFont(
    new Font( "Default", Font.PLAIN, 22 ) );
    paintballJLabel.setHorizontalAlignment(
    JLabel.CENTER );
    contentPane.add( paintballJLabel );


    // JPanel for Fills
    fillsJPanel=new JPanel();
    fillsJPanel.setBounds
    fillsJPanel.setBorder(new LineBorder(Color.BLACK));
    fillsJPanel.setLayout(null);
    contentPane.add(fillsJPanel);


    // 1 Fill Button
    1fillJRadioButton=new JRadioButton();
    1fillJRadioButton.setBounds
    1fillJRadioButton.setText("1 Air Fill");
    1fillJRadioButton.setSelected(false);
    displayButtonGroup.add(1fillJRadioButton);
    contentPane.add(1fillJRadioButton);
    1fillJRadioButton.addActionListener(

    new ActionListener()
    {

    public void actionPerformed(ActionEvent event)
    {
    1fillJRadioButtonActionPerformed(event);
    }
    }
    );


    // 5 Fills Button
    5fillsJRadioButton=new JRadioButton();
    5fillsJRadioButton.setBounds
    5fillsJRadioButton.setText("5 Air Fills");
    5fillsJRadioButton.setSelected(false);
    displayButtonGroup.add(5fillsJRadioButton);
    contentPane.add(5fillsJRadioButton);
    5fillsJRadioButton.addActionListener(

    new ActionListener()
    {

    public void actionPerformed(ActionEvent event)
    {
    5fillsJRadioButtonActionPerformed(event);
    }
    }
    );


    // All Day Air Button
    alldayairJRadioButton=new JRadioButton();
    alldayairJRadioButton.setBounds
    alldayairJRadioButton.setText("All Day Air");
    alldayairJRadioButton.setSelected(false);
    displayButtonGroup.add(alldayairJRadioButton);
    contentPane.add(alldayairJRadioButton);
    alldayairJRadioButton.addActionListener(

    new ActionListener()
    {

    public void actionPerformed(ActionEvent event)
    {
    alldayairJRadioButtonActionPerformed(event);
    }
    }
    );


    // JPanel for Paint
    paintJPanel=new JPanel();
    paintJPanel.setBounds
    paintJPanel.setBorder(new LineBorder(Color.BLACK));
    paintJPanel.setLayout(null);
    contentPane.add(paintJPanel);


    // Marballizer
    marballizerJCheckBox=new JCheckBox();
    marballizerJCheckBox.setBounds
    marballizerJCheckBox.setText("Marballizer Paintballs")
    contentPane.add(marballizerJCheckBox);

    marballizerJLabel=new JLabel();
    marballizerJLabel.setBounds
    marballizerJLabel.setText("$65");
    contentPane.add(marballizerJLabel);


    // Evil
    evilJCheckBox=new JCheckBox();
    evilJCheckBox.setBounds
    evilJCheckBox.setText("Evil Paintballs")
    contentPane.add(evilJCheckBox);

    evilJLabel=new JLabel();
    evilJLabel.setBounds
    evilJLabel.setText("$60");
    contentPane.add(evilJLabel);


    // Premium
    premiumJCheckBox=new JCheckBox();
    premiumJCheckBox.setBounds
    premiumJCheckBox.setText("Premium Paintballs")
    contentPane.add(premiumJCheckBox);

    premiumJLabel=new JLabel();
    premiumJLabel.setBounds
    premiumJLabel.setText("$50");
    contentPane.add(premiumJLabel);


    // Rampage
    rampageJCheckBox=new JCheckBox();
    rampageJCheckBox.setBounds
    rampageJCheckBox.setText("Rampage Paintballs")
    contentPane.add(rampageJCheckBox);

    rampageJLabel=new JLabel();
    rampageJLabel.setBounds
    rampageJLabel.setText("$40");
    contentPane.add(rampageJLabel);


    // Shrapnel
    shrapnelJCheckBox=new JCheckBox();
    shrapnelJCheckBox.setBounds
    shrapnelJCheckBox.setText("Shrapnel Paintballs")
    contentPane.add(shrapnelJCheckBox);

    shrapnelJLabel=new JLabel();
    shrapnelJLabel.setBounds
    shrapnelJLabel.setText("$25");
    contentPane.add(shrapnelJLabel);


    // JPanel for Misc
    miscJPanel=new JPanel();
    miscJPanel.setBounds
    miscJPanel.setBorder(new LineBorder(Color.BLACK));
    miscJPanel.setLayout(null);
    contentPane.add(miscJPanel);


    // 6AA Batteries
    6AABattJCheckBox=new JCheckBox();
    6AABattJCheckBox.setBounds
    6AABattJCheckBox.setText("6 AA Batteries")
    contentPane.add(6AABattJCheckBox);

    6AABattJLabel=new JLabel();
    6AABattJLabel.setBounds
    6AABattJLabel.setText("$5");
    contentPane.add(6AABattJLabel);


    // 9V Battery
    9VBattJCheckBox=new JCheckBox();
    9VBattJCheckBox.setBounds
    9VBattJCheckBox.setText("9V Battery")
    contentPane.add(9VBattJCheckBox);

    9VBattJLabel=new JLabel();
    9VBattJLabel.setBounds
    9VBattJLabel.setText("$2.50");
    contentPane.add(9VBattJLabel);


    // One Tank O-Ring
    tankOringJCheckBox=new JCheckBox();
    tankOringJCheckBox.setBounds
    tankOringJCheckBox.setText("One Tank O-Ring")
    contentPane.add(tankOringJCheckBox);

    tankOringJLabel=new JLabel();
    tankOringJLabel.setBounds
    tankOringJLabel.setText("$.50");
    contentPane.add(tankOringJLabel);


    // Five Tank O-Rings
    5TankOringJCheckBox=new JCheckBox();
    5TankOringJCheckBox.setBounds
    5TankOringJCheckBox.setText("One Tank O-Ring")
    contentPane.add(5TankOringJCheckBox);

    5TankOringJLabel=new JLabel();
    5TankOringJLabel.setBounds
    5TankOringJLabel.setText("$.50");
    contentPane.add(5TankOringJLabel);


    // Minor Tune-Up
    minorJCheckBox=new JCheckBox();
    minorJCheckBox.setBounds
    minorJCheckBox.setText("Minor Tune-Up")
    contentPane.add(minorJCheckBox);

    minorJLabel=new JLabel();
    minorJLabel.setBounds
    minorJLabel.setText("$15");
    contentPane.add(minorJLabel);


    // Major Tune-Up
    majorJCheckBox=new JCheckBox();
    majorJCheckBox.setBounds
    majorJCheckBox.setText("Major Tune-Up")
    contentPane.add(majorJCheckBox);

    majorJLabel=new JLabel();
    majorJLabel.setBounds
    majorJLabel.setText("$25");
    contentPane.add(majorJLabel);


    // Calculate Button
    calculateJButton = new JButton();
    calculateJButton.setBounds( 155, 296, 94, 24 );
    calculateJButton.setText( "Calculate" );
    contentPane.add( calculateJButton );
    calculateJButton.addActionListener(

    new ActionListener()
    {

    public void actionPerformed( ActionEvent event )
    {
    calculateJButtonActionPerformed( event );
    }

    }

    );


    // Reset Button
    resetJButton = new JButton();
    resetJButton.setBounds( 155, 296, 94, 24 );
    resetJButton.setText( "Reset" );
    contentPane.add( resetJButton );
    resetJButton.addActionListener(

    new ActionListener()
    {

    public void actionPerformed( ActionEvent event )
    {
    resetJButtonActionPerformed( event );
    }

    }

    );


    // Total JLabel
    totalJLabel = new JLabel();
    totalJLabel.setBounds( 144, 256, 41, 21 );
    totalJLabel.setText( "Total:" );
    contentPane.add( totalJLabel );


    // Total JTextField
    totalJTextField = new JTextField();
    totalJTextField.setBounds( 192, 256, 56, 21 );
    totalJTextField.setEditable( false );
    totalJTextField.setHorizontalAlignment( JTextField.CENTER );
    contentPane.add( totalJTextField );

    Heres the pic again so you dont have to scroll all that way up.


  2. #2
    Junior Member
    Join Date
    Nov 2006
    Posts
    2
    P.S.

    Thanks for your help guys.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •