0

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);
	}
}
2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by mKorbel
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.