Hur skapar man en länkad lista med hjälp av två klasser?
Länkad lista?
1 svar · 481 visningar · startad av coolish
Menar du nåt i stil med detta:
package list;
import java.util.*;
public class CountryList {
private LinkedHashMap hm;
public CountryList() {
hm = new LinkedHashMap();
hm.put("", "Select your Country");
hm.put("af", "Afghanistan");
hm.put("al", "Albania");
hm.put("dz", "Algeria");
hm.put("as", "American Samoa");
hm.put("ad", "Andorra");
hm.put("ao", "Angola");
hm.put("ai", "Anguilla");
hm.put("aq", "Antarctica");
hm.put("ag", "Antigua and Barbuda");
hm.put("ar", "Argentina");
hm.put("am", "Armenia");
hm.put("aw", "Aruba");
hm.put("au", "Australia");
hm.put("at", "Austria");
hm.put("az", "Azerbaidjan");
hm.put("bs", "Bahamas");
hm.put("bh", "Bahrain");
hm.put("Ba", "Bangladesh");
hm.put("bb", "Barbados");
hm.put("by", "Belarus");
hm.put("be", "Belgium");
hm.put("bz", "Belize");
hm.put("bj", "Benin");
hm.put("bm", "Bermuda");
hm.put("bt", "Bhutan");
hm.put("bo", "Bolivia");
hm.put("ba", "Bosnia-Herzegovina");
hm.put("bw", "Botswana");
hm.put("bv", "Bouvet Island");
hm.put("br", "Brazil");
hm.put("io", "British Indian Ocean Territory");
hm.put("bn", "Brunei Darussalam");
hm.put("bg", "Bulgaria");
hm.put("bf", "Burkina Faso");
hm.put("bi", "Burundi");
hm.put("kh", "Cambodia, Kingdom of");
hm.put("cm", "Cameroon");
hm.put("ca", "Canada");
hm.put("cv", "Cape Verde");
hm.put("ky", "Cayman Islands");
hm.put("cf", "Central African Republic");
hm.put("td", "Chad");
hm.put("cl", "Chile");
hm.put("cn", "China");
hm.put("cx", "Christmas Island");
hm.put("cc", "Cocos (Keeling) Islands");
hm.put("co", "Colombia");
hm.put("km", "Comoros");
hm.put("cg", "Congo");
hm.put("cd", "Congo, The Democratic Republic of the");
hm.put("ck", "Cook Islands");
hm.put("cr", "Costa Rica");
hm.put("hr", "Croatia");
hm.put("cu", "Cuba");
hm.put("cy", "Cyprus");
hm.put("cz", "Czech Republic");
hm.put("dk", "Denmark");
hm.put("dj", "Djibouti");
hm.put("dm", "Dominica");
hm.put("do", "Dominican Republic");
hm.put("tp", "East Timor");
hm.put("ec", "Ecuador");
hm.put("eg", "Egypt");
hm.put("sv", "El Salvador");
hm.put("gq", "Equatorial Guinea");
hm.put("er", "Eritrea");
hm.put("ee", "Estonia");
hm.put("et", "Ethiopia");
hm.put("fk", "Falkland Islands");
hm.put("fo", "Faroe Islands");
hm.put("fj", "Fiji");
hm.put("fi", "Finland");
hm.put("fr", "France");
hm.put("gf", "French Guyana");
hm.put("tf", "French Southern Territories");
hm.put("ga", "Gabon");
hm.put("gm", "Gambia");
hm.put("ge", "Georgia");
hm.put("de", "Germany");
hm.put("gh", "Ghana");
hm.put("gi", "Gibraltar");
hm.put("gr", "Greece");
hm.put("gl", "Greenland");
hm.put("gd", "Grenada");
hm.put("gp", "Guadeloupe (French)");
hm.put("gu", "Guam (USA)");
hm.put("gt", "Guatemala");
hm.put("gn", "Guinea");
hm.put("gw", "Guinea Bissau");
hm.put("gy", "Guyana");
hm.put("ht", "Haiti");
hm.put("hm", "Heard and McDonald Islands");
hm.put("va", "Holy See (Vatican City State)");
hm.put("hn", "Honduras");
hm.put("hk", "Hong Kong");
hm.put("hu", "Hungary");
hm.put("is", "Iceland");
hm.put("in", "India");
hm.put("id", "Indonesia");
hm.put("ir", "Iran");
hm.put("iq", "Iraq");
hm.put("ie", "Ireland");
hm.put("il", "Israel");
hm.put("it", "Italy");
hm.put("ci", "Ivory Coast (Cote D'Ivoire)");
hm.put("jm", "Jamaica");
hm.put("jp", "Japan");
hm.put("jo", "Jordan");
hm.put("kz", "Kazakhstan");
hm.put("ke", "Kenya");
hm.put("ki", "Kiribati");
hm.put("kw", "Kuwait");
hm.put("kg", "Kyrgyz Republic (Kyrgyzstan)");
hm.put("la", "Laos");
hm.put("lv", "Latvia");
hm.put("lb", "Lebanon");
hm.put("ls", "Lesotho");
hm.put("lr", "Liberia");
hm.put("ly", "Libya");
hm.put("li", "Liechtenstein");
hm.put("lt", "Lithuania");
hm.put("lu", "Luxembourg");
hm.put("mo", "Macau");
hm.put("mk", "Macedonia");
hm.put("mg", "Madagascar");
hm.put("mw", "Malawi");
hm.put("my", "Malaysia");
hm.put("mv", "Maldives");
hm.put("ml", "Mali");
hm.put("mh", "Marshall Islands");
hm.put("mq", "Martinique (French)");
hm.put("mr", "Mauritania");
hm.put("mu", "Mauritius");
hm.put("yt", "Mayotte");
hm.put("mx", "Mexico");
hm.put("fm", "Micronesia");
hm.put("md", "Moldavia");
hm.put("mc", "Monaco");
hm.put("mn", "Mongolia");
hm.put("ms", "Montserrat");
hm.put("ma", "Morocco");
hm.put("mz", "Mozambique");
hm.put("mm", "Myanmar");
hm.put("na", "Namibia");
hm.put("nr", "Nauru");
hm.put("np", "Nepal");
hm.put("nl", "Netherlands");
hm.put("an", "Netherlands Antilles");
hm.put("nc", "New Caledonia (French)");
hm.put("nz", "New Zealand");
hm.put("ni", "Nicaragua");
hm.put("ne", "Niger");
hm.put("ng", "Nigeria");
hm.put("nu", "Niue");
hm.put("nf", "Norfolk Island");
hm.put("kp", "North Korea");
hm.put("mp", "Northern Mariana Islands");
hm.put("no", "Norway");
hm.put("om", "Oman");
hm.put("pk", "Pakistan");
hm.put("pw", "Palau");
hm.put("pa", "Panama");
hm.put("pg", "Papua New Guinea");
hm.put("py", "Paraguay");
hm.put("pe", "Peru");
hm.put("ph", "Philippines");
hm.put("pn", "Pitcairn Island");
hm.put("pl", "Poland");
hm.put("pf", "Polynesia (French)");
hm.put("pt", "Portugal");
hm.put("pr", "Puerto Rico");
hm.put("qa", "Qatar");
hm.put("re", "Reunion (French)");
hm.put("ro", "Romania");
hm.put("ru", "Russian Federation");
hm.put("rw", "Rwanda");
hm.put("gs", "S. Georgia & S. Sandwich Isls.");
hm.put("sh", "Saint Helena");
hm.put("kn", "Saint Kitts & Nevis Anguilla");
hm.put("lc", "Saint Lucia");
hm.put("pm", "Saint Pierre and Miquelon");
hm.put("st", "Saint Tome (Sao Tome) and Principe");
hm.put("vc", "Saint Vincent & Grenadines");
hm.put("ws", "Samoa");
hm.put("sm", "San Marino");
hm.put("sa", "Saudi Arabia");
hm.put("sn", "Senegal");
hm.put("sc", "Seychelles");
hm.put("sl", "Sierra Leone");
hm.put("sg", "Singapore");
hm.put("sk", "Slovak Republic");
hm.put("si", "Slovenia");
hm.put("sb", "Solomon Islands");
hm.put("so", "Somalia");
hm.put("za", "South Africa");
hm.put("kr", "South Korea");
hm.put("es", "Spain");
hm.put("lk", "Sri Lanka");
hm.put("sd", "Sudan");
hm.put("sr", "Suriname");
hm.put("sj", "Svalbard and Jan Mayen Islands");
hm.put("sz", "Swaziland");
hm.put("se", "Sweden");
hm.put("ch", "Switzerland");
hm.put("sy", "Syria");
hm.put("tj", "Tadjikistan");
hm.put("tw", "Taiwan");
hm.put("tz", "Tanzania");
hm.put("th", "Thailand");
hm.put("tg", "Togo");
hm.put("tk", "Tokelau");
hm.put("to", "Tonga");
hm.put("tt", "Trinidad and Tobago");
hm.put("tn", "Tunisia");
hm.put("tr", "Turkey");
hm.put("tm", "Turkmenistan");
hm.put("tc", "Turks and Caicos Islands");
hm.put("tv", "Tuvalu");
hm.put("um", "USA Minor Outlying Islands");
hm.put("ug", "Uganda");
hm.put("ua", "Ukraine");
hm.put("ae", "United Arab Emirates");
hm.put("uk", "United Kingdom");
hm.put("uy", "Uruguay");
hm.put("uz", "Uzbekistan");
hm.put("vu", "Vanuatu");
hm.put("ve", "Venezuela");
hm.put("vn", "Vietnam");
hm.put("vg", "Virgin Islands (British)");
hm.put("vi", "Virgin Islands (USA)");
hm.put("wf", "Wallis and Futuna Islands");
hm.put("eh", "Western Sahara");
hm.put("ye", "Yemen");
hm.put("yu", "Yugoslavia");
hm.put("zr", "Zaire");
hm.put("zm", "Zambia");
hm.put("zw", "Zimbabwe");
}
public String getCountry(String selected) {
Iterator it=hm.keySet().iterator();
String ret = "";
while(it.hasNext()) {
String key = (String)it.next();
if (selected.equals(key)){
ret += "<option value=\"" + key + "\" selected>" + hm.get(key) + "</option>";
}
else{
ret += "<option value=\"" + key + "\">" + hm.get(key) + "</option>";
}
}
return ret;
}
}
Senare:
list.CountryList cl = new list.CountryList();
cl.getCountry(form.getCountry())
Andreas