-2
这是我已经有的代码。现在我想能够创建自己的字符串数组,然后将其作为我的gui中的列表。我尝试了几个只是将其添加到面板,并没有奏效。任何想法我会如何去做这件事?如何从数组中添加一个gui列表?
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JList;
import java.awt.*;
public class plannerGUI {
private JFrame f;
private JPanel p2;
private JPanel p;
private JButton b1;
private JLabel label;
public plannerGUI() {
gui();
}
public void gui() {
f = new JFrame("Planner");
f.setVisible(true);
f.setSize(600,400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p = new JPanel();
p2 = new JPanel();
b1 = new JButton("Add Date");
label = new JLabel("Upcoming Events");
p2.add(label);
p.add(b1);
f.add(p2);
f.add(p,BorderLayout.SOUTH);
}
public static void main(String[] args) {
new plannerGUI();
}
}