Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import static java.lang.System.currentTimeMillis;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.Vector;
- import javax.swing.JButton;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextArea;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author sss
- */
- public class AddPanel extends JPanel{
- public static final int HEIGHT = 500;
- public static final int WIDTH = 600;
- private JButton add;
- private JButton text1;
- private JButton text2;
- private JButton text3;
- private JLabel label;
- private Text123 textField;
- private JPanel addPanel;
- private JLabel label2;
- private String username;
- private String text;
- public AddPanel(String username){
- this.username = username;
- add = new AddButton();
- text1 = new TextButton1();
- text2 = new TextButton2();
- text3 = new TextButton3();
- label = new JLabel("Wybierz text");
- label2 = new JLabel();
- textField = new Text123();
- addPanel = this;
- textField.setLineWrap(true);
- textField.setWrapStyleWord(true);
- setLayout(new FlowLayout());
- setPreferredSize(new Dimension(WIDTH, HEIGHT));
- add(text1);
- add(text2);
- add(text3);
- add(label);
- add(textField);
- add(add);
- add(label2);
- }
- class Text123 extends JTextArea implements KeyListener{
- private int dane;
- private int iloscznakow;
- private Vector<Integer> znaki=new Vector<Integer>();
- private Vector znak = new Vector();
- private double start;
- private Vector wynik = new Vector();
- private String userInput = "";
- private final String secret = "secret";
- public Text123() {
- super(10,50);
- addKeyListener(this);
- dane =0;
- }
- @Override
- public void keyPressed(KeyEvent evt) {
- if(dane==0){start=currentTimeMillis();dane=1;}
- wynik.add(currentTimeMillis()-start);
- znaki.add((int)evt.getKeyChar());
- znak.add('p');
- dane++;
- }
- @Override
- public void keyReleased(KeyEvent evt) {
- if(dane==0){start=currentTimeMillis();dane=1;}
- wynik.add(currentTimeMillis()-start);
- znaki.add((int)evt.getKeyChar());
- znak.add('r');
- dane++;
- }
- @Override
- public void keyTyped(KeyEvent evt) {
- /* if(dane==0){start=currentTimeMillis();dane=1;}
- wynik[dane]=currentTimeMillis()-start;
- znaki[dane]=evt.getKeyChar();
- dane++;
- //znaki[iloscznakow]=evt.getKeyChar();
- */
- }
- public void zapisz() throws FileNotFoundException{
- Date dt = new Date();
- SimpleDateFormat form = new SimpleDateFormat("yyyy.MM.dd H");
- PrintWriter fileWriter = new PrintWriter(username + "/" + text + " " +form.format(dt) + ".txt");
- int size = wynik.size();
- for(int i=0; i<size-1;i++){
- fileWriter.println(znaki.get(i) + " " + wynik.get(i) + " " + znak.get(i));
- }
- fileWriter.close();
- }
- }
- class AddButton extends JButton implements ActionListener {
- AddButton() {
- super("Add");
- addActionListener(this);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- textField.zapisz();
- } catch (Exception ee) {
- }
- }
- }
- class TextButton1 extends JButton implements ActionListener {
- TextButton1() {
- super("Text 1");
- addActionListener(this);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- text = "text1";
- label.setText("<html>Mary Brewster Hazelton (November 23, 1868 – September 13, 1953) was an American <br>"
- +" portrait painter. She attended the School of the Museum of Fine Arts, Boston, <br>"
- +" where she was later an instructor. Among the awards that she won, Hazelton was <br>"
- +" the first woman to win an award open to both men and women in the United States <br>"
- +" when she won the Hallgarten Prize from the National Academy of Design in 1896. <br>"
- +" Her portrait paintings are in the collections of the Massachusetts State House, <br>"
- +" Harvard University, Peabody Essex Museum, and Wellesley Historical Society. <br>"
- +" Among the professional organizations that Hazelton was affiliated with, she was <br>"
- +" a founding member of the Wellesley Society of Artists and a charter member of The <br>"
- +" Guild of Boston Artists. She lived her adult life with her sisters in the <br>"
- +" Hazelton family home in Wellesley, Massachusetts."
- +" </html>");
- }
- }
- class TextButton2 extends JButton implements ActionListener {
- TextButton2() {
- super("Text 2");
- addActionListener(this);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- text="text2";
- label.setText("<html><center>Alan Mathison Turing – angielski matematyk, kryptolog, twórca pojęcia maszyny Turinga<br>"
- +" i jeden z twórców informatyki. Jego ojciec, Julius Turing, był pracownikiem indyjskiej<br>"
- +" służby cywilnej i razem z żoną Ethel Turing mieszkał w Chatrapur niedaleko Madrasu w<br>"
- +" południowych Indiach. Tam też Alan Turing został poczęty jesienią 1911. Ponieważ<br>"
- +" rodzice przyszłego matematyka chcieli, aby dziecko urodziło się w Anglii,<br>"
- +" opuścili Indie i 23 czerwca 1912 w Londynie urodził się Alan Mathison Turing. <br>"
- +"Jego ojciec niedługo po jego narodzinach wrócił do Indii, natomiast matka<br>"
- +" wyjechała piętnaście miesięcy później, w połowie września 1913,<br>"
- +" pozostawiając Alana pod opieką nianiek. W 1926 roku Alan Turing rozpoczął <br>"
- +" naukę w Scherbone School w Dorset. Od samego początku nauki wykazywał duże zdolności w dziedzinie <br>"
- + " nauk ścisłych, jednak źle czuł się w szkole, która kształciła przyszłą<br>"
- +" kadrę przywódczą Imperium Brytyjskiego. </html>");
- }
- }
- class TextButton3 extends JButton implements ActionListener {
- TextButton3() {
- super("Text 3");
- addActionListener(this);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- text = "text3";
- label.setText("<html><center>Londyn miasto w południowo-wschodniej części Wielkiej Brytanii, <br>"
- +"stolica tego państwa, a także stolica Anglii.<br>"
- +"Położony nad Tamizą, jest największym miastem Europy po Moskwie i<br>"
- +" Stambule, a większym od Paryża; jest także największym miastem Unii<br>"
- +" Europejskiej i jednym z większych miast świata zarówno w skali samego<br>"
- +" miasta, jak i aglomeracji. Liczba mieszkańców Londynu<br>"
- +" (w granicach tzw. Wielkiego Londynu) wynosi ok. 8,4 mln (2013 r.)<br>"
- +" na obszarze 1572 km²; cała zaś aglomeracja londyńska, łącznie ze<br>"
- +" wszystkimi przyległymi miejscowościami liczy ok. 13 mln mieszkańców<br>"
- +" (obszar tzw. metropolia). Około 20% mieszkańców pochodzi z Azji, Afryki i Karaibów.<br>"
- +"Współczesny Londyn jest największym centrum finansowym świata (od 2006 przed Nowym Jorkiem).<br>"
- +" Tutaj dokonuje się 30% światowego obrotu walutami i 40% światowego obrotu Euroobligacjami.</html>");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement