java swing按钮事件。

要制作如图要求的一个界面,现在卡在给按钮提供方法那里,不知道该怎么返回得到的数组给列表。图片说明

import java.awt.*;
import java.awt.List;

import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class work2 {
    private JFrame jf = new JFrame("随机数序列排序");
    private Container c = jf.getContentPane();
    private JLabel a1 = new JLabel("长度");
    private JTextField length = new JTextField(5);
    private JLabel a2 = new JLabel("范围");
    private JTextField limit = new JTextField(5);
    private JButton creat = new JButton("生成");
    private JButton sort = new JButton("排序");
    private String[] list_1;
    private String[] list_2;
    private String[] list_3;
    private JList list1 = new JList();
    private JList list2 = new JList();
    private JList list3 = new JList();
    private JScrollPane gundong1 = new JScrollPane();
    private JScrollPane gundong2 = new JScrollPane();
    private JScrollPane gundong3 = new JScrollPane();

    public work2()
    {
        jf.setBounds(400,500,1000,300);
        c.setLayout(new BorderLayout());
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setVisible(true);
        init();
    }
    public void init()
    {
        //面板的上边
        JPanel title = new JPanel();
        title.setLayout(new FlowLayout());
        title.add(a1);
        title.add(length);
        title.add(a2);
        title.add(limit);
        title.add(creat);
        title.add(sort);
        c.add(title,"North");
        //面板的下边
        JPanel list = new JPanel();
        list.setLayout(new FlowLayout());
        gundong1.setBorder(BorderFactory.createTitledBorder("随机数序列"));
        gundong2.setBorder(BorderFactory.createTitledBorder("排序序列(升序)"));
        gundong3.setBorder(BorderFactory.createTitledBorder("降序序列(降序)"));
        gundong1.setViewportView(list1);
        gundong2.setViewportView(list2);
        gundong3.setViewportView(list3);
        list.add(gundong1);
        list.add(gundong2);
        list.add(gundong3);
        c.add(list,"Center");
    }
    public void listerner()
    {
        creat.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int len = Integer.parseInt(length.getText());
                int limits = Integer.parseInt(limit.getText());
                Random ra = new Random();
                int[] arr1 = new int[len];

                for(int i=0;i<len;i++)
                {
                    arr1[i] = ra.nextInt(limits);
                    list_3[i] = String.valueOf(arr1[i]);
                }
                list1.add(list_3);
            }

        });
    }
    public static void main(String[] args)
    {
        new work2();
    }
}
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐