[実現したいこと]
追加ボタンを押すと、別ウィンドウが表示される。(実装済み)
そのウィンドウにあるテキストボックスに入力すると、テキストファイルが更新される。(実装済み)
そのテキストボックスを、再度読み込みプルダウンに表示される項目を更新される。
(未実装)
[使用言語]
java
[開発環境]
elipse
[アルゴリズム]
決まった方式で記載されている文字列から、決まった部分を取り出し、
プルダウンに表示
[参考サイト]
http://www.javadrive.jp/tutorial/jcombobox/index12.html
if(e.getSource() == update_btn) { String value = JOptionPane.showInputDialog(this, "料理名,追加食材:色(任意の数)"); if (value == null){ //ansLabel.setText("取消されました"); System.out.println("取消されました"); }else{ File file = new File("cook.txt"); FileWriter filewriter = null; try { filewriter = new FileWriter(file,true); BufferedWriter bw = new BufferedWriter(filewriter); PrintWriter pw = new PrintWriter(bw); pw.println(value); model.addElement(value); pw.close(); //dispose(); } catch (IOException e1) { // TODO 自動生成された catch ブロック e1.printStackTrace(); } //BufferedWriter bw = new BufferedWriter(filewriter); //PrintWriter pw = new PrintWriter(bw); //pw.println(value); //pw.close(); } JOptionPane.showMessageDialog(this, "再起動してください"); try{ System.out.println("Debug 0"); File file = new File("cook.txt"); FileReader filereader = new FileReader(file); BufferedReader line = new BufferedReader(filereader); int ch,count = 0; String LineName; String[] cook_data = new String[100]; while((LineName = line.readLine()) != null){ System.out.println(++count + ":"+LineName); cook_data[count] = LineName; System.out.println(count + ":"+ cook_data[count]); String[] cook_menu = LineName.split(",",0); cook_menu2[count] = cook_menu[0]; System.out.println(count + ":"+ cook_menu2[count]); System.out.println("Debug A"); } model = new DefaultComboBoxModel(cook_menu2); comboBox = new JComboBox(model); comboBox.addActionListener(this); filereader.close(); System.out.println("Debug B"); }catch(FileNotFoundException e1){ System.out.println(e1); }catch(IOException e1){ System.out.println(e1); } }
あなたの回答
tips
プレビュー