Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.23 KB | None | 0 0
  1. package test;
  2. import java.awt.Dimension;
  3. import java.awt.FlowLayout;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.KeyEvent;
  7. import java.awt.event.KeyListener;
  8. import java.io.FileNotFoundException;
  9. import java.io.PrintWriter;
  10. import static java.lang.System.currentTimeMillis;
  11. import java.text.SimpleDateFormat;
  12. import java.util.Date;
  13. import java.util.Vector;
  14. import javax.swing.JButton;
  15. import javax.swing.JLabel;
  16. import javax.swing.JPanel;
  17. import javax.swing.JTextArea;
  18.  
  19. /*
  20. * To change this license header, choose License Headers in Project Properties.
  21. * To change this template file, choose Tools | Templates
  22. * and open the template in the editor.
  23. */
  24.  
  25. /**
  26. *
  27. * @author sss
  28. */
  29. public class AddPanel extends JPanel{
  30. public static final int HEIGHT = 500;
  31. public static final int WIDTH = 600;
  32. private JButton add;
  33. private JButton text1;
  34. private JButton text2;
  35. private JButton text3;
  36. private JLabel label;
  37. private Text123 textField;
  38. private JPanel addPanel;
  39. private JLabel label2;
  40. private String username;
  41. private String text;
  42.  
  43. public AddPanel(String username){
  44.  
  45. this.username = username;
  46. add = new AddButton();
  47. text1 = new TextButton1();
  48. text2 = new TextButton2();
  49. text3 = new TextButton3();
  50. label = new JLabel("Wybierz text");
  51. label2 = new JLabel();
  52. textField = new Text123();
  53. addPanel = this;
  54. textField.setLineWrap(true);
  55. textField.setWrapStyleWord(true);
  56. setLayout(new FlowLayout());
  57. setPreferredSize(new Dimension(WIDTH, HEIGHT));
  58. add(text1);
  59. add(text2);
  60. add(text3);
  61. add(label);
  62. add(textField);
  63. add(add);
  64. add(label2);
  65. }
  66.  
  67. class Text123 extends JTextArea implements KeyListener{
  68. private int dane;
  69. private int iloscznakow;
  70. private Vector<Integer> znaki=new Vector<Integer>();
  71. private Vector znak = new Vector();
  72. private double start;
  73. private Vector wynik = new Vector();
  74. private String userInput = "";
  75. private final String secret = "secret";
  76.  
  77. public Text123() {
  78. super(10,50);
  79. addKeyListener(this);
  80. dane =0;
  81. }
  82.  
  83. @Override
  84. public void keyPressed(KeyEvent evt) {
  85.  
  86. if(dane==0){start=currentTimeMillis();dane=1;}
  87. wynik.add(currentTimeMillis()-start);
  88. znaki.add((int)evt.getKeyChar());
  89. znak.add('p');
  90. dane++;
  91.  
  92.  
  93. }
  94.  
  95. @Override
  96. public void keyReleased(KeyEvent evt) {
  97. if(dane==0){start=currentTimeMillis();dane=1;}
  98. wynik.add(currentTimeMillis()-start);
  99. znaki.add((int)evt.getKeyChar());
  100. znak.add('r');
  101. dane++;
  102.  
  103.  
  104. }
  105.  
  106. @Override
  107. public void keyTyped(KeyEvent evt) {
  108. /* if(dane==0){start=currentTimeMillis();dane=1;}
  109. wynik[dane]=currentTimeMillis()-start;
  110. znaki[dane]=evt.getKeyChar();
  111. dane++;
  112. //znaki[iloscznakow]=evt.getKeyChar();
  113. */
  114. }
  115.  
  116. public void zapisz() throws FileNotFoundException{
  117. Date dt = new Date();
  118. SimpleDateFormat form = new SimpleDateFormat("yyyy.MM.dd H");
  119. PrintWriter fileWriter = new PrintWriter(username + "/" + text + " " +form.format(dt) + ".txt");
  120.  
  121. int size = wynik.size();
  122. for(int i=0; i<size-1;i++){
  123. fileWriter.println(znaki.get(i) + " " + wynik.get(i) + " " + znak.get(i));
  124. }
  125. fileWriter.close();
  126. }
  127. }
  128.  
  129. class AddButton extends JButton implements ActionListener {
  130.  
  131. AddButton() {
  132. super("Add");
  133. addActionListener(this);
  134. }
  135.  
  136. @Override
  137. public void actionPerformed(ActionEvent e) {
  138. try {
  139. textField.zapisz();
  140. } catch (Exception ee) {
  141. }
  142.  
  143. }
  144.  
  145.  
  146. }
  147. class TextButton1 extends JButton implements ActionListener {
  148.  
  149. TextButton1() {
  150. super("Text 1");
  151. addActionListener(this);
  152. }
  153.  
  154. @Override
  155. public void actionPerformed(ActionEvent e) {
  156. text = "text1";
  157. label.setText("<html>Mary Brewster Hazelton (November 23, 1868 – September 13, 1953) was an American <br>"
  158. +" portrait painter. She attended the School of the Museum of Fine Arts, Boston, <br>"
  159. +" where she was later an instructor. Among the awards that she won, Hazelton was <br>"
  160. +" the first woman to win an award open to both men and women in the United States <br>"
  161. +" when she won the Hallgarten Prize from the National Academy of Design in 1896. <br>"
  162. +" Her portrait paintings are in the collections of the Massachusetts State House, <br>"
  163. +" Harvard University, Peabody Essex Museum, and Wellesley Historical Society. <br>"
  164. +" Among the professional organizations that Hazelton was affiliated with, she was <br>"
  165. +" a founding member of the Wellesley Society of Artists and a charter member of The <br>"
  166. +" Guild of Boston Artists. She lived her adult life with her sisters in the <br>"
  167. +" Hazelton family home in Wellesley, Massachusetts."
  168. +" </html>");
  169. }
  170. }
  171. class TextButton2 extends JButton implements ActionListener {
  172.  
  173. TextButton2() {
  174. super("Text 2");
  175. addActionListener(this);
  176. }
  177.  
  178. @Override
  179. public void actionPerformed(ActionEvent e) {
  180. text="text2";
  181. label.setText("<html><center>Alan Mathison Turing – angielski matematyk, kryptolog, twórca pojęcia maszyny Turinga<br>"
  182. +" i jeden z twórców informatyki. Jego ojciec, Julius Turing, był pracownikiem indyjskiej<br>"
  183. +" służby cywilnej i razem z żoną Ethel Turing mieszkał w Chatrapur niedaleko Madrasu w<br>"
  184. +" południowych Indiach. Tam też Alan Turing został poczęty jesienią 1911. Ponieważ<br>"
  185. +" rodzice przyszłego matematyka chcieli, aby dziecko urodziło się w Anglii,<br>"
  186. +" opuścili Indie i 23 czerwca 1912 w Londynie urodził się Alan Mathison Turing. <br>"
  187. +"Jego ojciec niedługo po jego narodzinach wrócił do Indii, natomiast matka<br>"
  188. +" wyjechała piętnaście miesięcy później, w połowie września 1913,<br>"
  189. +" pozostawiając Alana pod opieką nianiek. W 1926 roku Alan Turing rozpoczął <br>"
  190. +" naukę w Scherbone School w Dorset. Od samego początku nauki wykazywał duże zdolności w dziedzinie <br>"
  191. + " nauk ścisłych, jednak źle czuł się w szkole, która kształciła przyszłą<br>"
  192. +" kadrę przywódczą Imperium Brytyjskiego. </html>");
  193. }
  194. }
  195. class TextButton3 extends JButton implements ActionListener {
  196.  
  197. TextButton3() {
  198. super("Text 3");
  199. addActionListener(this);
  200. }
  201.  
  202. @Override
  203. public void actionPerformed(ActionEvent e) {
  204. text = "text3";
  205. label.setText("<html><center>Londyn miasto w południowo-wschodniej części Wielkiej Brytanii, <br>"
  206. +"stolica tego państwa, a także stolica Anglii.<br>"
  207. +"Położony nad Tamizą, jest największym miastem Europy po Moskwie i<br>"
  208. +" Stambule, a większym od Paryża; jest także największym miastem Unii<br>"
  209. +" Europejskiej i jednym z większych miast świata zarówno w skali samego<br>"
  210. +" miasta, jak i aglomeracji. Liczba mieszkańców Londynu<br>"
  211. +" (w granicach tzw. Wielkiego Londynu) wynosi ok. 8,4 mln (2013 r.)<br>"
  212. +" na obszarze 1572 km²; cała zaś aglomeracja londyńska, łącznie ze<br>"
  213. +" wszystkimi przyległymi miejscowościami liczy ok. 13 mln mieszkańców<br>"
  214. +" (obszar tzw. metropolia). Około 20% mieszkańców pochodzi z Azji, Afryki i Karaibów.<br>"
  215. +"Współczesny Londyn jest największym centrum finansowym świata (od 2006 przed Nowym Jorkiem).<br>"
  216. +" Tutaj dokonuje się 30% światowego obrotu walutami i 40% światowego obrotu Euroobligacjami.</html>");
  217. }
  218. }
  219.  
  220.  
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement