java JTextField編輯框自動獲取焦點光標

		jf.addWindowListener(new WindowAdapter() {
			
			public void windowOpened( WindowEvent e ){
				in.requestFocus();				//獲取焦點
		    }
			
			public void windowClosing(WindowEvent e) {
				int result = JOptionPane.showConfirmDialog(null, "是否要退出?", "退出確認", JOptionPane.YES_NO_OPTION,
						JOptionPane.QUESTION_MESSAGE);
				if (result == JOptionPane.YES_OPTION)
					System.exit(0);
			}
		});

jf是Jframe對象,in是JTextField對象

 

		// 當窗口關閉時,需要釋放串口資源。
		this.addWindowListener(new WindowAdapter() {
			
			public void windowOpened( WindowEvent e ){
				in.requestFocus();				//獲取焦點
		    }
			
			public void windowClosing(WindowEvent arg0) {
				if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(
						FileEntry.this, "是否要退出?", "警告",
						JOptionPane.YES_NO_OPTION)) {
					System.out.println("system closed");
					System.exit(0);
				}
			}
		});

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章