单击此代码后,如何将值传递给JPanel类!
patientFrame
{
patientFrame.add(new pnlPatientInformation());
JButton btnShearch = new JButton("Search");
btnShearch.addActionListe(,,,)
{
pnlPatientInformation pnlx = new pnlPatientInformation()
pnlx.lblID.setText("Value");
}
pnlPatientInformation exetend JPanel()
{
JLabel lblID = new JLabel();
pnlPatientInformation.add(lblID);
}
最佳答案
您确实应该使用一个在两个类之间共享的模型。然后,这将向相关方提供更改通知。
首先看一下:
Understanding Model-View-Controller
Observer Pattern
更多细节。此处的目的是使代码与各种元素的管理脱钩,以使代码在长期内更具灵活性和可重用性。
正确实施将需要一些时间。在短期内。屏幕上显示的面板实例也应该与您尝试更新的面板实例相同...
private pnlPatientInformation patientInformation;
//...
{
patientInformation = new pnlPatientInformation();
patientFrame.add();
JButton btnShearch = new JButton("Search");
btnShearch.addActionListe(,,,)
{
patientInformation.lblID.setText("Value");
}