我在显示JOptionPane.showMessageDialog上的Jtextfield时遇到了问题。 它显示类似于 名称:javax swing.Jtextfield [,0,19,195x20,invalid.layout ......... 节:javax swing.Jtextfield [,0,19,195x20,invalid.layout .. ....... 下面是代码:在JOptionPane.showMessageDialog上显示Jtextfield
package quiz_application;
import java.awt.Component;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
/**
*
* @author Christian
*/
public class Quiz_application {
public static void main(String[] args){
/**
* Input
*/
JTextField fullName = new JTextField();
JTextField section = new JTextField();
Object[] message = {
"Name:", fullName,
"Section:", section,
};
Component parent = null;
int option = JOptionPane.showConfirmDialog(parent, message,"User Information", JOptionPane.OK_CANCEL_OPTION);
if (option == JOptionPane.OK_OPTION)
{
String value1 = fullName.getText();
String value2 = section.getText();
}
String outputStr="Name: "+ fullName+"\n"
+"Section: "+ section;
JOptionPane.showMessageDialog(null, outputStr,"User Information",JOptionPane.INFORMATION_MESSAGE);
}
}
' “名称: ”+全名+“ \ n”'它应该是'“名称:”+ fullName.getText()+“\ n”' –
请改善标题中的编排 –