java如何导入jframe包,Java:如何将JFrame带到前面?

I am currently waiting for a very important announcement and I have created a simple application to check every 30 minutes whether the announcement was made or not

When the announcement is made, I want a window to pop up and inform me about it. The window is just a simple JFrame that has some text in it.

I have a class called Announcement.

Inside this class I define another class for the frame called Form,

so I have something like this:

class Form{

public Form(){

//create frame and show it

JFrame frame = new JFrame("anouncement");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Container c = frame.getContentPane();

frame.setSize(420, 100);

JLabel l1 = new JLabel("The announcement was just made");

l1.setFont(new Font("Courier New", Font.ITALIC, 20));

c.add(l1);

frame.setLocationRelativeTo(null);

frame.setResizable(false);

frame.setVisible(true);

frame.toFront(); //this thing doesn't work

}

}

public class Announcement{

public static void main(String[] args){

//do the checking every 30 minutes part

}

}

The toFront function doesn't work at all.

What I want it do is, for example: while I'm browsing, I want this window to pop up and set the focus on this window.

So I want it to be in front of all the other windows no matter how many other windows I have already opened.

解决方案

If I understand you correctly, your code has at least two windows -- one the basic program which you call "Form" and the other a window that you wish to "jump out" over the basic window, correct? If so, then don't use a second JFrame, but rather have the "jump-out" window be a JDialog or JOptionPane and make it dependent on the first window.

Please correct me if my assumptions are incorrect.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值