如何保存和打开文件顺序Java GUI

如何保存和打开文件顺序Java GUI,java,Java,所以我的问题是我的最后一个按钮。我不知道如何用GUI保存和打开一个文件,我可以得到全部信息,但如果能得到帮助,我将不胜感激。“用户应该能够单击标签为Total的按钮,该按钮在标签中显示采购总价(总价应包括密歇根州6%的销售税)。另一个按钮允许用户将订单保存到文件。另一个按钮允许用户从文件中打开订单。” 为了节省“此外,在提交保存之前,程序应询问用户是否确实要保存文件。他们应该能够从这个弹出对话框中指出是否要保存它。如果用户表示不想保存文件,则不保存订单。如果他们表示确实要保存该文件,则会使用新顺

所以我的问题是我的最后一个按钮。我不知道如何用GUI保存和打开一个文件,我可以得到全部信息,但如果能得到帮助,我将不胜感激。“用户应该能够单击标签为Total的按钮,该按钮在标签中显示采购总价(总价应包括密歇根州6%的销售税)。另一个按钮允许用户将订单保存到文件。另一个按钮允许用户从文件中打开订单。”

为了节省“此外,在提交保存之前,程序应询问用户是否确实要保存文件。他们应该能够从这个弹出对话框中指出是否要保存它。如果用户表示不想保存文件,则不保存订单。如果他们表示确实要保存该文件,则会使用新顺序创建(或覆盖)该文件。订单文件的名称为order.txt。“

对于“打开”,您的程序应该能够打开和保存文件。当程序打开订单时,应将所有GUI组件设置为反映文件中订单的适当值。如果order.txt文件尚不存在(即,订单从未保存),则会显示一个对话框,告知用户“没有保存的订单可用”,并且主GUI保持不变。”


使用JFileChooser打开/保存文件。

发布作业并说“我不知道如何。。。“。具体展示你为完成任务所做的努力。概述您认为需要执行的步骤,以及您遇到的问题。让我们知道您遇到了哪些错误,以及您为修复这些错误所做的努力。还要确保非常具体地描述我们需要知道的任何细节,比如“文件顺序”是什么。这是你的家庭作业所特有的,因此我们甚至不能在没有更多细节的情况下谈论它。确保你的问题非常具体。你说你不知道如何用GUI打开文件,但GUI不打开文件。GUI为用户提供了一个漂亮的界面,可以显示文件中的数据,但不能打开它们。您可以使用文件读取器或扫描仪之类的东西来读取文件。请解释一下使用GUI打开文件的意思。这是一个很好的地方,可以确保你的问题是有答案的和高质量的。我确实发布了我尝试过的东西,但我不知道该去哪里。这并不是说我什么都没做。我写了整件事,这只是最后两个步骤,我有麻烦,就像我不明白“你不会得到帮助,你必须提出你的家庭作业,并说我不知道如何”。如果我知道我不会发布这个,我真的不知道该怎么做。不管怎么说,文件顺序是香草的,没有坚果和樱桃焦糖斯蒂芬,我不是想攻击你。我想让你在你的问题上得到帮助,但我需要告诉你你需要做什么才能尽快做到这一点。我是说你不能只说“我不知道怎么做”,也不能更深入地了解你不知道怎么做。您已经包含了很多细节,但其中许多只是您的程序的要求。这些要求并不是很严格。最好是你能把老师的话变成程序员的话。例如,请参阅我的下一条评论。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;

public class IcecreamOrdersGUI extends JFrame
{
   private IcecreamFlavorPanel icecreamFlavors;  // iceCreamFlavor panel
   private NutsPanel nuts; //nuts panel
   private SyrupPanel syrup; //syrup panel
   private ScoopsPanel scoops; //scoops panel
   private JPanel buttonPanel; //To hold the buttons
   private JButton saveButton; // To save the order
   private JButton openButton; // to open the order
   private JButton totalButton; //To figure out the total
   private final double TAX_RATE = 0.06; // Sales tax rate

  /**
      Constructor
   */

  public IcecreamOrdersGUI()
  {
         //Display a title.
         setTitle("Icecream Orders");

         //Specify an action for the close button.
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

         //Create a BorderLayout manager.
         setLayout(new BorderLayout());
         // Create the custom panels.
         icecreamFlavors = new IcecreamFlavorPanel();
         scoops = new ScoopsPanel();
         nuts = new NutsPanel();
         syrup = new SyrupPanel();

         // Create the button panel.
         buildButtonPanel();

         //Add the components to the content pane.
         add(icecreamFlavors, BorderLayout.WEST);
         add(scoops, BorderLayout.CENTER);
         add(nuts, BorderLayout.NORTH);
         add(syrup, BorderLayout.EAST);
         add(buttonPanel, BorderLayout.SOUTH);

     //Pack the contents of the window and display it.
     pack();
     setVisible(true);
}

private void buildButtonPanel()
{
   //Create a panel for the buttons.
   buttonPanel = new JPanel();

   //Create the buttons.
   saveButton = new JButton("Save Order");
   openButton = new JButton("Open Order");
   totalButton = new JButton("Total");

   //Register the action listeners.
   saveButton.addActionListener(new saveButtonListener());
   openButton.addActionListener(new openButtonListener());
   totalButton.addActionListener(new totalButtonListener());

   //Add the buttons to the button panel.
   buttonPanel.add(saveButton);
   buttonPanel.add(openButton);
   buttonPanel.add(totalButton);
} 
private class totalButtonListener implements ActionListener
{
   public void actionPerformed(ActionEvent e)
   {
      //Variables to hold the subtotal, tax, and total
      double subtotal, tax, total;

      //Calculate the subtotal.
      subtotal = icecreamFlavor.getIcecreamFlavorCost() + nuts.getNutsCost() + syrup.getSyrupCost() + scoops.getScoopsCost();

 // Calculate the sales tax
 tax = subtotal * TAX_RATE;

 // Calcuate the total
 total = subtotal + tax;

 //Create a DecimalFormat object to format output.
 DecimalFormat dollar = new DecimalFormat("0.00");

 //Display the charges.
 JOptionPane.showMessageDialog(null, "Subtotal: $" + 
              dollar.format(subtotal) + "\n" + 
              "Tax: $" + dollar.format(tax) + "\n" +
              "Total: $" + dollar.format(total));
}
}

/**
Private  inner class that handles the event when
the user clicks the Exit button.
*/

private class ExitButtonListener implements ActionListener 
{
public void actionPerformed(ActionEvent e)
{
     System.exit(0);
}

}

/** 
main method
*/
public static void main(String[] args)
   {
     new OrderCalculatorGUI();
    }
}