-
Notifications
You must be signed in to change notification settings - Fork 2
/
JComboListExam.java
56 lines (39 loc) · 1.23 KB
/
JComboListExam.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @author Ephramar Telog, CK
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JComboListExam extends JFrame {
JList list;
JComboBox listSubjects;
JLabel labelSubjects;
JTextField showSubjects;
Container container;
public JComboListExam() {
super( "This is an exam" );
container = getContentPane();
container.setLayout( new FlowLayout( FlowLayout.LEFT ) );
labelSubjects = new JLabel( "Choose a subject: " );
listSubjects = new JComboBox();
// Panel Colors
listSubjects.setBackground( Color.BLUE );
listSubjects.setForeground( Color.YELLOW );
// Add specified subjects on the combo box
listSubjects.addItem( "Math" );
listSubjects.addItem( "Science" );
listSubjects.addItem( "English" );
listSubjects.addItem( "Filipino" );
String string = ( String )listSubjects.getSelectedItem();
getContentPane().add( labelSubjects );
getContentPane().add( listSubjects );
getContentPane().add( showSubjects = new JTextField( 10 ) );
showSubject.setText( string );
}
public static void main( String args[] ) {
JComboListExam exam = new JComboListExam();
exam.setSize( 400, 200 );
exam.setVisible( true );
exam.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}