combobox

Hi

wel basically i have to make a task (for school) with 5 TextFields , 1 combobox and 1 button

if you press on that button then the data should get under it

i have got two problems how to get a selected item out of an combobox and how to get the data under it

if someone could help me

thanks

this is what i have already done

import java.awt.event.*;

import javax.swing.*;

import java.awt.*;

class TekstvakEnKnopPaneel extends JPanel {

private JTextField tekstvak1,tekstvak2,tekstvak3,tekstvak4,tekstvak5;

private JButton knop;

private JComboBox box;

public TekstvakEnKnopPaneel() {

tekstvak1 = new JTextField (20);

tekstvak1.setText ("Name");

tekstvak2 = new JTextField (20)

tekstvak2.setText ("Voornaam");

tekstvak3 = new JTextField (30);

tekstvak3.setText ("Adres");

tekstvak4 = new JTextField (4);

tekstvak4.setText ("Postcode");

tekstvak5 = new JTextField (20);

tekstvak5.setText ("Plaats");

JComboBox box = new JComboBox();

String[] item = { "Mevrouw", "Mijnheer"};

box = new JComboBox(item);

ActionListener handler = new Handler();

knop = new JButton ("Klik hier");

knop.addActionListener(handler);

add( tekstvak1 );

add( tekstvak2 );

add( tekstvak3 );

add( tekstvak4 );

add( tekstvak5 );

add( knop );

add( box);

}

class Handler implements ActionListener {

public void actionPerformed( ActionEvent e ) {

if(e.getSource() == knop);

}

}

}

[1618 byte] By [infina] at [2007-10-2 3:13:53]
# 1
1) Use the "code" formatting tags when posting code so the code is readable.2) [url http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html#listeners]How to Use Combo Boxes[/url]
camickra at 2007-7-15 21:41:00 > top of Java-index,Desktop,Core GUI APIs...
# 2
I not understand the problem. The textfield's text must be added at the JComboBox item when I press the button?
Maxa at 2007-7-15 21:41:00 > top of Java-index,Desktop,Core GUI APIs...
# 3
Yes if i press the button then under button should come the text for exempleif i chose in the combbox sir and i type your name in one of the textfields and i press on the button then there should come " dear sir max "
infina at 2007-7-15 21:41:00 > top of Java-index,Desktop,Core GUI APIs...
# 4

I used a label that have add to Panel to view the text but you can print it to video with a System.out...

label.setText(comboBox.getSelectedItem().toString()+" "+textField1.getText()+" "+textField2.getText());

add this code in the action performed method.

Maxa at 2007-7-15 21:41:00 > top of Java-index,Desktop,Core GUI APIs...
# 5
another thing: You create first the array of option that you want insert in the JComboBox and than invoke the constructor so that you avoid to call 2 times the same constructor. I hope to help you.
Maxa at 2007-7-15 21:41:00 > top of Java-index,Desktop,Core GUI APIs...