从其他框架调用Jlist时未显示

时间:2018-09-04 12:05:10

标签: java user-interface jframe

Jlist在其自己的框架中位于pi22类中,并且使用Mapper类作为Gui进行iam给用户使用,因此当我从Class Mapper中调用pi22类时,Pi22类中的框架不会显示Jlist它应该显示它仅显示空框架 这是我的代码

package gui;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;

import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.sql.SQLException;

public class Mapper {

private static JFrame frame1;
private static JFrame frame2;
public static String []Excel=new String[99];
public static String []Access=new String[99];



/**
 * @wbp.parser.entryPoint
 */
private static void ff() {
    frame1 = new JFrame();
    frame1.setBounds(100, 100, 450, 300);
    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame1.getContentPane().setLayout(null);

    JButton btnNewButton = new JButton("Choose Excel File");
    btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 18));
    btnNewButton.setBounds(24, 92, 183, 42);
    frame1.getContentPane().add(btnNewButton);

    JButton btnNewButton_1 = new JButton("Choose Access File");
    btnNewButton_1.setFont(new Font("Tahoma", Font.PLAIN, 18));
    btnNewButton_1.setBounds(241, 92, 183, 42);
    frame1.getContentPane().add(btnNewButton_1);

    JButton btnNewButton_2 = new JButton("Map Tables");
    btnNewButton_2.setFont(new Font("Tahoma", Font.PLAIN, 18));
    btnNewButton_2.setBounds(143, 198, 148, 42);
    frame1.getContentPane().add(btnNewButton_2);
    btnNewButton_2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

        backEndMapper h=new backEndMapper();
        try {
            Excel=h.excel();
            for(int i=0;i<Excel.length;i++)
            {
                System.out.println(Excel[i]);
            }
        } catch (EncryptedDocumentException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (InvalidFormatException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try {
            Access=h.access_get();
            for(int i=0;i<Access.length;i++)
            {
                System.out.println(Access[i]);
            }
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }


        pi22 p=new pi22();
        p.callme(Excel, Access);
        }
    });



frame1.setVisible(true);











}
public static void main(String args[])
{


ff();


}

}

Ans,这是pi22类

    package gui;

import java.awt.EventQueue;
import java.awt.Frame;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JButton;

public class pi22 {

    private static JFrame frame2;
public static String []excel;
public static String []access;

    /**
     * Launch the application.
     */
public static void callme(String []ex,String[] ac)
{
    excel=ex;
    access=ac;
initialize();

}
    public pi22() {


    }

    /**
     * Initialize the contents of the frame.
     * @wbp.parser.entryPoint
     */
    public static void initialize() {
        frame2 = new JFrame();
        frame2.setBounds(100, 100, 450, 355);
        frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame2.getContentPane().setLayout(null);


        JButton btnNewButton = new JButton("New button");
        btnNewButton.setBounds(167, 270, 89, 23);
        frame2.getContentPane().add(btnNewButton);

        JList list_2 = new JList(excel);
        list_2.setBounds(31, 35, 147, 187);
        list_2.setVisibleRowCount(10);
        list_2.setVisible(true);
        frame2.getContentPane().add(new JScrollPane(list_2));


        JList list_3 = new JList(access);
        list_3.setBounds(255, 29, 169, 193);
        list_3.setVisibleRowCount(10);
        list_3.setVisible(true);
        frame2.getContentPane().add(new JScrollPane(list_3));

        frame2.setVisible(true);
    }

}

问题在于,在Mapper类中的帧正在调用pi22时,框架pi22中的数据已更新

0 个答案:

没有答案