在Netbeans中创建一个新的ArrayList

时间:2016-01-27 11:35:03

标签: java netbeans arraylist

我是public ActionResult AuditReportList(int stnAssureAuditId) { //get the data for the list var people = new List<People.Models.Person>(Peopledb.People); var reports = new List<StnAssureAuditReport>(db.StnAssureAuditReports); var units = new List<People.Models.Unit>(Peopledb.Units); var auditUnits = new List<StnAssureUnit>(db.StnAssureUnits).Where(x => x.StnAssureAuditId == stnAssureAuditId); var auditReportList = from u in auditUnits join r in reports on u.UnitId equals r.UnitId into ur from a in ur.DefaultIfEmpty() select new { CarriedOut = (a == null ? String.Empty : a.CarriedOut.ToLongDateString()), StnAssureAuditReportId = (a == null ? 0 : a.StnAssureAuditReportId), UnitId = a.UnitId, Complete = (a == null ? false : true), StnCommId = a.StnCommId, WatchCommId = a.WatchCommId }; var auditUnitsList = from u in auditReportList join r in units on u.UnitId equals r.UnitId select new { UnitId = u.UnitId, UnitName = r.UnitName, CarriedOut = u.CarriedOut, StnAssureAuditReportId = u.StnAssureAuditReportId, Complete = u.Complete, StnCommId = u.StnCommId, WatchCommId = u.WatchCommId }; var reportStnComm = (from c in auditUnitsList join d in people on c.StnCommId equals d.PersonId select new ReportStnComm { StnAssureAuditReportId = c.StnAssureAuditReportId, StnComm = d.FirstName + " " + d.LastName, WatchCommId = c.WatchCommId, UnitName = c.UnitName, CarriedOut = c.CarriedOut, UnitId = c.UnitId, Complete = c.Complete, }).ToList(); var reportList = (from h in reportStnComm join f in people on h.WatchCommId equals f.PersonId select new StnAssureReportList { CarriedOut = h.CarriedOut, StnAssureAuditReportId = h.StnAssureAuditReportId, StnComm = h.StnComm, UnitName = h.UnitName, WatchComm = f.FirstName + " " + f.LastName, UnitId = h.UnitId, Complete = h.Complete, }).OrderBy(x => x.UnitName).ToList(); var viewModel = reportList.Select(t => new AuditReportListViewModel { CarriedOut = t.CarriedOut, StnAssureAuditReportId = t.StnAssureAuditReportId, StnComm = t.StnComm, UnitName = t.UnitName, WatchComm = t.WatchComm, Complete = t.Complete }); return View("AuditReportList", viewModel); } 编程的新手,请尽量保持简单。

所以,现在我在同一个项目中有3个java文件:mainframe.java,edit.java和add.java。

在大型机窗口中,您有2个按钮,可以进入编辑和添加窗口。在添加窗口中,您可以在文本字段中输入文本,然后按一个按钮将其添加到Netbeans中,我这样做了:

ArrayList

按钮:

public static void main(String args[]) {

    List<String> Hey = new ArrayList<String>();
}

接下来,在编辑窗口中,我有private void btnFortsattActionPerformed(java.awt.event.ActionEvent evt) { //The variable name of the text field is "txfCreate" String text = txfCreate.getText(); Hey.add(text); //The problem here is that Netbeans cannot find "Hey" symbol } 来显示JList的内容。我不知道如何编码:(

1 个答案:

答案 0 :(得分:1)

public class My {

List<String> Hey;

public static void main(String args[]) {
    Hey = new ArrayList<String>();
}

private void btnFortsattActionPerformed(java.awt.event.ActionEvent evt) {
    //The variable name of the text field is "txfCreate"

    String text = txfCreate.getText();
    Hey.add(text);  //The problem here is that Netbeans cannot find "Hey" symbol 
}

}