0
這裏是情況,我有一個醫生記錄數組,其中有屬性,如名字,醫生ID,聯繫電話等。我試圖顯示所有註冊的醫生ID和他們的聯繫號碼在JOptionPane消息對話框中,我希望這發生在我按下按鈕時。它應該顯示爲一個列表。顯示消息對話框中的記錄列表
這可能嗎?我已經嘗試過,但我只設法得到一個記錄顯示,其他記錄都混亂。
謝謝你的時間。
這裏是情況,我有一個醫生記錄數組,其中有屬性,如名字,醫生ID,聯繫電話等。我試圖顯示所有註冊的醫生ID和他們的聯繫號碼在JOptionPane消息對話框中,我希望這發生在我按下按鈕時。它應該顯示爲一個列表。顯示消息對話框中的記錄列表
這可能嗎?我已經嘗試過,但我只設法得到一個記錄顯示,其他記錄都混亂。
謝謝你的時間。
應該straig向前
樣本:
醫生級別
package com.doc;
public class Doctor {
private String name;
private int id;
public Doctor(String name, int id) {
super();
this.name = name;
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
醫生演示
package com.doc;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
public class DoctorDemo {
/**
* @param args
*/
public static void main(String[] args) {
List<Doctor> doctors = new ArrayList<Doctor>();
// populate from database
// im hard coding
doctors.add(new Doctor("Test", 1));
doctors.add(new Doctor("Test2", 2));
doctors.add(new Doctor("Test3", 3));
String message = "\n Doctor records \n ";
for (Doctor doc : doctors) {
message += "\n\n\n" + "Name:" + doc.getName() + "Id:" + doc.getId();
}
JOptionPane.showMessageDialog(null, message);
}
}
這顯示瞭如何在joption消息對話框顯示。
謝謝你做到了。 – 2013-05-07 12:23:37
不客氣。 – Makky 2013-05-07 12:28:14