0
我已經創建了3個班TourAgency類,addTourAgency JDialog類的和addGuide JDialog類的我如何得到已經從一個JDialog類創建要在
TourAgency類
public class TourAgency
{
...
public TourAgency() {
this("Not set", "Not set");
}
public TourAgency(String inAgencyName, String inAgencyLocation)
{
setAgencyName(inAgencyName);
setAgencyLocation(inAgencyLocation);
}
另一JDialog類的使用對象
addTourAgency類(在其中創建機構代碼)
public class addTAJD extends JDialog{
...
private TourAgency ta1;
okBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
String name = nameTF.getText().trim();
String location = locationTF.getText().trim();
ta1 = new TourAgency(name, location);
...
setVisible(false);
JOptionPane.showMessageDialog(null, ta1.getAgencyName() + " is created");
}
});
addGuide類(代碼部分檢查機構是否缺少或不)
public class AddNGuideJD extends JDialog{
private JLabel name, idNumber, salary, extra;
private JTextField nameTF, idNumberTF, salaryTF, extraTF;
private JButton okBtn, resetBtn, cancelBtn;
private Guide guide;
private TourAgency ta1;
okBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
if(ta1 != null)
{
...
}
else
{
JOptionPane.showMessageDialog(null, "Please add a Tour Agency to countinue");
}
}
});
所以我的問題是,當我在addTourAgency類創建的旅行社和我從addGuide類點擊按鈕,爲什麼總是彈出消息說,不創建一個機構?(( JOptionPane.showMessageDialog(null,「請添加一個Tour代理到countinue」);)。我錯過了什麼?我如何使用我已經創建的對象?
感謝您的建議。有用! –