-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDropdown Box GUI
40 lines (28 loc) · 1.1 KB
/
Dropdown Box GUI
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
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DropDownBox {
public static void main(String[] args) {
String[] optionsToChoose = {"Cardio", "Arms", "Legs", "Push", "Pull"};
JFrame frame = new JFrame(); //Makes window
JComboBox<String> jComboBox = new JComboBox<>(optionsToChoose); //makes drop down list
jComboBox.setBounds(50,70,140,20);
JButton button = new JButton("Done");
button.setBounds(100,100,90,20);
JLabel jLabel = new JLabel();
jLabel.setBounds(90,100,400,100);
frame.add(button);
frame.add(jComboBox);
frame.add(jLabel);
frame.setLayout(null);
frame.setSize(350,250);
frame.setVisible(true);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String selectedWorkout = "You selected " + jComboBox.getItemAt(jComboBox.getSelectedIndex());
jLabel.setText(selectedWorkout);
}
});
}
}