从另一个私有类调用arrayList

时间:2016-05-08 14:14:38

标签: java swing arraylist actionevent

我正试图在gui中显示一个arraylist。但是我遇到了一些麻烦。我需要检查我的游戏是否合法,如果它不合法,那么它调用getProblems来显示arraylist。我试图直接在GUI类中调用getProblems,但是它会将数组显示为空。 (因为它没有检查它是否合法)。我也尝试调用isLegal然后调用getProblems,但你不能在<%@page import="oracle.net.aso.i"%> <%@ page import="java.io.*,java.util.*,javax.mail.*,java.sql.*"%> <%@ page import="javax.mail.internet.*,javax.activation.*"%> <%@ page import="javax.servlet.http.*,javax.servlet.*" %> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <%! Connection con; Statement st; ResultSet rs; %> <% Class.forName("oracle.jdbc.OracleDriver"); con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","rahul","odeya"); st=con.createStatement(); rs=st.executeQuery("select email from register"); %> <% String host="", user="", pass=""; int i=0; String id[] = new String[100]; while(rs.next()) { id[i] = rs.getString(1); } host ="smtp.gmail.com"; user ="ocrsindore@gmail.com"; pass ="odeya"; String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; String from ="ocrsindore@gmail.com"; String subject =request.getParameter("subject"); String messageText =request.getParameter("message"); boolean sessionDebug = true; Properties props = System.getProperties(); props.put("mail.host", host); props.put("mail.transport.protocol.", "smtp"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.", "true"); props.put("mail.smtp.port", "465"); props.put("mail.smtp.socketFactory.fallback", "false"); props.put("mail.smtp.socketFactory.class", SSL_FACTORY); Session mailSession = Session.getDefaultInstance(props, null); mailSession.setDebug(sessionDebug); Message msg = new MimeMessage(mailSession); msg.setFrom(new InternetAddress(from)); InternetAddress[] address = {new InternetAddress(id[i])}; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(subject); msg.setContent(messageText, "text/html"); Transport transport = mailSession.getTransport("smtp"); transport.connect(host,from,pass); try { transport.sendMessage(msg, msg.getAllRecipients()); out.println("message successfully sended"); } catch (Exception err) { out.println("message not successfully sended"); } transport.close(); %> <jsp:include page="adminis.html"/> 中执行此操作。关于我如何调用它的任何提示?

GetProblems类

JOptionPane

IsLegal Class

 protected List < String > getProblems() {
     return displayOutput;
 }

GUI:

public boolean isLegal() {
  boolean legality;

  if (checkRowConstraints().isEmpty()) {
    legality = true;

  } else {
    getProblems();
    legality = false;

  }
  return legalCheck;
}

以下是GUI结果的实际显示与我想要获得的结果之间的区别。

Actual display of GUI to result and result i'm trying to get

  

发现更多问题:   我需要返回arraylist然后清空它。修正了

1 个答案:

答案 0 :(得分:2)

目前,当您在List内拨打toString()时,会隐含调用puzzle.getProblems()的{​​{1}}方法。所以,而不是获得JOptionPane的内容,这是你想要的,你得到的是List给你的东西。

你不会得到toString()的内容,除非你先重复它。

你可以尝试这样的事情。 (注意,这是未经测试的代码。出于演示目的。)

List

然后您可以输出格式化的String formattedString = ""; //let's iterate over our List and build a formatted string for output for(String element : puzzle.getProblems()) { formattedString += element; }

String