jake
Posts: 83
Nickname: onorok
Registered: May, 2002
Radio button help
Posted: Jun 11, 2002 10:40 PM
Advertisement
NO matter what radio button I press I always get "true", what am I doing wrong???import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class newAccount extends JFrame
{
//makes the text fields.
TextField fname=new TextField();//First name field.
TextField lname=new TextField();//Last name field.
TextField pnumber=new TextField();//Phone number field.
DoubleField intB=new DoubleField(1);//Interest account field.
//DoubleField simpA=new DoubleField(1);//simple account field.
//Makes the two radio buttons.
JRadioButton simpleA=new JRadioButton("Simple" ,true );
JRadioButton interestA=new JRadioButton("Interest Account" ,false );
//Makes JButton.
JButton ok=new JButton("done" );
public boolean A=true ;
public newAccount()
{
setSize(420,470);
setLocation(350,200);
//Makes the labels.
JLabel title=new JLabel("New Account" ,SwingConstants.CENTER);
title.setFont(new Font("Times New Roman" ,Font.BOLD,28));
JLabel fn=new JLabel("First Name" );
fn.setFont(new Font("Times New Roman" ,Font.BOLD,20));
JLabel ln=new JLabel("Last Name" );
ln.setFont(new Font("Times New Roman" ,Font.BOLD,20));
JLabel pn=new JLabel("Phone Number" );
pn.setFont(new Font("Times New Roman" ,Font.BOLD,20));
JLabel Atype=new JLabel("What type of Account would you like?" );
Atype.setFont(new Font("Times New Roman" ,Font.BOLD,18));
JLabel interA=new JLabel("Base amount is $500" );
interA.setFont(new Font("Times New Roman" ,Font.BOLD,14));
//Sets up the Radio Buttons.
ButtonGroup typebutton=new ButtonGroup();
typebutton.add(simpleA);
typebutton.add(interestA);
//Makes a new container
Container contentPane=getContentPane();
contentPane.setLayout(null );
//Adds components to the frame.
contentPane.add(title);//Fields.
contentPane.add(fname);
contentPane.add(lname);
contentPane.add(pnumber);
contentPane.add(intB);
//contentPane.add(simpA);
contentPane.add(fn);//Labels.
contentPane.add(ln);
contentPane.add(pn);
contentPane.add(interA);
contentPane.add(Atype);
contentPane.add(ok);//JButton.
//Adds Radio Buttons.
contentPane.add(simpleA);
contentPane.add(interestA);
Insets insets=contentPane.getInsets();
//Sets component location.
title.setBounds(50+ insets.left, 3+ insets.top,300, 50);//label.
fname.setBounds(160+ insets.left, 80+ insets.top,200, 20);//Field.
fn.setBounds(35+ insets.left, 80+ insets.top,100, 20);//Label.
lname.setBounds(160+ insets.left, 120+ insets.top,200, 20);//Field.
ln.setBounds(35+ insets.left, 120+ insets.top,100, 20);//Label.
pnumber.setBounds(160+ insets.left, 160+ insets.top,200, 20);//Field.
pn.setBounds(20+ insets.left, 160+ insets.top,200, 20);//Label.
//Sets Radio buttons locations.
Atype.setBounds(50+ insets.left, 230+ insets.top,300, 20);//Label.
simpleA.setBounds(80+ insets.left, 265+ insets.top,200, 20);//Radio button.
//simpA.setBounds(196+ insets.left, 265+ insets.top,50, 20);//Field.
interestA.setBounds(80+ insets.left, 305+ insets.top,200, 20);//Radio button.
intB.setBounds(196+ insets.left, 305+ insets.top,50, 20);//Field.
interA.setBounds(280+ insets.left, 305+ insets.top,140, 20);//JLabel.
ok.setBounds(100+ insets.left, 375+ insets.top,200, 30);//JButton.
//Action events.
ProActionListener actionListener = new ProActionListener();
ok.addActionListener (actionListener);
}
//Caries out all the actions of the game.
private class ProActionListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Object source=event.getSource();
double S=0;
//If simple account is pressed.
if (source==simpleA)
{
A=true ;
}
//If interest account is pressed.
if (source==interestA)
{
//S=intB.getDoubleValue();
A=false ;
}
//If ok button is pressed
if (source==ok)
{
Main_menu.thebank.addCustomer(fname.getText(),lname.getText(),
pnumber.getText(),A,S);
//Main_menu.bankmain.insert(Bank.C.displayCustomer()+"",0);
setVisible(false );
}
}
}
/*public static void main(String[]args)
{
newAccount o=new newAccount();
o.show();
}*/
}