java 中同一个包中调用另一个类中的方法

qiuzigame qiuzigame 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package txttest;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import txttest.sendTxt;
import java.awt.Button;

public class TxtTest {

public JFrame frame;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TxtTest window = new TxtTest();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the application.
*/
public TxtTest() {
initialize();
}

/**
* Initialize the contents of the frame.
*/
public void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);

JTextArea textArea = new JTextArea();
textArea.setBounds(0, 0, 434, 195);
frame.getContentPane().add(textArea);
textArea.append("TESTONE");

JButton btnNewButton = new JButton("New button");
btnNewButton.setBounds(10, 218, 93, 23);
frame.getContentPane().add(btnNewButton);

Button button = new Button("button1");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

JButton Button2 = new JButton("button2");
Button2.setBounds(120, 218, 93, 23);
frame.getContentPane().add(Button2);
frame.repaint();
}


});
button.setBounds(259, 218, 76, 23);
frame.getContentPane().add(button);


btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {

textArea.append("TESTTWO");
sendTxt cbt = new sendTxt();
cbt.createbutton();

}
});



}
}
---------------------------------------------------------------------------
package txttest;

import java.awt.Button;

import txttest.TxtTest;

public class sendTxt {

public static void main(String args[]) {

}
public void createbutton(){

Button button = new Button("button");
button.setBounds(120, 218, 93, 23);
TxtTest bt = new TxtTest();
bt.frame.getContentPane().add(button);
bt.frame.repaint();

}
public void sendtext(){
//想在textarea中输入写内容

}
}
---------------------------------------------------------
在sendtxt中的createbutton()不能显示按钮
想在txttest中的textarea中输入写内容改如何,谢谢
...全文
评论
收藏 已收藏
分享
返回顶部
qiuzigame
Java 51,407 成员 86,137 内容