Adding in CS-115 coursework
This commit is contained in:
36
cs-115-test/src/List.java
Normal file
36
cs-115-test/src/List.java
Normal file
@@ -0,0 +1,36 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class List {
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame();
|
||||
String[] trees = { "Maple", "Larch", "Spruce", "Balsam" };
|
||||
JList treeList = new JList(trees);
|
||||
JPanel panel = new JPanel();
|
||||
|
||||
JLabel label = new JLabel("Select a Tree");
|
||||
|
||||
treeList.add(panel);
|
||||
|
||||
JButton button = new JButton("Show Me");
|
||||
button.setBounds(10, 150, 230, 30);
|
||||
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String data = "";
|
||||
if (treeList.getSelectedIndex() != -1) {
|
||||
data = "Trees: " + treeList.getSelectedValue();
|
||||
button.setText(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
frame.add(button);
|
||||
frame.add(treeList);
|
||||
frame.setSize(250, 250);
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user