嗨,先生,我对我的程序感到困惑,我怎么能找到并调整我的JList等等。我现在正在使用FlowLayout();但我不能调整大小并找到JList等,这是我的代码到目前为止。任何建议的人
public static void main(String args [])
{
brie t1 = new brie();
t1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
t1.setSize(300,200);
t1.setVisible(true);
t1.setLocationRelativeTo(null);
t1.setResizable(false);
}
String namep [] = {"Chocolate", "Cake", "Candy", "Ice Cream", "Snacks"};
int pricep [] = {1, 2, 3, 4, 5};
JPanel panel2 = new JPanel();
JLabel l = new JLabel("Enter your payment");
JTextField f = new JTextField(15);
JButton tru = new JButton("Yes");
JFrame w = new JFrame("pay");
JList lst = new JList(namep);
JLabel l2 = new JLabel("Enter Quantity");
JTextField t1 = new JTextField(10);
JLabel l3 = new JLabel();
JButton b2 = new JButton("Exit");
JButton b1 = new JButton("Compute");
double tet;
Container cong = getContentPane();
String namep1,totallist;
double otpc;
int paym,tot = 0;
int quan,pricep1;
int x,grandtotal,change;
public brie(){
totallist = "";
namep1 = "";
// t1.setEditable(false);
t1.setText("");
cong.setLayout(new FlowLayout());
new JScrollPane(lst).setSize(30,30);
cong.add(new JScrollPane(lst));
cong.add(l2);
cong.add(t1);
cong.add(b1);
cong.add(b2);
cong.add(l3);
b1.addActionListener(this);
b2.addActionListener(this);
tru.addActionListener(this);
lst.setSelectedIndex(0);
lst.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
lst.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
t1.setEditable(true);
x = lst.getSelectedIndex();
}
});