|
04.07.2006, 11:46
#33829631
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
|
|
Участник
Сообщения: 207
Рейтинг:
0
/ 0
|
|
|
|
Поставил пакет j2sdk-1_4_2_12-nb-5_0. Netbeans говрит, что javagently нет.
Подскожите, что я делаю не правильно, может не в той среде. Спасибо!
Вот полный пример из книги
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146.
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import javagently.*;
class ConverterGUI extends Frame {
/* The Converter Program by J M Bishop Dec 1998
* --------------------- Display version July 1999
* GUI version July 1999
* updated August 2000
* Keeps the exchange rates from one currency into
* many others and enables currency exchanges to be
* estimated.
*
* Illustrates the use of a customised GUI
* and managed sequences of events
*/
ConverterGUI () throws IOException {
DataHandler data = new DataHandler ();
data.initialize();
data.readIn();
}
class DataHandler extends Frame
implements ActionListener, ItemListener {
Hashtable table = new Hashtable();
// read in each line of data and store in
// the hash table with country as key
Choice fromChoice, toChoice;
boolean fromSelected, toSelected;
TextField amountField;
TextArea resultField;
String toCountry, fromCountry;
Button goButton;
void initialize () {
Panel p = new Panel ( new BorderLayout());
// left hand side panel
Panel q = new Panel();
q.add ("North", new Label ("From"));
fromChoice = new Choice();
fromChoice.addItemListener ( this );
q.add("Center",fromChoice);
p.add ("West", q);
// right hand side panel
q = new Panel();
q.add ("North", new Label ("To"));
toChoice = new Choice();
toChoice.addItemListener ( this );
q.add("Center",toChoice);
p.add ("East",q);
// Centre panel
q = new Panel( new BorderLayout());
Panel r = new Panel();
r.add( new Label("Amount"));
amountField = new TextField("1000 ");
amountField.addActionListener( this );
r.add(amountField);
q.add("North",r);
resultField = new TextArea( 8 , 20 );
q.add ("Center",resultField);
resultField.append("First select the countries\n");
goButton = new Button ("Convert");
goButton.addActionListener( this );
q.add("South",goButton);
p.add("Center",q);
add(p);
setTitle("Currency Converter");
setSize( 610 , 300 );
addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit( 0 );
}
});
}
public void actionPerformed (ActionEvent e) {
int amount = 1000 ;
if (e.getSource() == amountField)
amount = ( int ) Integer.parseInt(amountField.getText());
else
if (e.getSource() == goButton) {
if (fromSelected && toSelected)
transaction(amount);
else
resultField.append("First select the countries\n");
}
}
public void itemStateChanged(ItemEvent e) {
String s = (String) e.getItem();
if (e.getItemSelectable() == fromChoice) {
fromSelected = true;
fromCountry = s;
}
else {
toSelected = true;
toCountry = s;
}
}
void transaction ( int amount) {
Rates fromRate = (Rates) table.get(fromCountry);
Rates toRate = (Rates) table.get(toCountry);
resultField.append(amount+" "+fromRate.country+" "+
fromRate.currency+
"\n in "+toRate.country+" "+toRate.currency+"\n was "+
Stream.format(amount/fromRate.conversion*
toRate.conversion, 10 , 3 )+"\n\n");
fromSelected = false;
toSelected = false;
}
void readIn() throws IOException {
Stream fin = new Stream("Rates.dat", Stream.READ);
Rates rate;
try {
for ( int i = 0 ; ; i++) {
rate = new Rates();
rate.setRate(fin);
table.put(rate.country, rate);
toChoice.addItem(rate.country);
fromChoice.addItem(rate.country);
}
}
catch (EOFException e) {}
fromSelected = false;
toSelected = false;
setVisible(true);
}
}
public static void main(String[] args) throws IOException {
new ConverterGUI();
}
}
|
|
|