Я организовал мой примерный проект для отработки MVC паттернов. Пакет модели Я сохранил класс «Student», представление модели Я сохранил JFrame
с именем «ExampleView», контроллер Я сохранил класс «ExampleController».
В JFrame
«ExampleView» у меня есть button(btnGetAllInfo)
и таблица (tblGetAll).
Это мой исходный код для "ExampleView"
package View;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JTable;
public class ExampleView extends JFrame {
private JPanel contentPane;
private JTable tblGetAllStudentInfo;
private JButton btnGetAllInformation;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ExampleView frame = new ExampleView();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ExampleView() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
this.contentPane = new JPanel();
this.contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(this.contentPane);
this.contentPane.setLayout(null);
this.btnGetAllInformation = new JButton("Get all information");
this.btnGetAllInformation.setBounds(159, 11, 128, 23);
this.contentPane.add(btnGetAllInformation);
this.tblGetAllStudentInfo = new JTable();
this.tblGetAllStudentInfo.setBounds(24, 52, 384, 180);
this.contentPane.add(this.tblGetAllStudentInfo);
}
public JPanel getContentPane() {
return contentPane;
}
public void setContentPane(JPanel contentPane) {
this.contentPane = contentPane;
}
public JTable getTblGetAllStudentInfo() {
return tblGetAllStudentInfo;
}
public void setTblGetAllStudentInfo(JTable tblGetAllStudentInfo) {
this.tblGetAllStudentInfo = tblGetAllStudentInfo;
}
public JButton getBtnGetAllInformation() {
return btnGetAllInformation;
}
public void setBtnGetAllInformation(JButton btnGetAllInformation) {
this.btnGetAllInformation = btnGetAllInformation;
}
}
Когда я запускаю JFrame
«ExampleView» без getBtnGetAllInfo()
и getTblGetAllStudentInfo()
методов, я получаю следующий результат
И соответствующий результат с getBtnGetAllInfo()
и getTblGetAllStudentInfo()
методами, я получил этот результат ниже
Может кто-нибудь объяснить мне, почему, когда у меня есть методы get (), set () для кнопки и таблицы, как у меня выше, мои кнопка и таблица не отображаются?