eclipse JOptionPane导入不进去,未解决

今天在写socke聊天程序时,发现JOptionPane导入不进去,查阅了一下,把问题解决了

先打开eclipse->procket->properties
在这里插入图片描述 找到图示中的Deprecated and restricted API
将其中相关的改为Ignore就可以啦
如图中所示

非常抱歉,我的回答有误。JOptionPane不能自动关闭。如果需要实现自动关闭的弹框,可以使用JDialog类和Timer类来实现。 具体实现方式如下: 1. 创建一个JDialog对象,并设置其大小、位置、模式等属性。 2. 在JDialog中添加需要显示的内容,例如JLabel、JButton等组件。 3. 创建一个Timer对象,并使用它来控制JDialog的自动关闭。 4. 在Timer的ActionListener中,关闭JDialog并停止Timer。 下面是一个示例代码,实现了一个3秒自动关闭的弹框: ``` import javax.swing.*; import java.awt.*; import java.awt.event.*; public class AutoCloseDialog extends JDialog { private Timer timer; public AutoCloseDialog(JFrame parent, String message) { super(parent, true); JLabel label = new JLabel(message); JButton button = new JButton("关闭"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); timer.stop(); } }); JPanel panel = new JPanel(); panel.add(label); panel.add(button); getContentPane().add(panel); pack(); setLocationRelativeTo(parent); setResizable(false); setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); timer = new Timer(3000, new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); timer.stop(); } }); timer.start(); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("显示弹框"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AutoCloseDialog dialog = new AutoCloseDialog(frame, "3秒后自动关闭"); dialog.setVisible(true); } }); frame.getContentPane().add(button, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } } ``` 上面的代码中,AutoCloseDialog类继承自JDialog。在构造函数中,设置了JDialog的属性、添加了需要显示的组件,并创建了一个Timer对象来控制自动关闭。在main()方法中,创建了一个JFrame和一个按钮,点击按钮时会弹出自动关闭的弹框。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值