How to open a JFrame

本文介绍了一个简单的Java Swing示例,展示了如何使用Action注解来打开一个新的JFrame窗口。通过检查aboutBox实例是否存在来避免重复创建窗口,并将其相对于主窗口进行定位。

How to open a JFrame

@Action public void showAboutBox() { if (aboutBox == null) { JFrame mainFrame = NumberSliderApp.getApplication().getMainFrame(); aboutBox = new NumberSliderAboutBox(mainFrame); aboutBox.setLocationRelativeTo(mainFrame); } NumberSliderApp.getApplication().show(aboutBox); }

/** * This demo showcases how to use Alibaba Cloud's DashScope model for recognition from microphone * audio input to text Type 'q' to finish recording and recognition. */ public class RecognizeSpeechFromMicrophoneUsingFlowable { public static void main(String[] args) { // set exit flags boolean[] shouldExit = {false}; Object exitFlag = new Object(); // Start a new thread to record and recognize new Thread( () -> { try { startRecordingAndRecognition(exitFlag, shouldExit); } catch (Exception e) { e.printStackTrace(); System.exit(0); } }) .start(); // Exit the program waitForExitSignal(exitFlag, shouldExit); } // Wait for exit signal by key press. private static void waitForExitSignal(Object exitFlag, boolean[] shouldExit) { // Create a hidden JFrame to capture key events JFrame frame = new JFrame(); frame.setUndecorated(true); frame.setSize(1, 1); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); System.out.println("Press 'Ctrl+C' to stop recording and recognition..."); frame.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_C) { synchronized (exitFlag) { shouldExit[0] = true; exitFlag.notifyAll(); // 通知录音线程退出 } System.out.println("Exit signal received. Exiting..."); } } }); frame.setVisible(true); } private static void startRecordingAndRecognition(Object exitFlag, boolean[] shouldExit) throws NoApiKeyException { // Create a Flowable<ByteBuffer> for streaming audio data Flowable<ByteBuffer> audioSource = createAudioSourceWithControl(exitFlag, shouldExit); // Create speech Recognizer Recognition recognizer = new Reco
03-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值