fork download
  1. import java.awt.Color;
  2. import java.util.*;
  3. import java.awt.*;
  4.  
  5. /*
  6.  * To change this license header, choose License Headers in Project Properties.
  7.  * To change this template file, choose Tools | Templates
  8.  * and open the template in the editor.
  9.  */
  10. /**
  11.  *
  12.  * @author misiek
  13.  */
  14. public class Nieregularne extends javax.swing.JFrame {
  15.  
  16. /**
  17.   * Creates new form Nieregularne
  18.   */
  19. public Nieregularne() {
  20. initComponents();
  21. //new SerializacjaCzasownik();
  22. dzialaj = new Dzialaj("czasowniki.ser");
  23. jSlider1.setMaximum(dzialaj.size());
  24. jSlider1.setValue(20);
  25. this.aktywuj(false);
  26. }
  27.  
  28. /**
  29.   * This method is called from within the constructor to initialize the form.
  30.   * WARNING: Do NOT modify this code. The content of this method is always
  31.   * regenerated by the Form Editor.
  32.   */
  33. @SuppressWarnings("unchecked")
  34. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  35. private void initComponents() {
  36.  
  37. jButton1 = new javax.swing.JButton();
  38. jLabel1 = new javax.swing.JLabel();
  39. jTextField1 = new javax.swing.JTextField();
  40. jTextField2 = new javax.swing.JTextField();
  41. jTextField3 = new javax.swing.JTextField();
  42. jButton2 = new javax.swing.JButton();
  43. jLabel2 = new javax.swing.JLabel();
  44. jLabel3 = new javax.swing.JLabel();
  45. jLabel4 = new javax.swing.JLabel();
  46. jSlider1 = new javax.swing.JSlider();
  47. jTextField4 = new javax.swing.JTextField();
  48. jMenuBar1 = new javax.swing.JMenuBar();
  49. jMenu1 = new javax.swing.JMenu();
  50. jMenuItem1 = new javax.swing.JMenuItem();
  51.  
  52. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  53. setTitle("Czasowniki nieregularne");
  54.  
  55. jButton1.setFont(new java.awt.Font("Calibri", 0, 24)); // NOI18N
  56. jButton1.setText("Losuj");
  57. jButton1.setMaximumSize(new java.awt.Dimension(120, 39));
  58. jButton1.setMinimumSize(new java.awt.Dimension(120, 39));
  59. jButton1.setPreferredSize(new java.awt.Dimension(120, 39));
  60. jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
  61. public void mouseClicked(java.awt.event.MouseEvent evt) {
  62. jButton1MouseClicked(evt);
  63. }
  64. });
  65.  
  66. jLabel1.setFont(new java.awt.Font("Calibri", 1, 36)); // NOI18N
  67. jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  68. jLabel1.setText("Czasowniki nieregularne!");
  69. jLabel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  70.  
  71. jTextField1.setBackground(new java.awt.Color(204, 204, 204));
  72. jTextField1.setFont(new java.awt.Font("Calibri", 0, 20)); // NOI18N
  73. jTextField1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
  74. public void mouseDragged(java.awt.event.MouseEvent evt) {
  75. jTextField1MouseDragged(evt);
  76. }
  77. public void mouseMoved(java.awt.event.MouseEvent evt) {
  78. jTextField1MouseMoved(evt);
  79. }
  80. });
  81.  
  82. jTextField2.setBackground(new java.awt.Color(204, 204, 204));
  83. jTextField2.setFont(new java.awt.Font("Calibri", 0, 20)); // NOI18N
  84.  
  85. jTextField3.setBackground(new java.awt.Color(204, 204, 204));
  86. jTextField3.setFont(new java.awt.Font("Calibri", 0, 20)); // NOI18N
  87.  
  88. jButton2.setFont(new java.awt.Font("Calibri", 0, 24)); // NOI18N
  89. jButton2.setText("Sprawdź");
  90. jButton2.setEnabled(false);
  91. jButton2.setMaximumSize(new java.awt.Dimension(120, 39));
  92. jButton2.setMinimumSize(new java.awt.Dimension(120, 39));
  93. jButton2.setName(""); // NOI18N
  94. jButton2.setPreferredSize(new java.awt.Dimension(120, 39));
  95. jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
  96. public void mouseClicked(java.awt.event.MouseEvent evt) {
  97. jButton2MouseClicked(evt);
  98. }
  99. });
  100. jButton2.addActionListener(new java.awt.event.ActionListener() {
  101. public void actionPerformed(java.awt.event.ActionEvent evt) {
  102. jButton2ActionPerformed(evt);
  103. }
  104. });
  105. jButton2.addKeyListener(new java.awt.event.KeyAdapter() {
  106. public void keyReleased(java.awt.event.KeyEvent evt) {
  107. jButton2KeyReleased(evt);
  108. }
  109. });
  110.  
  111. jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  112. jLabel2.setText("jLabel2");
  113.  
  114. jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  115. jLabel3.setText("jLabel2");
  116.  
  117. jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  118. jLabel4.setText("jLabel2");
  119.  
  120. jSlider1.setMinimum(1);
  121. jSlider1.setValue(20);
  122. jSlider1.addChangeListener(new javax.swing.event.ChangeListener() {
  123. public void stateChanged(javax.swing.event.ChangeEvent evt) {
  124. jSlider1StateChanged(evt);
  125. }
  126. });
  127. jSlider1.addMouseListener(new java.awt.event.MouseAdapter() {
  128. public void mouseClicked(java.awt.event.MouseEvent evt) {
  129. jSlider1MouseClicked(evt);
  130. }
  131. });
  132.  
  133. jTextField4.setBackground(new java.awt.Color(240, 240, 240));
  134. jTextField4.setHorizontalAlignment(javax.swing.JTextField.CENTER);
  135. jTextField4.setText("20");
  136. jTextField4.addCaretListener(new javax.swing.event.CaretListener() {
  137. public void caretUpdate(javax.swing.event.CaretEvent evt) {
  138. jTextField4CaretUpdate(evt);
  139. }
  140. });
  141. jTextField4.addActionListener(new java.awt.event.ActionListener() {
  142. public void actionPerformed(java.awt.event.ActionEvent evt) {
  143. jTextField4ActionPerformed(evt);
  144. }
  145. });
  146.  
  147. jMenu1.setText("Plik");
  148.  
  149. jMenuItem1.setText("Resetuj statystyki");
  150. jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
  151. public void actionPerformed(java.awt.event.ActionEvent evt) {
  152. jMenuItem1ActionPerformed(evt);
  153. }
  154. });
  155. jMenu1.add(jMenuItem1);
  156.  
  157. jMenuBar1.add(jMenu1);
  158.  
  159. setJMenuBar(jMenuBar1);
  160.  
  161. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  162. getContentPane().setLayout(layout);
  163. layout.setHorizontalGroup(
  164. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  165. .addGroup(layout.createSequentialGroup()
  166. .addContainerGap()
  167. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  168. .addGroup(layout.createSequentialGroup()
  169. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 487, javax.swing.GroupLayout.PREFERRED_SIZE)
  170. .addGap(0, 0, Short.MAX_VALUE))
  171. .addGroup(layout.createSequentialGroup()
  172. .addGap(0, 0, Short.MAX_VALUE)
  173. .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
  174. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  175. .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
  176. .addGroup(layout.createSequentialGroup()
  177. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  178. .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  179. .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE))
  180. .addGap(18, 18, 18)
  181. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  182. .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  183. .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
  184. .addGap(18, 18, 18)
  185. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  186. .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
  187. .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
  188. .addContainerGap())
  189. .addGroup(layout.createSequentialGroup()
  190. .addGap(95, 95, 95)
  191. .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
  192. .addGap(18, 18, 18)
  193. .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
  194. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  195. );
  196. layout.setVerticalGroup(
  197. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  198. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  199. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  200. .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
  201. .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  202. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  203. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
  204. .addGap(2, 2, 2)
  205. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  206. .addComponent(jLabel2)
  207. .addComponent(jLabel3)
  208. .addComponent(jLabel4))
  209. .addGap(2, 2, 2)
  210. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  211. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
  212. .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
  213. .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
  214. .addGap(18, 18, 18)
  215. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  216. .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
  217. .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
  218. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  219. );
  220.  
  221. pack();
  222. }// </editor-fold>
  223.  
  224. private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
  225. // TODO add your handling code here:
  226. if (test == false) {
  227. test = this.nastepny();
  228. } else {
  229. test = this.losujIndeksy(jSlider1.getValue());
  230. jSlider1.setEnabled(false);
  231. jTextField4.setEnabled(false);
  232. jButton1.setText("Następny");
  233. test = this.nastepny();
  234. this.aktywuj(true);
  235. }
  236. }
  237.  
  238. private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
  239. // TODO add your handling code here:
  240. if(jButton2.isEnabled()){
  241. this.sprawdz();
  242. }
  243. }
  244.  
  245. private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
  246. // TODO add your handling code here:
  247. dzialaj = new Dzialaj("czasowniki2.ser");
  248. }
  249.  
  250. private void jButton2KeyReleased(java.awt.event.KeyEvent evt) {
  251. // TODO add your handling code here:
  252. if(jButton2.isEnabled()){
  253. this.sprawdz();
  254. }
  255. }
  256.  
  257. private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {
  258. // TODO add your handling code here:
  259. jSlider1.setValue(Integer.parseInt(jTextField4.getText()));
  260. }
  261.  
  262. private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {
  263. // TODO add your handling code here:
  264. jTextField4.setText(Integer.toString(jSlider1.getValue()));
  265. losujIndeksy(jSlider1.getValue());
  266. }
  267.  
  268. /**
  269.   * @param args the command line arguments
  270.   */
  271. public static void main(String args[]) {
  272. /* Set the Nimbus look and feel */
  273. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  274. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  275.   * For details see http://d...content-available-to-author-only...e.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  276.   */
  277. try {
  278. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  279. if ("Nimbus".equals(info.getName())) {
  280. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  281. break;
  282. }
  283. }
  284. } catch (ClassNotFoundException ex) {
  285. java.util.logging.Logger.getLogger(Nieregularne.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  286. } catch (InstantiationException ex) {
  287. java.util.logging.Logger.getLogger(Nieregularne.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  288. } catch (IllegalAccessException ex) {
  289. java.util.logging.Logger.getLogger(Nieregularne.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  290. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  291. java.util.logging.Logger.getLogger(Nieregularne.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  292. }
  293. //</editor-fold>
  294.  
  295. /* Create and display the form */
  296. java.awt.EventQueue.invokeLater(new Runnable() {
  297. public void run() {
  298. new Nieregularne().setVisible(true);
  299. }
  300. });
  301. }
  302.  
  303. public void aktywuj(boolean b){
  304. jTextField1.setEnabled(b);
  305. jTextField2.setEnabled(b);
  306. jTextField3.setEnabled(b);
  307. jButton2.setEnabled(b);
  308. }
  309.  
  310. public boolean losujIndeksy(int i) {
  311. indeksy = dzialaj.losujListe(i);
  312. return false;
  313. }
  314.  
  315. public void reset(){
  316. jTextField1.setForeground(Color.BLACK);
  317. jTextField2.setForeground(Color.BLACK);
  318. jTextField3.setForeground(Color.BLACK);
  319. jTextField1.setText("");
  320. jTextField2.setText("");
  321. jTextField3.setText("");
  322. }
  323. /*public class Watek implements Runnable{
  324.   public void run(){
  325.   sprawdz();
  326.   }
  327.   }*/
  328. public boolean nastepny() {
  329. if(jButton2.isEnabled()){
  330. /*Runnable w2 = new Watek();
  331.   Thread watek2 = new Thread(w2);
  332.   watek2.start();*/
  333. sprawdz();
  334. czekaj();
  335. }
  336. index++;
  337. if (indeksy.isEmpty()) {
  338. jLabel1.setText("Koniec");
  339. jButton1.setText("Losuj");
  340. jSlider1.setEnabled(true);
  341. jTextField4.setEnabled(true);
  342. this.aktywuj(false);
  343. dzialaj.serializuj();
  344. this.reset();
  345. return true;
  346. }
  347. if (index == indeksy.size()) {
  348. index = 0;
  349. }
  350. jLabel1.setText(dzialaj.getConcret(indeksy.get(index)).getEng1());
  351. jLabel2.setText(dzialaj.getConcret(indeksy.get(index)).getEng2());
  352. jLabel3.setText(dzialaj.getConcret(indeksy.get(index)).getEng3());
  353. jLabel4.setText(dzialaj.getConcret(indeksy.get(index)).getPol());
  354. this.reset();
  355. jButton2.setEnabled(true);
  356. return false;
  357. }
  358. public void czekaj(){
  359. try{
  360. Thread.sleep(5000);
  361. System.out.println("Nie mozna zatrzymać programu");
  362. }
  363. }
  364.  
  365. public void sprawdz() {
  366. /**
  367.   * Sprawdzamy pokolei czy wprowadzono poprawną wartość. Jeśli tak,
  368.   * ustawiamy zielone tło Jeśli nie, ustawiamy czerwone tło
  369.   */
  370. final Color ZIELONY = new Color(0,153,0);
  371. boolean wynik1 = dzialaj.sprawdzCzasownik(dzialaj.getConcret(indeksy.get(index)).getEng2(), jTextField1.getText());
  372. if (wynik1 == true) {
  373. jTextField1.setForeground(ZIELONY);
  374. } else {
  375. jTextField1.setForeground(Color.RED);
  376. jTextField1.setText(dzialaj.getConcret(indeksy.get(index)).getEng2());
  377. //jTextField1.setBackground(Color.RED);
  378. }
  379. boolean wynik2 = dzialaj.sprawdzCzasownik(dzialaj.getConcret(indeksy.get(index)).getEng3(), jTextField2.getText());
  380. if (wynik2 == true) {
  381. jTextField2.setForeground(ZIELONY);
  382. } else {
  383. jTextField2.setForeground(Color.RED);
  384. jTextField2.setText(dzialaj.getConcret(indeksy.get(index)).getEng3());
  385. }
  386. boolean wynik3 = dzialaj.sprawdzCzasownik(dzialaj.getConcret(indeksy.get(index)).getPol(), jTextField3.getText());
  387. if (wynik3 == true) {
  388. jTextField3.setForeground(ZIELONY);
  389. } else {
  390. jTextField3.setForeground(Color.RED);
  391. jTextField3.setText(dzialaj.getConcret(indeksy.get(index)).getPol());
  392. }
  393. /**
  394.   * Sprawdzamy czy wszystkie pola zostały poprawnie uzupełnione. Jeśli
  395.   * nie, ustawiamy błędną odpowiedź Jeśli tak, ustawiamy poprawną
  396.   * odpoweidź, usuwamy to słowo z aktualnej listy, obniżamy index.
  397. *
  398.   */
  399. if (wynik1 != true || wynik2 != true || wynik3 != true) {
  400. dzialaj.getConcret(indeksy.get(index)).setWynik(false);
  401. System.out.println(dzialaj.getConcret(indeksy.get(index)));
  402. } else {
  403. dzialaj.getConcret(indeksy.get(index)).setWynik(true);
  404. System.out.println(dzialaj.getConcret(indeksy.get(index)));
  405. indeksy.remove(index);
  406. index--;
  407. }
  408. jButton2.setEnabled(false);
  409. }
  410.  
  411. Dzialaj dzialaj;
  412. ArrayList<Integer> indeksy;
  413. private int index = -1;
  414. boolean test = true;
  415. // Variables declaration - do not modify
  416. private javax.swing.JButton jButton1;
  417. private javax.swing.JButton jButton2;
  418. private javax.swing.JLabel jLabel1;
  419. private javax.swing.JLabel jLabel2;
  420. private javax.swing.JLabel jLabel3;
  421. private javax.swing.JLabel jLabel4;
  422. private javax.swing.JMenu jMenu1;
  423. private javax.swing.JMenuBar jMenuBar1;
  424. private javax.swing.JMenuItem jMenuItem1;
  425. private javax.swing.JSlider jSlider1;
  426. private javax.swing.JTextField jTextField1;
  427. private javax.swing.JTextField jTextField2;
  428. private javax.swing.JTextField jTextField3;
  429. private javax.swing.JTextField jTextField4;
  430. // End of variables declaration
  431. }
  432.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:14: error: class Nieregularne is public, should be declared in a file named Nieregularne.java
public class Nieregularne extends javax.swing.JFrame {
       ^
Main.java:412: error: cannot find symbol
    Dzialaj dzialaj;
    ^
  symbol:   class Dzialaj
  location: class Nieregularne
Main.java:22: error: cannot find symbol
        dzialaj = new Dzialaj("czasowniki.ser");
                      ^
  symbol:   class Dzialaj
  location: class Nieregularne
Main.java:75: error: cannot find symbol
                jTextField1MouseDragged(evt);
                ^
  symbol: method jTextField1MouseDragged(MouseEvent)
Main.java:78: error: cannot find symbol
                jTextField1MouseMoved(evt);
                ^
  symbol: method jTextField1MouseMoved(MouseEvent)
Main.java:102: error: cannot find symbol
                jButton2ActionPerformed(evt);
                ^
  symbol: method jButton2ActionPerformed(ActionEvent)
Main.java:129: error: cannot find symbol
                jSlider1MouseClicked(evt);
                ^
  symbol: method jSlider1MouseClicked(MouseEvent)
Main.java:138: error: cannot find symbol
                jTextField4CaretUpdate(evt);
                ^
  symbol: method jTextField4CaretUpdate(CaretEvent)
Main.java:247: error: cannot find symbol
        dzialaj = new Dzialaj("czasowniki2.ser");
                      ^
  symbol:   class Dzialaj
  location: class Nieregularne
9 errors
stdout
Standard output is empty