다른 클래스의 JFrame을 추가하는 데 문제가 있습니다. 런타임시 JFrame을 초기화하고 생성합니다.자바 다른 클래스의 JFrame에 JPanel 추가하기
public static void main(String[] args) throws IOException {
Testing exc = new Testing();
exc.MessagingGUI();
Update.Server();
Scanner input = new Scanner(System.in);
String some_text = input.nextLine();
exc.AddPanel();
}
public void MessagingGUI() throws IOException {
JPanel welcome = new JPanel();
JLabel title = new JLabel("Stuff");
welcome.add(title);
tab.add("Home", welcome);
pane.add(tab);
Messaging.setTitle("Messaging");
Messaging.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Messaging.setContentPane(pane);
Messaging.setVisible(true);
Messaging.pack();
System.out.println("Done");
}
그리고 다른 클래스에서 실행됩니다.
public class Update {
public static void Server() {
System.out.println("Hello");
Testing exc =new Testing();
exc.AddPanel();
}
}
는 지금은 업데이트 클래스는 JFrame의에 액세스 할 수 없습니다하지만 난 이유를 모르기 때문에 그것의 것을 알고있다. AddPanel 메서드가 아니기 때문에 텍스트를 입력하면 AddPanel 메서드를 실행할 수 있기 때문에 작동합니다. 그래서 누군가가 어떻게 그리고 왜 Update 클래스가 JFrame을 편집 할 수 없는지 설명 할 수 있습니다. 감사합니다.
Google에서 도와 드릴 수있는 충분한 코드를 게시하지 않았습니다. 아마도'Testing'에있는 AddPanel 메소드를 게시 할 수 있습니까? – ControlAltDel