我有两个班级Game 和班级wampusGUI.在wampusGUI课堂上我有一个在该方法下textarea命名.我试图从课堂上得到结果.但是当我试图从那个班级进入时.在运行良好,也将结果在该类(我只是通过简单的测试来 法),但不追加到.这是我的代码.displayTextAreatextarea1()appendtextareaGamefunctionSystem.out.print()textarea
// Code of wampusGUI class
public class wampusGUI extends javax.swing.JFrame {
/**
* Creates new form wampusGUI
*/
public wampusGUI() {
initComponents();
}
public void textArea1(String text) {
System.out.print(text);
displayTextArea.append(text); // this is not appending to textarea.
}
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new wampusGUI().setVisible(true);
Game g = new Game();
g.testing();
}
});
}
Run Code Online (Sandbox Code Playgroud)
//这是Game类的代码
private wampusGUI gui;
public void testing () {
String welCome=welcome();
gui= new wampusGUI();
gui.textArea1(welCome);
}
Run Code Online (Sandbox Code Playgroud)
在代码中进行此更改
在你的头等舱wampusGUI
public class wampusGUI extends javax.swing.JFrame {
/**
* Creates new form wampusGUI
*/
public wampusGUI() {
initComponents();
}
public void textArea1(String text) {
System.out.print(text);
displayTextArea.append(text); // this is not appending to textarea.
}
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
wampusGUI w=new wampusGUI();
w.setVisible(true);
Game g = new Game(w);
g.testing();
}
});
}
Run Code Online (Sandbox Code Playgroud)
而对于二等游戏
private wampusGUI gui;
//Add Contructor with Parameter
public Game(wampusGUI w){
//put this line of code at the end
gui=w;
}
public void testing () {
String welCome=welcome();
gui.textArea1(welCome);
}
Run Code Online (Sandbox Code Playgroud)
这会工作......
| 归档时间: |
|
| 查看次数: |
6412 次 |
| 最近记录: |