开发者

java item listener

开发者 https://www.devze.com 2023-01-28 09:43 出处:网络
i need help regarding the save menu item i have in my menu bar. i have set the code to private void smActionPerformed(java.awt.event.ActionEvent evt) {

i need help regarding the save menu item i have in my menu bar. i have set the code to

private void smActionPerformed(java.awt.event.ActionEvent evt) {


}

but i am unsure what needs to go inbetween the brackets? The gui is a form where poeple fill in there medical record e.g combo box "mr/mrs" textfield "medical problems" etc and when they click file save i would like the user to get a save box (like save as box in word) and the information to be saved in a txt file.

P.S. would it be possi开发者_StackOverflowble to have the "file type" set to save as a txt file as default.


Use JFileChooser#showSaveDialog() to ask the enduser to select a File.

JFileChooser fileChooser = new JFileChooser();
if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
    File file = fileChooser.getSelectedFile();
    // ...
} else {
    // User pressed cancel.
}


Maybe looking at this could help you. I don't fully understand what you need.

http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JFileChooser.html http://download.oracle.com/javase/tutorial/uiswing/components/filechooser.html

0

精彩评论

暂无评论...
验证码 换一张
取 消