将这个label作为参数传入另一个类的构造函数里
classname myclass=new classname(this.label);

解决方案 »

  1.   

    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);
      }
    }