我正在创建一个有助于解决会计账簿问题的应用程序。该应用程序有 12 章。所有章节都包含 15-20 个问题。问题显示在包含各种组合框和格式化文本框的 JPanel 中。假设我解决了一半的问题并想保存,以便下次我可以加载解决了一半的问题。
保存应通过单击菜单栏中的保存来完成。并从菜单栏加载
所有菜单栏和问题表都在工作,但我无法保存任何东西。我正在使用jFilechooser ...
他们有什么办法吗?
如何保存带有填充组合框项目和文本框的面板。他们是否有任何方式知道用户对任何项目进行了任何更改,以便在关闭问题时我可以再次要求先保存然后退出。
提前致谢。
我的一些代码:
private void openBtnMouseClicked(java.awt.event.MouseEvent evt) {
opening();
}
public void opening() {
JFileChooser chooser=new JFileChooser();
int choice=chooser.showOpenDialog(this);
javax.swing.JComboBox[] sourceALE = {aaCombo, baCombo, caCombo, daCombo, eaCombo, faCombo, gaCombo, haCombo, iaCombo, jaCombo, kaCombo,
alCombo, blCombo, clCombo, dlCombo, elCombo, flCombo, glCombo, hlCombo, ilCombo, jlCombo, klCombo,
aeCombo, beCombo, ceCombo, deCombo, eeCombo, feCombo, geCombo, heCombo, ieCombo, jeCombo, keCombo};
javax.swing.JTextField[] sourceP = {aeval1, beval, ceval, deval, eeval, feval, geval, heval, ieval, jeval, keval};
String [] comboboxes={"aaCombo", "baCombo", "caCombo", "daCombo", "eaCombo", "faCombo", "gaCombo", "haCombo", "iaCombo", "jaCombo", "kaCombo","alCombo", "blCombo", "clCombo", "dlCombo", "elCombo", "flCombo", "glCombo", "hlCombo", "ilCombo", "jlCombo","klCombo","aeCombo", "beCombo", "ceCombo", "deCombo", "eeCombo", "feCombo", "geCombo", "heCombo", "ieCombo", "jeCombo", "keCombo"};
if(choice==JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
try {
System.out.println("Hey");
Scanner scanner = new Scanner(new FileReader(file));
while ( scanner.hasNextLine() ){
Scanner scan = new Scanner(scanner.nextLine());
scan.useDelimiter("=");
if ( scan.hasNext() ){
String item=scan.next();
int value=scan.nextInt();
String color=scan.next();
for(int g=0;g<comboboxes.length;g++){
if(item.equals(comboboxes[g])) {
if(value<3)
sourceALE[g].setSelectedIndex(value);
if(color.equals("red"))
sourceALE[g].setForeground(red);
if(color.equals("green"))
sourceALE[g].setForeground(green);
if(color.equals("blah"))
sourceALE[g].setForeground(blah);
}
}
}
scan.close();
}
scanner.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(q1.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void opening() {
JFileChooser chooser=new JFileChooser();
int choice=chooser.showOpenDialog(this);
javax.swing.JComboBox[] sourceALE = {aaCombo, baCombo, caCombo, daCombo, eaCombo, faCombo, gaCombo, haCombo, iaCombo, jaCombo, kaCombo,
alCombo, blCombo, clCombo, dlCombo, elCombo, flCombo, glCombo, hlCombo, ilCombo, jlCombo, klCombo,
aeCombo, beCombo, ceCombo, deCombo, eeCombo, feCombo, geCombo, heCombo, ieCombo, jeCombo, keCombo};
javax.swing.JTextField[] sourceP = {aeval1, beval, ceval, deval, eeval, feval, geval, heval, ieval, jeval, keval};
String [] comboboxes={"aaCombo", "baCombo", "caCombo", "daCombo", "eaCombo", "faCombo", "gaCombo", "haCombo", "iaCombo", "jaCombo", "kaCombo","alCombo", "blCombo", "clCombo", "dlCombo", "elCombo", "flCombo", "glCombo", "hlCombo", "ilCombo", "jlCombo","klCombo","aeCombo", "beCombo", "ceCombo", "deCombo", "eeCombo", "feCombo", "geCombo", "heCombo", "ieCombo", "jeCombo", "keCombo"};
if(choice==JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
try {
System.out.println("Hey");
Scanner scanner = new Scanner(new FileReader(file));
while ( scanner.hasNextLine() ){
Scanner scan = new Scanner(scanner.nextLine());
scan.useDelimiter("=");
if ( scan.hasNext() ){
String item=scan.next();
int value=scan.nextInt();
String color=scan.next();
for(int g=0;g<comboboxes.length;g++){
if(item.equals(comboboxes[g])) {
if(value<3)
sourceALE[g].setSelectedIndex(value);
if(color.equals("red"))
sourceALE[g].setForeground(red);
if(color.equals("green"))
sourceALE[g].setForeground(green);
if(color.equals("blah"))
sourceALE[g].setForeground(blah);
}
}
}
scan.close();
}
scanner.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(q1.class.getName()).log(Level.SEVERE, null, ex);
}
}
System.out.println("OUT");
}
}