PDA

Click to See Complete Forum and Search --> : JButton (ActionPerformed)


mbonfyre
Mar 12th, 2003, 11:31 AM
Please could somebody tell me where I am going wrong:

The three buttons are meant to read from their combo box and write to the text box, but all three buttons only read from one combo box(so it is repeating)
ie.

Instead of '1st January 2003' it reads '1st 1st 1st'

I know that the rest of the form needs sorting, but I am trying to deal with one part at a time so I gain a full understanding of what is happening.


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

public class System1Trial1 extends JApplet implements ActionListener {

Container c;

JComboBox myCombo2;
JComboBox myCombo;
JComboBox myCombo3;

JPanel mypan;
JTextArea myBox;

JButton myRound;
JButton myRound2;
JButton myRound3;
JButton mythirdbtn;
JButton mypicbtn;

String myOrder ="";
String myOrder2="";
String myOrder3="";

public void init() {

JPanel mypan = new JPanel();

JPanel myButts = new JPanel();
JCheckBox myfirst = new JCheckBox("Male");
JCheckBox mysecond = new JCheckBox("Female");
JCheckBox mythird = new JCheckBox("all of the above!");

Icon fly = new ImageIcon("butterfly.gif");

myBox = new JTextArea(1,5); //5,15

myCombo2 =new JComboBox();
myCombo2.addItem("1st");
myCombo2.addItem("2nd");
myCombo2.addItem("3rd");
myCombo2.addItem("4th");
myCombo2.addItem("5th");
myCombo2.addItem("6th");
myCombo2.addItem("7th");
myCombo2.addItem("8th");
myCombo2.addItem("9th");
myCombo2.addItem("10th");
myCombo2.addItem("11th");
mypan.add(myCombo2);

myRound2 = new JButton("<- Confirm Date");
myRound2.addActionListener(this);
mypan.add(myRound2);

myCombo =new JComboBox();
myCombo.addItem("January");
myCombo.addItem("February");
myCombo.addItem("March");
myCombo.addItem("April");
myCombo.addItem("May");
myCombo.addItem("June");
myCombo.addItem("July");
myCombo.addItem("August");
myCombo.addItem("September");
myCombo.addItem("October");
myCombo.addItem("November");
myCombo.addItem("December");
mypan.add(myCombo);

myRound = new JButton("<- Confirm Month");
myRound.addActionListener(this);
mypan.add(myRound);

myCombo3 =new JComboBox();
myCombo3.addItem("2000");
myCombo3.addItem("2001");
myCombo3.addItem("2002");
myCombo3.addItem("2003");
myCombo3.addItem("2004");
mypan.add(myCombo3);

myRound3 = new JButton("<- Confirm Year");
myRound3.addActionListener(this);
mypan.add(myRound3);

JLabel secondLabel = new JLabel("Enrollment date ->", fly,SwingConstants.CENTER);
mypan.add(secondLabel);

mypan.add(myBox);

ButtonGroup sex = new ButtonGroup();


JTextField tfield1 = new JTextField();
JButton myfirstbtn = new JButton("how's this?");
JButton mypicbtn = new JButton("Button 2 avec de picture");

mypan.add(mypicbtn);

mypan.add(tfield1);
mypan.add(myfirstbtn);

mypan.setLayout(new GridLayout(6,2));

sex.add(myfirst);
sex.add(mysecond);
sex.add(mythird);

myButts.add(myfirst);
myButts.add(mysecond);
myButts.add(mythird);

myButts.add(myfirstbtn);
myButts.add(mypicbtn);

mypan.add(mypicbtn);


EtchedBorder bread = new EtchedBorder();
myButts.setBorder(new TitledBorder(bread, "What sex are you?"));

mypan.add(myButts);


mypan.setLayout(new GridLayout(6,2));

c = getContentPane();

c.add(mypan);
}

public void actionPerformed(ActionEvent e){
myOrder += myCombo.getSelectedItem()+"\n";
myBox.setText(myOrder);

myOrder2 += myCombo2.getSelectedItem()+" ";
myBox.setText(myOrder2);

myOrder3 += myCombo3.getSelectedItem()+" ";
myBox.setText(myOrder3);
}

}

mbonfyre
Apr 1st, 2003, 11:17 AM
bump :D

delta770
Apr 7th, 2003, 03:08 AM
i just quickly went over the code, so i could be wrong ut i don't see a prob here...so if you have more code it could be something there...

--770

mbonfyre
Apr 7th, 2003, 04:42 AM
that's all the code, I will need to add more later, I just wanted to get one bit working properly before I carried on with it.