Guest User

Untitled

a guest
Apr 15th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.85 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package juna;
  6.  
  7. import com.mysql.jdbc.Connection;
  8. import java.sql.DriverManager;
  9. import java.util.Properties;
  10. import java.sql.*;
  11. import javax.swing.JFrame;
  12. /**
  13. *
  14. * @author Mikko
  15. */
  16. public class Main {
  17. public static void main(String[] args) {
  18. // Tieto tie = new Tieto();
  19.  
  20. try {
  21. // Vaihe 1: Ladataan JDBC-ajuri
  22. System.out.println("ripuli");
  23. String driver = "org.gjt.mm.mysql.Driver";
  24. Class.forName(driver).newInstance();
  25.  
  26.  
  27. // Vaihe 2: Määritellään yhteyden parametrit
  28. /* Properties props = new Properties();
  29. props.put("user", "mikkokoi");
  30. props.put("password", "8Fjkl12A");
  31. */
  32. // Vaihe 3: Avataan yhteys
  33.  
  34. String serverName= "localhost:3306";
  35. String url = "jdbc:mysql://" + serverName + "/mikkokoi?user=mikkokoi&password=mikkokoi";
  36. Connection con = (Connection) DriverManager.getConnection(url);
  37.  
  38. // Vaihe 4: Luodaan PreparedStatement, joka
  39. // sisältää tiedot hakevan SQL-kyselyn
  40. PreparedStatement s = con.prepareStatement("Select * From mikkokoi");
  41.  
  42. // Vaihe 5: Suoritetaan kysely, tulokset
  43. // tallentuvat ResultSet-muuttujaan
  44. ResultSet rs = s.executeQuery();
  45.  
  46. // Vaihe 6: Käydään kaikki kyselyn
  47. // palauttamat rivit
  48. // läpi ja tulostetaan rivien sisältö
  49. while (rs.next()) {
  50. System.out.println("nimi: " + rs.getString(1) + ", numero: " + rs.getString(2));
  51. }
  52.  
  53. // Vaihe 7: Suljetaan lopuksi yhteydet
  54. rs.close();
  55. con.close();
  56.  
  57. } catch (Exception e) {
  58. System.out.println("paskaa koodia");
  59. // e.printStackTrace();
  60. }
  61. run();
  62. // JFrame etu = Juna.luoIkkuna();
  63.  
  64.  
  65. }
  66. public static void run(){
  67. Juna juna = new Juna();
  68. juna.ekaIkkuna(/*etu,tie*/);
  69. }
  70. }
  71. package juna;
  72.  
  73. import java.awt.*;
  74. import java.awt.event.*;
  75. import javax.swing.*;
  76. /* @author LasseA */
  77.  
  78.  
  79. public class Kalenteri {
  80. public void Kalenteri(){
  81. }
  82. int month = java.util.Calendar.getInstance().get(java.util.Calendar.MONTH);
  83. int year = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR);
  84. int pvm = java.util.Calendar.getInstance().get(java.util.Calendar.DAY_OF_MONTH);
  85. int pvk = java.util.Calendar.getInstance().get(java.util.Calendar.DAY_OF_WEEK);
  86.  
  87.  
  88. JLabel l = new JLabel("", JLabel.CENTER);
  89. public String day, title = "";
  90. JDialog d;
  91. int i=0;
  92. public JButton[] button = new JButton[49];
  93.  
  94.  
  95.  
  96.  
  97. public String maaritaTitle () {
  98.  
  99. if (month == 0){
  100. title = "Tammikuu";
  101.  
  102. } else if (month == 1) {
  103. title = "Helmikuu";
  104. }
  105. else if (month == 2) {
  106. title = "Maaliskuu";
  107. }
  108. else if (month == 3) {
  109. title = "Huhtikuu";
  110. }
  111. else if (month == 4) {
  112. title = "Toukokuu";
  113. }
  114. else if (month == 5) {
  115. title = "Kesäkuu";
  116. }
  117. else if (month == 6) {
  118. title = "Heinäkuu";
  119. }
  120. else if (month == 7) {
  121. title = "Elokuu";
  122. }
  123. else if (month == 8) {
  124. title = "Syyskuu";
  125. }
  126. else if (month == 9) {
  127. title = "Lokakuu";
  128. }
  129. else if (month == 10) {
  130. title = "Marraskuu";
  131. }
  132. else if (month == 11) {
  133. title = "Joulukuu";
  134. }else if (month == 12){
  135. year++;
  136. month = 0;
  137. title = "Tammikuu";
  138. }
  139.  
  140.  
  141.  
  142.  
  143. return title;
  144.  
  145. }
  146.  
  147.  
  148. public Kalenteri (JFrame parent, final Tieto tie) {
  149.  
  150.  
  151.  
  152.  
  153. d = new JDialog();
  154. d.setModal(true);
  155.  
  156. String[] header = { "Su", "Ma", "Ti", "Ke", "To", "Pe", "La" };
  157. JPanel p1 = new JPanel(new GridLayout(7, 7));
  158. p1.setPreferredSize(new Dimension(480, 120));
  159.  
  160. //combokk.setSelectedIndex(4);
  161. //combokk.addActionListener(null);
  162. for (int x = 0; x < button.length; x++) {
  163. final int selection = x;
  164. for(i = 1; i<= pvm; i++){
  165.  
  166.  
  167.  
  168. }
  169. button[x] = new JButton("" + pvm);
  170. button[x].setFocusPainted(false);
  171. button[x].setBackground(Color.white);
  172.  
  173. if (x > 6)
  174. button[x].addActionListener(new ActionListener() {
  175. @Override
  176. public void actionPerformed(ActionEvent ae) {
  177. day = button[selection].getActionCommand();
  178. tie.setPvm(day);
  179. d.dispose();
  180. }
  181. });
  182. if (x < 7) {
  183. button[x].setText(header[x]);
  184. button[x].setForeground(Color.red);
  185. }
  186. p1.add(button[x]);
  187. }
  188.  
  189. JPanel p2 = new JPanel(new GridLayout(1, 3));
  190. JButton previous = new JButton("<< Edellinen kk");
  191. previous.addActionListener(new ActionListener() {
  192.  
  193. public void actionPerformed(ActionEvent ae) {
  194. //Jos mennään edelliseen vuoteen, tarvitaan siihen if lause joka tarkistaa napin painalluksessa
  195. if(month == 0){
  196. month = 12;
  197. year--;
  198. }
  199. month--;
  200. maaritaTitle();
  201. d.setTitle(title);
  202.  
  203.  
  204. }
  205. });
  206. p2.add(previous);
  207. p2.add(l);
  208. JButton next = new JButton("Seuraava kk >>");
  209. next.addActionListener(new ActionListener() {
  210. @Override
  211. public void actionPerformed(ActionEvent ae) {
  212.  
  213.  
  214. month++;
  215. maaritaTitle();
  216. d.setTitle(title);
  217. // System.out.println(title);
  218.  
  219.  
  220. }
  221. });
  222.  
  223. p2.add(next);
  224. d.add(p1, BorderLayout.CENTER);
  225. d.add(p2, BorderLayout.SOUTH);
  226. d.pack();
  227. d.setLocationRelativeTo(parent);
  228. maaritaTitle();
  229. d.setTitle(title);
  230.  
  231. d.setVisible(true);
  232. }
  233.  
  234. /*public static void main (String [] args) {
  235. Kalenteri kalu = new Kalenteri(null);
  236.  
  237.  
  238. }*/
  239. }
  240. package juna;
  241. import java.awt.BorderLayout;
  242. import java.awt.Color;
  243. import java.awt.Container;
  244. import java.awt.Dimension;
  245. import java.awt.FlowLayout;
  246. import java.awt.Graphics;
  247. import java.awt.GridBagConstraints;
  248. import java.awt.GridBagLayout;
  249. import java.awt.GridLayout;
  250. import java.awt.Image;
  251. import java.awt.Insets;
  252. import java.awt.MediaTracker;
  253. import java.awt.Toolkit;
  254. import java.sql.PreparedStatement;
  255. import java.sql.ResultSet;
  256. import java.util.Properties;
  257. import java.sql.Connection;
  258. import java.sql.DriverManager;
  259. import java.awt.event.ActionListener;
  260. import java.awt.event.ActionEvent;
  261. import javax.swing.*;
  262. import javax.swing.KeyStroke;
  263. import java.util.*;
  264. /**
  265. *
  266. * @author Mikko
  267. */
  268. public class Juna {
  269.  
  270. public void Juna(){}
  271. /**
  272.  
  273. * LUODAAN MAIN METODISSA TIETOKANTAYHTEYS SEKÄ KUTSUTAAN IKKUNAA
  274. */
  275.  
  276. /* @SuppressWarnings("CallToThreadDumpStack")
  277. public static void main(String[] args) {
  278. Tieto tie = new Tieto();
  279.  
  280. try {
  281. // Vaihe 1: Ladataan JDBC-ajuri
  282. System.out.println("ripuli");
  283. String driver = "org.apache.derby.jdbc.ClientDriver";
  284. Class.forName(driver).newInstance();
  285.  
  286.  
  287. // Vaihe 2: Määritellään yhteyden parametrit
  288. Properties props = new Properties();
  289. props.put("user", "test");
  290. props.put("password", "test");
  291.  
  292. // Vaihe 3: Avataan yhteys
  293. String url = "jdbc:derby://localhost:1527/Juna";
  294.  
  295. Connection conn = DriverManager.getConnection(url , props);
  296.  
  297. // Vaihe 4: Luodaan PreparedStatement, joka
  298. // sisältää tiedot hakevan SQL-kyselyn
  299. PreparedStatement s = conn.prepareStatement("Select nimi, numero from APP.VAUNU");
  300.  
  301. // Vaihe 5: Suoritetaan kysely, tulokset
  302. // tallentuvat ResultSet-muuttujaan
  303. ResultSet rs = s.executeQuery();
  304.  
  305. // Vaihe 6: Käydään kaikki kyselyn
  306. // palauttamat rivit
  307. // läpi ja tulostetaan rivien sisältö
  308. while (rs.next()) {
  309. System.out.println("nimi: " + rs.getString(1) + ", numero: " + rs.getString(2));
  310. }
  311.  
  312. // Vaihe 7: Suljetaan lopuksi yhteydet
  313. rs.close();
  314. conn.close();
  315.  
  316. } catch (Exception e) {
  317. System.out.println("paskaa koodia");
  318. e.printStackTrace();
  319. }
  320. JFrame etu =luoIkkuna();
  321. ekaIkkuna(etu,tie);
  322.  
  323. }*/
  324. public JFrame luoIkkuna(){
  325.  
  326. JFrame etu = new JFrame("Junanvaraus");
  327.  
  328. //MEnun teko
  329. JMenuBar bar = new JMenuBar();
  330. JMenu menu = new JMenu("File");
  331. bar.add(menu);
  332.  
  333. JMenuItem nappi = new JMenuItem("help");
  334. JMenuItem nappi2 = new JMenuItem("exit");
  335.  
  336.  
  337. menu.add(nappi);
  338. menu.add(new JSeparator()); // SEPARATOR
  339. menu.add(nappi2);
  340.  
  341. etu.setJMenuBar(bar);
  342. /*
  343. *
  344. *
  345. *
  346. *
  347. *
  348. Tehdään actionlistenerit suorittamaan nappuloista tapahtuvia toimintoja mm menuvalikoista.
  349. */ etu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  350. ActionListener actionListener = new ActionListener(){
  351. @Override
  352. public void actionPerformed(ActionEvent actionEvent){
  353. System.out.println("nappia painettu");
  354. System.exit(0);
  355.  
  356. }
  357. };
  358.  
  359.  
  360. ActionListener actionListener3 = new ActionListener(){
  361. @Override
  362. public void actionPerformed(ActionEvent actionEvent){
  363. kaynnistaHelp();
  364.  
  365. }
  366. };
  367.  
  368. nappi.addActionListener(actionListener3);
  369. nappi2.addActionListener(actionListener);
  370. //säädetään ikkunan kokoa ja asetetaan ikkuna näkyväksi
  371.  
  372.  
  373.  
  374. etu.setSize(750,500);
  375. etu.setVisible(true);
  376.  
  377.  
  378.  
  379. return etu;
  380. }
  381.  
  382. /*
  383. Tehdään help toiminto MUISTA KIRJOTTAA TUO TEKSTI SINNE JOSSAIN VÄLISSÄ
  384. */
  385. public void kaynnistaHelp(){
  386.  
  387. String msg = "<html>KIRJOTA TÄHÄN helppi<br>BR VAIHTAA RIVIÄ";
  388.  
  389. JOptionPane optionPane = new NarrowOptionPane();
  390. optionPane.setMessage(msg);
  391. optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
  392. JDialog dialog = optionPane.createDialog(null, "HELP");
  393. dialog.setVisible(true);
  394. }
  395.  
  396.  
  397.  
  398. public void ekaIkkuna(/*final JFrame etu,final Tieto tie*/){
  399. final Tieto tie = new Tieto();
  400. final JFrame etu = luoIkkuna();
  401. JButton b1 = new JButton("kemi-oulu");
  402. JButton b2 = new JButton("Oulu-Kemi");
  403. JButton b3 = new JButton("Oulu-Kempele");
  404. JButton b4 = new JButton("Kempele-Oulu");
  405. JButton b5 = new JButton("Jatka");
  406. JButton b6 = new JButton ("Peruuta");
  407. // b1.setPreferredSize(new Dimension(20,30));
  408. /*etu.setLayout(null);
  409. etu.setBounds(50, 50, 300, 300);*/
  410.  
  411. // Container content = etu.getContentPane();
  412. // content.setLayout(new GridBagLayout());
  413. JPanel napit = new JPanel(new GridBagLayout());
  414. etu.getContentPane().add(napit, BorderLayout.NORTH);
  415. GridBagConstraints grid = new GridBagConstraints();
  416. napit.setBackground(Color.BLUE);
  417. grid.fill = GridBagConstraints.HORIZONTAL;
  418. grid.gridwidth = 1;
  419. grid.gridheight = 1;
  420. grid.weightx = 0;
  421. grid.insets = new Insets(10,10,10,10);
  422. grid.fill = GridBagConstraints.HORIZONTAL;
  423. grid.gridx = 5;
  424. grid.gridy = 1;
  425. napit.add(b1, grid);
  426.  
  427. grid.fill = GridBagConstraints.HORIZONTAL;
  428. grid.weightx = 0;
  429. grid.gridx = 5;
  430. grid.gridy = 2;
  431. napit.add(b2, grid);
  432.  
  433. grid.fill = GridBagConstraints.HORIZONTAL;
  434. grid.weightx = 0;
  435. grid.gridx = 5;
  436. grid.gridy =3;
  437. napit.add(b3, grid);
  438.  
  439. grid.fill = GridBagConstraints.HORIZONTAL;
  440. grid.weightx = 0;
  441. grid.gridx = 5;
  442. grid.gridy = 4;
  443. napit.add(b4, grid);
  444.  
  445. JPanel apupane = new JPanel(new GridBagLayout());
  446. etu.getContentPane().add(apupane, BorderLayout.LINE_END);
  447. apupane.setBackground(Color.PINK);
  448.  
  449.  
  450. grid.weightx =0.5;
  451. grid.weighty = 1;
  452. grid.gridx = 3;
  453. grid.gridy = 1;
  454. grid.anchor = GridBagConstraints.LAST_LINE_END;
  455. apupane.add(b5, grid);
  456. //grid.fill = GridBagConstraints.HORIZONTAL;
  457. // grid.fill = GridBagConstraints.HORIZONTAL;
  458. grid.weightx = 0.5;
  459. grid.gridx = 2;
  460. grid.gridy = 1;
  461.  
  462. apupane.add(b6,grid);
  463.  
  464.  
  465.  
  466.  
  467. ActionListener actionListener2 = new ActionListener(){
  468. @Override
  469. public void actionPerformed(ActionEvent actionEvent){
  470. System.out.println("nappia painettu");
  471. TokaIkkuna toka = new TokaIkkuna();
  472. etu.setVisible(false);
  473. toka.teeKentat(luoIkkuna(),tie);
  474. }
  475. };
  476. ActionListener actionListener4 = new ActionListener(){
  477. @Override
  478. public void actionPerformed(ActionEvent actionEvent){
  479. String kohde = "kemi-Oulu";
  480. tie.setKohde(kohde);
  481. tie.getKohde();
  482. Kalenteri kal = new Kalenteri(null, tie);
  483. tie.getPvm();
  484. }
  485. };
  486. ActionListener actionListener5 = new ActionListener(){
  487. @Override
  488. public void actionPerformed(ActionEvent actionEvent){
  489. String kohde = "Oulu-Kemi";
  490. tie.setKohde(kohde);
  491. tie.getKohde();
  492. Kalenteri kal = new Kalenteri(null,tie);
  493. tie.getPvm();
  494. }
  495. };
  496. ActionListener actionListener6 = new ActionListener(){
  497. @Override
  498. public void actionPerformed(ActionEvent actionEvent){
  499. String kohde = "Oulu-Kempele";
  500. tie.setKohde(kohde);
  501. tie.getKohde();
  502. Kalenteri kal = new Kalenteri(null,tie);
  503. tie.getPvm();
  504. }
  505. };
  506. ActionListener actionListener7 = new ActionListener(){
  507. @Override
  508. public void actionPerformed(ActionEvent actionEvent){
  509. String kohde = "Kempele-Oulu";
  510. tie.setKohde(kohde);
  511. tie.getKohde();
  512. Kalenteri kal = new Kalenteri(null,tie);
  513. tie.getPvm();
  514. }
  515. };
  516.  
  517. //liitetään actionlistenerit nappiin
  518. b1.addActionListener(actionListener4);
  519. b2.addActionListener(actionListener5);
  520. b3.addActionListener(actionListener6);
  521. b4.addActionListener(actionListener7);
  522. b5.addActionListener(actionListener2);
  523.  
  524. }
  525. }
  526.  
  527. class NarrowOptionPane extends JOptionPane {
  528.  
  529. NarrowOptionPane() {
  530. }
  531. }
  532.  
  533. package juna;
  534. import java.io.*;
  535. import javax.swing.*;
  536. import javax.swing.JOptionPane;
  537. import java.awt.Component;
  538. import java.awt.*;
  539. import java.awt.event.*;
  540.  
  541.  
  542. public class TokaIkkuna{
  543. public void TokaIkkuna(){}
  544. public void teeKentat( final JFrame etu, final Tieto tie){
  545.  
  546.  
  547. //Luodaan napit ja asetetaan gridbaglayout paneen.
  548. JButton button, button2;
  549. final JPanel pane = new JPanel();
  550. JPanel pane2 = new JPanel();
  551. JPanel pane3 = new JPanel();
  552. JPanel pane4 = new JPanel();
  553.  
  554.  
  555.  
  556. pane4.setLayout(new GridBagLayout());
  557. pane3.setLayout(new GridBagLayout());
  558. pane2.setLayout(new GridBagLayout());
  559. pane.setLayout(new GridBagLayout());
  560. pane.setBackground(Color.blue);
  561. pane4.setBackground(Color.cyan);
  562. pane2.setBackground(Color.red);
  563. pane3.setBackground(Color.green);
  564.  
  565.  
  566. GridBagConstraints c = new GridBagConstraints();
  567. etu.add(pane, BorderLayout.SOUTH);
  568. etu.add(pane2, BorderLayout.CENTER);
  569. etu.add(pane3, BorderLayout.LINE_START);
  570. etu.add(pane4, BorderLayout.PAGE_START);
  571.  
  572.  
  573. button = new JButton("Jatka");
  574. c.weighty = 1;
  575. c.weightx = 3;
  576. c.gridx = 3;
  577. c.gridy = 1;
  578. c.anchor = GridBagConstraints.LAST_LINE_END;
  579. pane.add(button, c);
  580.  
  581.  
  582.  
  583. button2 = new JButton("Takaisin");
  584. c.weighty = 1;
  585. c.weightx = 210;
  586. c.gridheight = 1;
  587. c.gridx = 2;
  588. c.gridy = 1;
  589. pane.add(button2, c);
  590.  
  591. //*****************************************************************************
  592. c.gridwidth = 0;
  593. ///LUODAAN TEKSTIKENT�T JA NIIDEN LABELIT
  594. Tieto tiet = new Tieto();
  595. final JTextField tekstiKentta = new JTextField(tiet.getNimi(),20);
  596. JLabel label1 = new JLabel ("Nimi: ");
  597. label1.setLabelFor(tekstiKentta);
  598. label1.setDisplayedMnemonic(KeyEvent.VK_N);
  599. c.insets= new Insets(5,5,5,5);
  600. c.weightx= 0;
  601. c.weighty = 0;
  602. c.gridx = 1;
  603. c.gridy = 0;
  604. pane2.add(tekstiKentta, c);
  605.  
  606. c.weighty= 0;
  607. c.weightx = 0;
  608. c.gridx = 0;
  609. c.gridy = 0;
  610. pane2.add(label1, c);
  611.  
  612. final JTextField tekstiKentta2 = new JTextField(tiet.getPuh(),20);
  613. JLabel label2 = new JLabel ("Osoite: ");
  614. label2.setDisplayedMnemonic(KeyEvent.VK_N);
  615. label2.setLabelFor(tekstiKentta2);
  616. tekstiKentta2.setHorizontalAlignment(JTextField.CENTER);
  617.  
  618. c.weighty = 0;
  619. c.weightx = 0;
  620. c.gridx = 1;
  621. c.gridy = 1;
  622. pane2.add(tekstiKentta2, c);
  623.  
  624. c.weighty = 0;
  625. c.weightx = 0;
  626. c.gridx =0;
  627. c.gridy = 1;
  628. pane2.add(label2, c);
  629.  
  630. final JTextField tekstiKentta3 = new JTextField(tiet.getOsote(),20);
  631. JLabel label3 = new JLabel ("PUH: ");
  632. label3.setDisplayedMnemonic(KeyEvent.VK_N);
  633. label3.setLabelFor(tekstiKentta3);
  634. c.weighty = 0;
  635. c.weightx = 0;
  636. c.gridx=0;
  637. c.gridy=2;
  638. pane2.add(label3, c);
  639.  
  640.  
  641. c.weighty = 0;
  642. c.weightx = 0;
  643. c.gridx = 1;
  644. c.gridy = 2;
  645. // pane2.add(label3, c);
  646. pane2.add(tekstiKentta3, c);
  647.  
  648.  
  649. c.weighty = 0;
  650. c.weightx = 0;
  651. c.gridx = 0;
  652. c.gridy = 0;
  653. //Actionlistenerit jatka ja takaisin nappeihin
  654.  
  655.  
  656.  
  657.  
  658. ActionListener actionListener1 = new ActionListener(){
  659. public void actionPerformed(ActionEvent actionEvent){
  660.  
  661. String nimi = tekstiKentta.getText();
  662. String osoite = tekstiKentta2.getText();
  663. String puh = tekstiKentta3.getText();
  664.  
  665. //Tsekataan jos on sy�tetty nimeen numeroita tai puhelinnumeroon kirjaimia, errorit sen mukaan jos tarpeellista.
  666.  
  667. for (int i=0; i<nimi.length();i++){
  668. if(Character.isDigit(nimi.charAt(i))){
  669. JOptionPane.showMessageDialog(pane, "�l� pist� numeroita nimees!");
  670. break;
  671. }
  672. }
  673.  
  674. for (int i=0; i<puh.length();i++){
  675. if(Character.isLetter(puh.charAt(i))){
  676. JOptionPane.showMessageDialog(pane, "Puhelinnumeroon sallitaan vain numeroita :-)");
  677. break;
  678. }
  679. }
  680.  
  681.  
  682. System.out.println(nimi + osoite + puh);
  683. KolmasIkkuna kolmas = new KolmasIkkuna();
  684. etu.setVisible(false);
  685. Juna juna = new Juna();
  686. kolmas.kolmas(juna.luoIkkuna(),tie);
  687. //T�h�n viel� siirtym�, nimi osoite ja puh sis�lt�v�t tiedot.
  688. }
  689.  
  690.  
  691. };
  692.  
  693.  
  694. ActionListener actionListener2 = new ActionListener(){
  695. @Override
  696. public void actionPerformed(ActionEvent actionEvent){
  697. System.out.println("Takaisin painettu");
  698. //T�h�n mit� tapahtuu ku painaa takaisin
  699. etu.setVisible(false);
  700. Juna juna = new Juna();
  701. juna.ekaIkkuna();
  702. }
  703. };
  704.  
  705.  
  706.  
  707. //Jos klikkaa tekstikentt�� niin l�htee ohjeteksti pois
  708. tekstiKentta.addMouseListener(new java.awt.event.MouseAdapter(){
  709. @Override
  710. public void mouseClicked(java.awt.event.MouseEvent e) {
  711. tekstiKentta.setText("");
  712. }
  713. });
  714. tekstiKentta2.addMouseListener(new java.awt.event.MouseAdapter(){
  715. @Override
  716. public void mouseClicked(java.awt.event.MouseEvent e){
  717. tekstiKentta2.setText("");
  718. }
  719. });
  720. tekstiKentta3.addMouseListener(new java.awt.event.MouseAdapter(){
  721.  
  722. public void mouseClicked(java.awt.event.MouseEvent e){
  723. tekstiKentta3.setText("");
  724. }
  725. });
  726.  
  727.  
  728. //Lis�t��n napeille actionlistenerit
  729. button.addActionListener(actionListener1);
  730. button2.addActionListener(actionListener2);
  731.  
  732.  
  733. pane.setVisible(true);
  734.  
  735.  
  736. }
  737.  
  738.  
  739.  
  740. }
  741.  
  742. package juna;
  743.  
  744. import javax.swing.JFrame;
  745. import javax.swing.*;
  746. import java.awt.*;
  747. import java.awt.event.ActionEvent;
  748. import java.awt.event.ActionListener;
  749. /**
  750. *
  751. * @author Mikko
  752. */
  753. class KolmasIkkuna {
  754. public void KolmaIkkuna(){}
  755. public void kolmas(JFrame etu, Tieto tie){
  756. JPanel pane= new JPanel(new BorderLayout());
  757.  
  758. etu.add(pane, BorderLayout.CENTER);
  759. JTextArea are = new JTextArea( tie.getNimi(),10,10);
  760. pane.add(are, BorderLayout.NORTH);
  761. pane.setBackground(Color.blue);
  762.  
  763. alanapit(etu,tie);
  764. }
  765.  
  766. public void alanapit(final JFrame etu, final Tieto tie ){
  767.  
  768. JButton b5 = new JButton("Hyväksy");
  769. JButton b6 = new JButton ("Peruuta");
  770. JPanel napit = new JPanel(new GridBagLayout());
  771. GridBagConstraints grid = new GridBagConstraints();
  772. JPanel apupane = new JPanel(new GridBagLayout());
  773. etu.getContentPane().add(apupane, BorderLayout.LINE_END);
  774. apupane.setBackground(Color.PINK);
  775.  
  776.  
  777. grid.weightx =0.5;
  778. grid.weighty = 1;
  779. grid.gridx = 3;
  780. grid.gridy = 1;
  781. grid.anchor = GridBagConstraints.LAST_LINE_END;
  782. apupane.add(b5, grid);
  783. //grid.fill = GridBagConstraints.HORIZONTAL;
  784. // grid.fill = GridBagConstraints.HORIZONTAL;
  785. grid.weightx = 0.5;
  786. grid.gridx = 2;
  787. grid.gridy = 1;
  788.  
  789. apupane.add(b6,grid);
  790. tie.getKohde();
  791. tie.getNimi();
  792. tie.getOsote();
  793. tie.getPuh();
  794. tie.getPvm();
  795. ActionListener actionListener2 = new ActionListener(){
  796. @Override
  797. public void actionPerformed(ActionEvent actionEvent){
  798. System.out.println("nappia painettu");
  799. Juna juna = new Juna();
  800. TokaIkkuna toka = new TokaIkkuna();
  801. etu.setVisible(false);
  802. toka.teeKentat(juna.luoIkkuna(),tie);
  803. }
  804. };
  805. ActionListener actionListener1 = new ActionListener(){
  806. @Override
  807. public void actionPerformed(ActionEvent actionEvent){
  808. System.out.println("nappia painettu");
  809. Juna juna = new Juna();
  810. TokaIkkuna toka = new TokaIkkuna();
  811. etu.setVisible(false);
  812. toka.teeKentat(juna.luoIkkuna(),tie);
  813. }
  814. };
  815. b6.addActionListener(actionListener2);
  816.  
  817. b5.addActionListener(actionListener1);
  818.  
  819. }
  820. }
  821. package juna;
  822.  
  823. /**
  824. *
  825. * @author Mikko
  826. */
  827. public class Tieto {
  828. public void Tieto(){}
  829. public String kohde=null;
  830. public String nimi=null;
  831. public String pvm=null;
  832. public String osoite=null;
  833. public String puh=null;
  834.  
  835. public void setKohde(String koh){
  836. this.kohde = koh;
  837.  
  838. }
  839.  
  840. public String getKohde(){
  841. System.out.println(kohde);
  842. return kohde;
  843. }
  844. public void setNimi(String nimi){
  845. this.nimi=nimi;
  846. }
  847. public String getNimi(){
  848. return nimi;
  849. }
  850.  
  851. public void setPvm(String pvm){
  852. this.pvm=pvm;
  853. }
  854. public String getPvm(){
  855. System.out.println(pvm);
  856. return pvm;
  857. }
  858.  
  859. public void setOsote(String osote){
  860. this.osoite=osote;
  861. }
  862. public String getOsote(){
  863. return osoite;
  864. }
  865. public void setPuh(String puh){
  866. this.puh=puh;
  867.  
  868. }
  869. public String getPuh(){
  870. return puh;
  871. }
  872. }
Add Comment
Please, Sign In to add comment