파일에서 초기 채우기 중 일부를 가져 오는 화면 (JFrame
)이 있습니다. 그러나 파일이 어떤 이유로 든 부재 중이거나 잘못 채워지면 많은 필드가 편집 불가능으로 차단되고 사용자는 설정 버튼을 클릭해야만 다른 JFrame
화면이 생성됩니다. 그런 다음 사용자가 파일을 올바르게 업데이트하면 원본 화면에 새 파일 데이터가 다시 채워지 길 원합니 까?java JFrame 업데이트가 다른 JFrame을 수정합니다.
그래서 자바 클래스 "설정"을 호출하는 설정 버튼에 대한 작업 수신기가 있습니다. "설정"데이터베이스/파일 업데이트를 활성화하는 "완료"버튼을 가지고 성공적인 업데이트/
공용 클래스 설정 JFrame의 확장 설정에 대한 원래의 프레임
btnSettings.setText("Settings");
btnSettings.setFont(font4);
btnSettings.setBounds(new Rectangle(15, 515, 140, 40));
btnSettings.setToolTipText("Default Settings");
btnSettings.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
settingsPerformed();
}
}) ;
private void settingsPerformed() {
JFrame settings = new Settings();
settings.setVisible(true);
}
한 다음 새 클래스를 해제합니다 의 ActionListener {
private.....
public Settings() {
this.getContentPane().setLayout(null);
this.setSize(new Dimension(450, 340));
this.setTitle("Default Settings");
this.setBackground(new Color(255, 247, 214));
this.setResizable(true);
this.setFont(font1);
pnlSettingsData.setBounds(new Rectangle(10, 10, 405, 285));
pnlSettingsData.setBorder(BorderFactory.createLineBorder(Color.blue, 1));
pnlSettingsData.setName("Settings");
pnlSettingsData.setLayout(null);
btnDone.setText("Done");
btnDone.setFont(font3);
btnDone.setBounds(new Rectangle(100, 250, 73, 20));
btnDone.setToolTipText("Click when ready for updating");
btnDone.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
doneActionPerformed(evt);
setVisible(false) ;
}
});
this.getContentPane().add(pnlSettingsData, null);
setDefaultCloseOperation(HIDE_ON_CLOSE);
setLocation(150,200);
//pack();
setVisible(true);
}
private void doneActionPerformed(ActionEvent evt) {
// include here the data base updates
}
public void actionPerformed(ActionEvent e) {
}
} 당신은 할 수
체크 아웃
@GuillaumePolet +1 그게 내가 제안하려고했던 것이다. –
예제에서, 두 번째 프레임은 첫 번째 프레임을 차단하지 않을 것이다. 이것은 JDialog의 역할이다. [How to use Dialogs] (http : // docs. oracle.com/javase/tutorial/uiswing/components/dialog.html) 자세한 내용은 – MadProgrammer