java销毁前一个窗体_JAVA怎样去销毁一个标签

/**Tochangethistemplate,chooseTools|Templates*andopenthetemplateintheeditor.*/packageFrame;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava...

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package Frame;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.Timer;

/**

*

* @author daniel

*/

public class Demo extends JFrame {

JLabel lal_1, lal_2;

private int count = 0;

Timer timer;

public Demo() {

setLayout(null);

lal_1 = new JLabel("JAVA is fun");

lal_2 = new JLabel("JAVA is powerful");

lal_1.setSize(100, 100);

lal_2.setSize(100, 100);

addMouseListener(new MouseAdapter() {

public void mousePressed(MouseEvent e) {

timer = new Timer(1000, new TimerListener());

timer.start();

}

public void mouseReleased(MouseEvent e) {

timer.stop();

lal_2.setVisible(false);

lal_1.setVisible(false);

}

});

// 创建窗体

this.setTitle("按下鼠标不动信息交替出现..松开消失");

this.setSize(400, 400);

this.setLocationRelativeTo(null);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setVisible(true);

}

class TimerListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

if ((count % 2) == 0) {

lal_2.setVisible(false);

getContentPane().add(lal_1);

lal_1.setLocation(100, 100);

lal_1.setVisible(true);

} else {

lal_1.setVisible(false);

getContentPane().add(lal_2);

lal_2.setLocation(250, 100);

lal_2.setVisible(true);

}

count += 1;

}

}

}

我想让点击鼠标时候...2个标签轮流出现...放开时候就不见了..

但对标签设置了setvisable 但其实还是在那 ...这样一直运行下去很霸占内存

问下有没方法让显示lal_1的内容时候lal_2不是不可见..而是被销毁了..

等下一秒lal_2出现的时候lal_1就销毁了...

希望有人解答...谢谢...

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值