Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从一个JFrame接收另一个JFrame的值并插入到JTable中_Java_Swing_Netbeans - Fatal编程技术网

Java 如何从一个JFrame接收另一个JFrame的值并插入到JTable中

Java 如何从一个JFrame接收另一个JFrame的值并插入到JTable中,java,swing,netbeans,Java,Swing,Netbeans,我支持从一个JFrame接收值并插入JTable 我想知道如何接收一个准备插入JTable的对象academico。从de my class FrameTemp 类模型Acadêmico package model; public class Academico { private String matricula; private String nome; private String curso; private int periodo; public Academico() { }

我支持从一个JFrame接收值并插入JTable

我想知道如何接收一个准备插入JTable的对象academico。从de my class FrameTemp

类模型Acadêmico

package model;

public class Academico {
private String matricula;
private String nome;
private String curso;
private int periodo;

public Academico() {
}

public Academico(String matricula, String nome, String curso, int periodo) {
    this.matricula = matricula;
    this.nome = nome;
    this.curso = curso;
    this.periodo = periodo;
}

public String getMatricula() {
    return matricula;
}

public void setMatricula(String matricula) {
    this.matricula = matricula;
}

public String getNome() {
    return nome;
}

public void setNome(String nome) {
    this.nome = nome;
}

public String getCurso() {
    return curso;
}

public void setCurso(String curso) {
    this.curso = curso;
}

public int getPeriodo() {
    return periodo;
}

public void setPeriodo(int periodo) {
    this.periodo = periodo;
}
}
类应该接收值的帧

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;

public class Frame extends JFrame implements ActionListener {

private static Academico novoAcademico;
private static FrameTemp frameTemporario;
private JTable tabela;
private DefaultTableModel modelo;
private ArrayList<Academico> academicos;
private JButton btAdd, btAtualizar, btDelete;
private JPanel painel, painelGrid;
private BorderLayout borderLayout;
private GridLayout gridLayout;

public Frame(Academico academico) {
    this.setTitle("Acadêmicos Cadastrados");

    this.painel = new JPanel();
    this.painelGrid = new JPanel();

    borderLayout = new BorderLayout();
    gridLayout = new GridLayout(1, 3);
    setContentPane(painel);
    this.setLayout(borderLayout);

    painel.add(painelGrid);
    painelGrid.setLayout(gridLayout);

    this.modelo = new DefaultTableModel();
    this.tabela = new JTable(modelo);
    this.btAdd = new JButton("Insert");
    this.btAdd.setFont(new Font("Verdana", Font.PLAIN, 20));
    this.btAdd.setBackground(Color.BLACK);
    this.btAdd.setForeground(Color.WHITE);
    this.btAtualizar = new JButton("Update");
    this.btAtualizar.setFont(new Font("Verdana", Font.PLAIN, 20));
    this.btAtualizar.setBackground(Color.BLACK);
    this.btAtualizar.setForeground(Color.WHITE);
    this.btDelete = new JButton("Delete");
    this.btDelete.setFont(new Font("Verdana", Font.PLAIN, 20));
    this.btDelete.setBackground(Color.BLACK);
    this.btDelete.setForeground(Color.WHITE);

    this.modelo.addColumn("Matrícula");
    this.modelo.addColumn("Nome");
    this.modelo.addColumn("Curso");
    this.modelo.addColumn("Período");

    this.tabela.getColumnModel().getColumn(0).setPreferredWidth(20);
    this.tabela.getColumnModel().getColumn(1).setPreferredWidth(30);
    this.tabela.getColumnModel().getColumn(2).setPreferredWidth(50);
    this.tabela.getColumnModel().getColumn(3).setPreferredWidth(20);

    this.academicos = new ArrayList<>();

    this.academicos.add(new Academico("123", "Student1", "Information System", 3));
    this.academicos.add(new Academico("234", "Student2", "Science", 5));
    this.academicos.add(new Academico("345", "Student3", "Engineer", 7));

    for (Academico a : this.academicos) {
        this.modelo.addRow(new Object[]{a.getMatricula(), a.getNome(), a.getCurso(), a.getPeriodo()});
    }

    this.painel.add(BorderLayout.NORTH, new JScrollPane(this.tabela));
    this.painel.add(BorderLayout.SOUTH, painelGrid);
    this.painelGrid.add(btAdd);
    this.painelGrid.add(btAtualizar);
    this.painelGrid.add(btDelete);

    this.btDelete.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int dialog = JOptionPane.YES_NO_OPTION;

            int selRow = tabela.getSelectedRow();
            if (selRow != -1) {
                int resultado = JOptionPane.showConfirmDialog(null, "Deseja realmente excluir essa linha?", "Confirmação", dialog);

                if (resultado == 0) {
                    modelo.removeRow(selRow);
                }

            }
        }
    }
    );

    this.btAdd.addActionListener(this);

    this.pack();

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.setVisible(true);
}

public static void main(String[] args) {
    new Frame(novoAcademico);
}

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btAdd) {

        Academico academico = new Academico();
        frameTemporario = new FrameTemp();
        frameTemporario.setVisible(true);


        ArrayList<Academico> lista = new ArrayList<>();

        lista.add(new Academico(academico.getMatricula(), academico.getNome(), academico.getCurso(), academico.getPeriodo()));

        for (Academico a : lista) {

            this.modelo.addRow(new Object[]{a.getMatricula(), a.getNome(), a.getCurso(), a.getPeriodo()});
        }


    }
}
}
导入java.awt.BorderLayout;
导入java.awt.Color;
导入java.awt.Font;
导入java.awt.GridLayout;
导入java.awt.event.ActionEvent;
导入java.awt.event.ActionListener;
导入java.util.ArrayList;
导入javax.swing.JButton;
导入javax.swing.JFrame;
导入javax.swing.JOptionPane;
导入javax.swing.JPanel;
导入javax.swing.JScrollPane;
导入javax.swing.JTable;
导入javax.swing.event.TableModelEvent;
导入javax.swing.event.TableModelListener;
导入javax.swing.table.DefaultTableModel;
公共类框架扩展JFrame实现ActionListener{
私立静态学院;
私有静态FrameTemp frameTemporario;
私有JTable tabela;
模型modelo;
私立ArrayList学院;
私有JButton btAdd、btAtualizar、btDelete;
私人JPanel painel,painelGrid;
私人边界布局;
私有网格布局;
公共框架(Academico Academico){
本文件标题为(“Acadêmicos Cadastrados”);
this.painel=new JPanel();
this.painelGrid=new JPanel();
borderLayout=新的borderLayout();
gridLayout=新的gridLayout(1,3);
setContentPane(painel);
此.setLayout(borderLayout);
painel.add(painelGrid);
painelGrid.setLayout(gridLayout);
this.modelo=新的DefaultTableModel();
this.tabela=新JTable(modelo);
this.btAdd=新的JButton(“插入”);
这个.btAdd.setFont(新字体(“Verdana”,Font.PLAIN,20));
此.btAdd.setBackground(颜色.黑色);
this.btAdd.set前台(Color.WHITE);
this.btAtualizar=新的JButton(“更新”);
setFont(新字体(“Verdana”,Font.PLAIN,20));
此.btAtualizar.backbackground(颜色:黑色);
this.btatuanizar.setForeground(Color.WHITE);
this.btDelete=新的JButton(“删除”);
这个.btDelete.setFont(新字体(“Verdana”,Font.PLAIN,20));
此.btDelete.setBackground(颜色.黑色);
this.btDelete.set前台(Color.WHITE);
本.modelo.addColumn(“Matrícula”);
本.modelo.addColumn(“Nome”);
此.modelo.addColumn(“Curso”);
这个.modelo.addColumn(“periodo”);
this.tabela.getColumnModel().getColumn(0.setPreferredWidth(20);
this.tabela.getColumnModel().getColumn(1.setPreferredWidth(30);
this.tabela.getColumnModel().getColumn(2.setPreferredWidth(50);
this.tabela.getColumnModel().getColumn(3.setPreferredWidth(20);
this.academicos=新的ArrayList();
本.academicos.增补(新Academico(“123”,“学生1”,“信息系统”,3));
本.academicos.增补(新Academico(“234”,“学生2”,“科学”,5));
本.academicos.增补(新的Academico(“345”,“学生3”,“工程师”,7));
对于(Academico a:这个,Academico){
this.modelo.addRow(新对象[]{a.getMatricula()、a.getNome()、a.getCurso()、a.getPeriodo()});
}
this.painel.add(BorderLayout.NORTH,新的JScrollPane(this.tabela));
this.painel.add(BorderLayout.SOUTH,painelGrid);
this.painelGrid.add(btAdd);
this.painelGrid.add(btAtualizar);
this.painelGrid.add(btDelete);
this.btDelete.addActionListener(新ActionListener(){
@凌驾
已执行的公共无效操作(操作事件e){
int dialog=JOptionPane.YES\u NO\u选项;
int selRow=tabela.getSelectedRow();
如果(selRow!=-1){
int resultado=JOptionPane.showConfirmDialog(null,“Deseja realmente excluir essa linha?”,“Confirmaço”,dialog);
if(resultado==0){
模型拆卸器(selRow);
}
}
}
}
);
this.btAdd.addActionListener(this);
这个包();
此.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
此.setVisible(true);
}
公共静态void main(字符串[]args){
新框架(novoAcademico);
}
@凌驾
已执行的公共无效操作(操作事件e){
如果(如getSource()==btAdd){
Academico Academico=新Academico();
frameTemporario=新的FrameTemp();
frameTemporario.setVisible(真);
ArrayList lista=新的ArrayList();
列表a.add(新的Academico(Academico.getMatricula(),Academico.getNome(),Academico.getCurso(),Academico.getPeriodo());
对于(a院士:lista){
this.modelo.addRow(新对象[]{a.getMatricula()、a.getNome()、a.getCurso()、a.getPeriodo()});
}
}
}
}
类,该类应发送值

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.jdesktop.swingx.prompt.PromptSupport;

public class FrameTemp extends JFrame implements ActionListener {

private String title = "Adicionar novo";
private Frame frame;
private ArrayList<Academico> academicos;
private Academico academico;
private JTextField tfMatricula, tfNome, tfCurso, tfPeriodo;
private JButton btConfirmar;
private JPanel painel, painelGrid;

private BorderLayout borderLayout;
private GridLayout gridLayout;

public FrameTemp() {
    this.setTitle(title);
    Container c = getContentPane();

    c.setLayout(new BorderLayout());

    Container c2 = new JPanel();
    c2.setLayout(new GridLayout(1, 4));
    academico = new Academico();
    academicos = new ArrayList<Academico>();

    this.btConfirmar = new JButton("Confirmar");
    this.tfMatricula = new JTextField();
    this.tfMatricula.setToolTipText("Insira sua matrícula aqui");
    PromptSupport.setPrompt("Matrícula", tfMatricula);
    PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, tfMatricula);
    PromptSupport.setFontStyle(Font.BOLD, tfMatricula);

    this.tfNome = new JTextField();
    this.tfNome.setToolTipText("Insira seu nome aqui");
    PromptSupport.setPrompt("Nome", tfNome);
    PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, tfNome);
    PromptSupport.setFontStyle(Font.BOLD, tfNome);

    this.tfCurso = new JTextField();
    this.tfCurso.setToolTipText("Insira seu curso aqui");
    PromptSupport.setPrompt("Curso", tfCurso);
    PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, tfCurso);
    PromptSupport.setFontStyle(Font.BOLD, tfCurso);

    this.tfPeriodo = new JTextField();
    this.tfPeriodo.setToolTipText("Insira seu período aqui");
    PromptSupport.setPrompt("Período", tfPeriodo);
    PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, tfPeriodo);
    PromptSupport.setFontStyle(Font.BOLD, tfPeriodo);

    btConfirmar.addActionListener(this);
    c2.add(tfMatricula);
    c2.add(tfNome);
    c2.add(tfCurso);
    c2.add(tfPeriodo);

    c.add(btConfirmar);

    c.add(BorderLayout.NORTH, c2);
    c.add(BorderLayout.SOUTH, btConfirmar);

    this.setVisible(true);
    this.setSize(500, 300);
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}

@Override
public void actionPerformed(ActionEvent e) {

    this.academico.setMatricula(tfMatricula.getText().toString());
    this.academico.setNome(tfNome.getText());
    this.academico.setCurso(tfCurso.getText());
    this.academico.setPeriodo(Integer.parseInt(tfPeriodo.getText()));

   Frame frame = new Frame(academico);
    this.dispose();
}

}
导入java.awt.BorderLayout;
导入java.awt.Container;
导入java.awt.Font;
导入java.awt.GridLayout;
导入java.awt.event.ActionEvent;
导入java.awt.event.ActionListener;
导入java.util.ArrayList;
导入javax.swing.JButton;
导入javax.swing.JFrame;
导入javax.swing.JPanel;
导入javax.swing.JTextField;
导入org.jdesktop.swingx.prompt.PromptSupport;
公共类FrameTemp扩展JFrame实现ActionListener{
私有字符串title=“Adicionar novo”;
专用框架;
私立ArrayList学院;
私人院士;
私人JTextField tfMatricula、tfNome、tfCurso、tfPeriodo;
私人JButton btConfirmar;
私人JPanel painel,painelGrid;
私人边界布局;
私有网格布局;
公共框架温度(){
这个.setTitle(title);
容器c=getContentPane();
c、 setLayout(新的BorderLayout());
容器c2=新的JPanel();
c2.设置布局(新网格布局(1,4));
academico=新academico();
academicos=新ArrayList();
this.btConfirmar=新的JButton(“Confirmar”);
this.tfMatricula=new JTextField();
这个.tfMatricula.setToolTipText(“Insira sua matrícula aqui”);
PromptSupport.setPrompt(“Matrícula”,tfMatricula);
PromptSupport.setFocusBehavior(PromptSupport.Foc
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.jdesktop.swingx.prompt.PromptSupport;

public class Main {

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

    public Main() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                }

                StuffINeedToAskYou askYou = new StuffINeedToAskYou();
                int response = JOptionPane.showConfirmDialog(null, askYou, "Adicionar novo", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
                if (response == JOptionPane.OK_OPTION) {
                    Academico academico = askYou.getAcademico();
                }
            }
        });
    }

    public class StuffINeedToAskYou extends JPanel implements ActionListener {

        private String title = "Adicionar novo";
        private ArrayList<Academico> academicos;
        private Academico academico;
        private JTextField tfMatricula, tfNome, tfCurso, tfPeriodo;
        private JButton btConfirmar;
        private JPanel painel, painelGrid;

        private BorderLayout borderLayout;
        private GridLayout gridLayout;

        public StuffINeedToAskYou() {

            setLayout(new BorderLayout());

            Container c2 = new JPanel();
            c2.setLayout(new GridLayout(1, 4));
            academico = new Academico();
            academicos = new ArrayList<Academico>();

            this.btConfirmar = new JButton("Confirmar");
            this.tfMatricula = new JTextField();
            this.tfMatricula.setToolTipText("Insira sua matrícula aqui");
            PromptSupport.setPrompt("Matrícula", tfMatricula);
            PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, tfMatricula);
            PromptSupport.setFontStyle(Font.BOLD, tfMatricula);

            this.tfNome = new JTextField();
            this.tfNome.setToolTipText("Insira seu nome aqui");
            PromptSupport.setPrompt("Nome", tfNome);
            PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, tfNome);
            PromptSupport.setFontStyle(Font.BOLD, tfNome);

            this.tfCurso = new JTextField();
            this.tfCurso.setToolTipText("Insira seu curso aqui");
            PromptSupport.setPrompt("Curso", tfCurso);
            PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, tfCurso);
            PromptSupport.setFontStyle(Font.BOLD, tfCurso);

            this.tfPeriodo = new JTextField();
            this.tfPeriodo.setToolTipText("Insira seu período aqui");
            PromptSupport.setPrompt("Período", tfPeriodo);
            PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, tfPeriodo);
            PromptSupport.setFontStyle(Font.BOLD, tfPeriodo);

            btConfirmar.addActionListener(this);
            c2.add(tfMatricula);
            c2.add(tfNome);
            c2.add(tfCurso);
            c2.add(tfPeriodo);

            add(btConfirmar);

            add(BorderLayout.NORTH, c2);
            add(BorderLayout.SOUTH, btConfirmar);

        }

        public Academico getAcademico() {
            return academico;
        }

        @Override
        public void actionPerformed(ActionEvent e) {

            this.academico.setMatricula(tfMatricula.getText().toString());
            this.academico.setNome(tfNome.getText());
            this.academico.setCurso(tfCurso.getText());
            this.academico.setPeriodo(Integer.parseInt(tfPeriodo.getText()));
        }

    }

    public class Academico {

        private String matricula;
        private String nome;
        private String curso;
        private int periodo;

        public Academico() {
        }

        public Academico(String matricula, String nome, String curso, int periodo) {
            this.matricula = matricula;
            this.nome = nome;
            this.curso = curso;
            this.periodo = periodo;
        }

        public String getMatricula() {
            return matricula;
        }

        public void setMatricula(String matricula) {
            this.matricula = matricula;
        }

        public String getNome() {
            return nome;
        }

        public void setNome(String nome) {
            this.nome = nome;
        }

        public String getCurso() {
            return curso;
        }

        public void setCurso(String curso) {
            this.curso = curso;
        }

        public int getPeriodo() {
            return periodo;
        }

        public void setPeriodo(int periodo) {
            this.periodo = periodo;
        }
    }
}
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class Frame extends JFrame implements ActionListener {

private static Academico novoAcademico;
private static FrameTemp frameTemporario;
private JTable tabela;
private static DefaultTableModel modelo;
private ArrayList<Academico> academicos;
private JButton btAdd, btAtualizar, btDelete;
private JPanel painel, painelGrid;
private BorderLayout borderLayout;
private GridLayout gridLayout;

public Frame(Academico academico) {
    this.setTitle("Acadêmicos Cadastrados");
    this.painel = new JPanel();
    this.painelGrid = new JPanel();

    borderLayout = new BorderLayout();
    gridLayout = new GridLayout(1, 3);
    setContentPane(painel);
    this.setLayout(borderLayout);

    painel.add(painelGrid);
    painelGrid.setLayout(gridLayout);

    this.modelo = new DefaultTableModel();
    this.tabela = new JTable(modelo);
    this.btAdd = new JButton("Insert");
    this.btAdd.setFont(new Font("Verdana", Font.PLAIN, 20));
    this.btAdd.setBackground(Color.BLACK);
    this.btAdd.setForeground(Color.WHITE);
    this.btAtualizar = new JButton("Update");
    this.btAtualizar.setFont(new Font("Verdana", Font.PLAIN, 20));
    this.btAtualizar.setBackground(Color.BLACK);
    this.btAtualizar.setForeground(Color.WHITE);
    this.btDelete = new JButton("Delete");
    this.btDelete.setFont(new Font("Verdana", Font.PLAIN, 20));
    this.btDelete.setBackground(Color.BLACK);
    this.btDelete.setForeground(Color.WHITE);

    this.modelo.addColumn("Matrícula");
    this.modelo.addColumn("Nome");
    this.modelo.addColumn("Curso");
    this.modelo.addColumn("Período");

    this.tabela.getColumnModel().getColumn(0).setPreferredWidth(20);
    this.tabela.getColumnModel().getColumn(1).setPreferredWidth(30);
    this.tabela.getColumnModel().getColumn(2).setPreferredWidth(50);
    this.tabela.getColumnModel().getColumn(3).setPreferredWidth(20);

    this.academicos = new ArrayList<>();

    this.academicos.add(new Academico("123", "Fredson", "Sistemas de Informação", 3));
    this.academicos.add(new Academico("234", "Vieira", "Ciência da Computação", 5));
    this.academicos.add(new Academico("345", "Costa", "Engenharia da Computação", 7));

    for (Academico a : this.academicos) {
        this.modelo.addRow(new Object[]{a.getMatricula(), a.getNome(), a.getCurso(), a.getPeriodo()});
    }

    this.painel.add(BorderLayout.NORTH, new JScrollPane(this.tabela));
    this.painel.add(BorderLayout.SOUTH, painelGrid);
    this.painelGrid.add(btAdd);
    this.painelGrid.add(btAtualizar);
    this.painelGrid.add(btDelete);

    this.btDelete.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int dialog = JOptionPane.YES_NO_OPTION;

            int selRow = tabela.getSelectedRow();
            if (selRow != -1) {
                int resultado = JOptionPane.showConfirmDialog(null, "Deseja realmente excluir essa linha?", "Confirmação", dialog);

                if (resultado == 0) {
                    modelo.removeRow(selRow);
                    JOptionPane.showMessageDialog(null, "Registro excluído com sucesso!" + "\nTotal de registros existentes: " + modelo.getRowCount());
                }

            }
        }
    }
    );

    this.btAdd.addActionListener(this);

    this.pack();

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.setVisible(true);
}

public static void main(String[] args) {
    new Frame(novoAcademico);
}

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btAdd) {

        frameTemporario = new FrameTemp();
        frameTemporario.setVisible(true);

    }
}

public static void addAcademico(Academico academico) {
    academico = frameTemporario.getAcademico();

    ArrayList<Academico> lista = new ArrayList<>();

    lista.add(new Academico(academico.getMatricula(), academico.getNome(), academico.getCurso(), academico.getPeriodo()));

    for (Academico a : lista) {
        System.out.println("Lista: " + lista.size());
        modelo.addRow(new Object[]{a.getMatricula(), a.getNome(), a.getCurso(), a.getPeriodo()});
        System.out.println(a.getMatricula() + "\n" + a.getNome() + "\n" + a.getCurso() + "\n" + a.getPeriodo());
    }

}

}
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.jdesktop.swingx.prompt.PromptSupport;

/**
 *
 * @author rafaelcarlos
 */
public class FrameTemp extends JFrame implements ActionListener {

private String title = "Adicionar novo";
private ArrayList<Academico> academicos;
private static Academico academico;
private JTextField tfMatricula, tfNome, tfCurso, tfPeriodo;
private JButton btConfirmar;

public FrameTemp() {
    this.setTitle(title);
    Container c = getContentPane();

    c.setLayout(new BorderLayout());

    Container c2 = new JPanel();
    c2.setLayout(new GridLayout(1, 4));
    academico = new Academico();
    academicos = new ArrayList<Academico>();

    this.btConfirmar = new JButton("Confirmar");
    this.tfMatricula = new JTextField();
    this.tfMatricula.setToolTipText("Insira sua matrícula aqui");
    PromptSupport.setPrompt("Matrícula", tfMatricula);
    PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, tfMatricula);
    PromptSupport.setFontStyle(Font.BOLD, tfMatricula);

    this.tfNome = new JTextField();
    this.tfNome.setToolTipText("Insira seu nome aqui");
    PromptSupport.setPrompt("Nome", tfNome);
    PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, tfNome);
    PromptSupport.setFontStyle(Font.BOLD, tfNome);

    this.tfCurso = new JTextField();
    this.tfCurso.setToolTipText("Insira seu curso aqui");
    PromptSupport.setPrompt("Curso", tfCurso);
    PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, tfCurso);
    PromptSupport.setFontStyle(Font.BOLD, tfCurso);

    this.tfPeriodo = new JTextField();
    this.tfPeriodo.setToolTipText("Insira seu período aqui");
    PromptSupport.setPrompt("Período", tfPeriodo);
    PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, tfPeriodo);
    PromptSupport.setFontStyle(Font.BOLD, tfPeriodo);

    btConfirmar.addActionListener(this);
    c2.add(tfMatricula);
    c2.add(tfNome);
    c2.add(tfCurso);
    c2.add(tfPeriodo);

    c.add(btConfirmar);

    c.add(BorderLayout.NORTH, c2);
    c.add(BorderLayout.SOUTH, btConfirmar);

    this.setVisible(true);
    this.setSize(500, 300);
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}

//Metodo que você vai usar para recuperar os dados na outra classe
public static Academico getAcademico() {
    return FrameTemp.academico;
}

@Override
public void actionPerformed(ActionEvent e) {

    this.academico.setMatricula(tfMatricula.getText());
    this.academico.setNome(tfNome.getText());
    this.academico.setCurso(tfCurso.getText());
    this.academico.setPeriodo(Integer.parseInt(tfPeriodo.getText()));
    ;
    Frame.addAcademico(academico);
    this.dispose();
}

}