我在顯示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」' –
請改善標題中的編排 –