Hi!. Well, we have an assignment, and we will make a program in which I will be selecting a subject from the JComboBox, and when I have my selected subject. It will appear in the Text Field below the Combo Box.

any ideas?
//not the codes :)

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

public class JComboBoxDemo extends JFrame{
	JLabel lbl;
	JLabel lb;
	JTextField tf;
	JComboBox subjectC;
	
	public JComboBoxDemo(){
		lbl=new JLabel("Enter your name:");
		tf=new JTextField(20);
		getContentPane().setLayout(new FlowLayout());
		getContentPane().add(lbl);
		getContentPane().add(tf);
		
		lb=new JLabel("Select a subject:");
		subjectC=new JComboBox();
		subjectC.addItem("COMART");
		subjectC.addItem("COPRO");
		subjectC.addItem("OFFPRO");
		subjectC.addItem("TRIGONO");
		subjectC.addItem("PHYEDU");
		
		JTextField lb3 = new JTextField(15);
		
		JPanel pane=new JPanel();
		pane.add(lbl);
		pane.add(tf);
		pane.add(lb);
		pane.add(subjectC);
		pane.add(lb3);
		
		setContentPane(pane);

		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public static void main(String args[]){
		JComboBoxDemo frame=new JComboBoxDemo();
		frame.setTitle("My GUI Application");
		frame.setSize(300,300);
		frame.setVisible(true);
	}
}

JComboBox#ItemListener

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.