当前位置: 代码迷 >> Eclipse >> [新手送分]JAVA中JLabel中的字怎么改变
  详细解决方案

[新手送分]JAVA中JLabel中的字怎么改变

热度:85   发布时间:2016-04-23 11:57:48.0
[新手送分]JAVA中JLabel中的字如何改变?
Java code
import javax.swing.*;import java.awt.*;import javax.swing.event.*;import java.awt.event.*;public class Ziti extends JFrame implements ActionListener{    JPanel rongqi,mianban1,mianban2;    JLabel biaoqian1,biaoqian2;    JButton anniu1;        public Ziti() {        super("字体设置");        anniu1=new JButton("按钮");        biaoqian1=new JLabel("请选择字体");        biaoqian2=new JLabel("请选择大小");        rongqi= new JPanel();        rongqi.add(biaoqian1);        rongqi.add(anniu1);        rongqi.add(biaoqian2);        this.setContentPane(rongqi);        this.setLocationRelativeTo(null);        setVisible(true);        setSize(250,200);        setDefaultCloseOperation(Ziti.EXIT_ON_CLOSE);    }    public static void main(String args[]){        new Ziti();    }    public void actionPerformed(ActionEvent ae){        if (ae.getSource()==anniu1){            biaoqian1.setText("hello");        }    }}


按按钮后liaoqian1的内容不变 为啥捏?

------解决方案--------------------
没有下面这个
Java code
anniu1.addActionListener(this);
  相关解决方案