我是相当新的Java,我只是寻求一点帮助
我试图创建一个程序,允许用户输入gui的名称和>>百货商店的位置.它允许这样但是程序不等待>细节被输入它只是初始化Gui类并且继续进行>处理这是将输入Gui的细节添加到数组列表中.但尚未输入>详细信息,因此它创建了一个空值,因为它已经超前了.
那么如何让它停下来等到输入值然后提交?
这是代码的Gui组件:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class guiDepartment extends JFrame
{
private String depName;
private String depLocation;
private static Department newDepartment;
private JTextField departmentDetails1;
private JTextField departmentDetails2;
private JTextField departmentDetails3;
private Employee worksInInTheDepartment;
public guiDepartment()
{
System.out.println("bob the builder ");
JButton submit;
JButton b1;
JFrame frame = new JFrame();
departmentDetails1 = new JTextField(10);
departmentDetails2 = new JTextField(10);
departmentDetails3 = new JTextField(10);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(320, 75));
frame.setTitle("Department Details");
frame.setLayout(new FlowLayout());
frame.add(new JLabel("Please enter department …Run Code Online (Sandbox Code Playgroud) 我只是想输出一个先前创建的ArrayList来序列化它以备将来存储.
但是当我这样做时,我得到了runTime错误"notSerialisableException:Department.
他们是一种序列化arrayList的特殊方式吗?
有人能告诉我为什么我可能会收到此错误.
这是代码:
import java.awt.*;
import java.util.*;
import java.io.*;
import java.io.Serializable;
public class tester1ArrayListObjectSave
{
private ArrayList <Department> allDeps = new ArrayList<Department>();
private int choice = 0;
private String name;
private String loc;
Department theDepartment;
Scanner scan;
public static void main(String[] args)
{
new tester1ArrayListObjectSave();
}
public tester1ArrayListObjectSave()
{
scan = new Scanner(System.in);
options();
}
public void options()
{
System.out.println("wadya wanna do");
System.out.println("1. create a new department");
System.out.println("2. read from text file");
System.out.println("4. save it to system as …Run Code Online (Sandbox Code Playgroud) 各位程序员再次问好.
所以我正在创建一个程序,允许用户指定他们想要的保险类型作为保险单的一部分.
由于它们只有4种类型的封面可供选择,我想使用一套或散列集来跟踪提供给用户的封面类型.
问题是,似乎没有摆脱重复,它正在将它视为arraylist,当我打印出集合的内容时,我得到重复,这不应该发生在集合中.
这是我用来将创建的保险类型对象传递给保险单类的代码.在实例化之后.
CoverType theInsuranceType = new CoverType("Fire",250);
theInsurancePolicy.includeCover(theInsuranceType);
Run Code Online (Sandbox Code Playgroud)
这是我在保险单类中使用的代码,用于跟踪用户已采取的保险类型.
import java.util.*;
// Class: InsurancePolicy
// Purpose: To represent a particular customer's insurance agreement
public class InsurancePolicy {
//ArrayList<Product> orderList = new ArrayList<Product>();
private static int totalPolicyCost;
private static String name = null;
private static int price = 0;
private int amount = 0;
private static int total = 0, claims = 0;
private static Set<CoverType> TheCoverType = new HashSet<CoverType>();
public static boolean includeCover(CoverType which)
{
TheCoverType.add(which);
System.out.println(which.getName()+" …Run Code Online (Sandbox Code Playgroud)