用jb怎么在另一个类中控制frame中的一个label的text的实时的变化?多谢 将这个label作为参数传入另一个类的构造函数里classname myclass=new classname(this.label); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Hand extends JFrame{ Knife knife; JButton jButton1 = new JButton(); public static void main(String[] args) { Knife knife = new Knife(); knife.setTitle("Knife"); knife.setLocation(100, 80); knife.setSize(200, 80); knife.setVisible(true); Hand hand = new Hand(knife); //创建 Hand 时把 Knife 的句柄传过去 hand.setTitle("Hand"); hand.setLocation(200, 90); hand.setSize(200, 80); hand.setVisible(true); } public Hand() { } public Hand(Knife knife){ this.knife = knife; jButton1.setText("Button"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); this.getContentPane().add(jButton1, BorderLayout.NORTH); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } void jButton1_actionPerformed(ActionEvent e) { knife.jLabel1.setText(knife.jLabel1.getText() + "Ctrl "); }}class Knife extends JFrame { JLabel jLabel1 = new JLabel(); public Knife() { this.getContentPane().add(jLabel1, BorderLayout.CENTER); }} 怎样学习JAVA? 请问,如何让一个java程序只能运行一次 手写一个set工具包 关于打包的问题。。 为什么不往文件里写啊?? 两个JAVA连接数据库的小问题,请各位高手帮忙~~~~~ 请问:在WinME下如何设置环境变量? javax.script是干嘛的? 关于重载的问题,超急,在线等!!!! 请问:实体BEAN和会话BEAN的区别 help me 为什么用RMIC编译类,老是找不到该类啊
import java.awt.*;
import java.awt.event.*;public class Hand extends JFrame{
Knife knife;
JButton jButton1 = new JButton(); public static void main(String[] args) {
Knife knife = new Knife();
knife.setTitle("Knife");
knife.setLocation(100, 80);
knife.setSize(200, 80);
knife.setVisible(true); Hand hand = new Hand(knife); //创建 Hand 时把 Knife 的句柄传过去
hand.setTitle("Hand");
hand.setLocation(200, 90);
hand.setSize(200, 80);
hand.setVisible(true);
} public Hand() {
}
public Hand(Knife knife){
this.knife = knife;
jButton1.setText("Button");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
this.getContentPane().add(jButton1, BorderLayout.NORTH);
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
} void jButton1_actionPerformed(ActionEvent e) {
knife.jLabel1.setText(knife.jLabel1.getText() + "Ctrl ");
}
}class Knife extends JFrame {
JLabel jLabel1 = new JLabel(); public Knife() {
this.getContentPane().add(jLabel1, BorderLayout.CENTER);
}
}