這是給我錯誤的代碼:
private void btnLLamada1ActionPerformed(java.awt.event.ActionEvent evt) {
minutos = Integer.parseInt(JOptionPane.showInputDialog(null, "numero de minutos"));
String[] lista = {"Local", "Internacional", "Celular"};
JComboBox optionList = new JComboBox(lista);
optionList.setSelectedIndex(0);
tp = JOptionPane.showMessageDialog(null, optionList, "Que tipo de llamada va a usar",
JOptionPane.QUESTION_MESSAGE);
}
uj5u.com熱心網友回復:
JOptionPane.showMessageDialog(...)不回傳任何東西,因此它回傳void。并且沒有任何東西 ( void) 不能轉換為字串。你要使用的方法showInputDialog。如需靈感,請查看(docs.oracle.com/javase/tutorial/uiswing/components/ ...。
一個簡短的可執行黑客來顯示對話框:
import java.awt.*;
import javax.swing.*;
public class Test {
void initGui() {
int minutos = Integer.parseInt(JOptionPane.showInputDialog(null, "Numero de minutos"));
System.out.println("Numero de minutos: " minutos);
String[] lista = { "Local", "Internacional", "Celular" };
JComboBox<String> optionList = new JComboBox<String>(lista);
optionList.setSelectedIndex(0);
String tipo = JOptionPane.showInputDialog(null, optionList, "Que tipo de llamada va a usar", JOptionPane.QUESTION_MESSAGE);
System.out.println("tipo de llamada: " tipo);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Test().initGui();
}
});
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/473166.html
上一篇:將CSV檔案加載到JTable
下一篇:不重復上一個亂數的亂數
