時遇到問題只是與訪問另一個類中的方法有關的一個簡單問題。 我知道這聽起來很簡單,但無論我看什麼都可以爲我回答..所以在這裏。在訪問方法
這是一類。(只留在相關位,因爲大多數的其他的東西只是格式化並通過各地值。)
public class ContactManager extends JFrame{
public void getData()throws FileNotFoundException{
...
...
private class thehandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
if (event.getSource() == viewButton && selectedIndex != -1){
ViewContact view = new ViewContact();
view.pack();
view.setVisible(true);
public class ViewContact extends JFrame {
...
...
private class viewhandler implements ActionListener {
public void actionPerformed(ActionEvent event){
if (event.getSource() == updateButton){
getData(); //this method i want to use thats in the contact manager window is what im having issues with.
}
我知道的語法是錯誤的訪問方法在另一個班級,我只是想表明我正在努力做什麼。我無法創建聯繫人管理器類的另一個實例,因爲我已經在使用它。:S至少我認爲這是問題所在。 我希望我已經留下了足夠的相關信息,並提前感謝您的幫助。
爲什麼你不能創建你可以創建ContactManager的實例作爲下面的答案。 –
,因爲ContactManager已經初始化,我想從另一個類更新該實例。 – user968366