Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. package lab05;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.EventQueue;
  5.  
  6. import javax.swing.JFrame;
  7. import javax.swing.JPanel;
  8. import javax.swing.border.EmptyBorder;
  9. import net.miginfocom.swing.MigLayout;
  10. import javax.swing.JButton;
  11. import java.awt.FlowLayout;
  12. import javax.swing.JTextField;
  13. import javax.swing.JLabel;
  14. import java.awt.event.ActionListener;
  15. import java.io.File;
  16. import java.io.FileNotFoundException;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import java.util.Scanner;
  20. import java.awt.event.ActionEvent;
  21.  
  22. public class GUI extends JFrame {
  23.  
  24. private JPanel contentPane;
  25. private JTextField textNx;
  26. private JTextField textXmin;
  27. private JTextField textNy;
  28. private JTextField textYmin;
  29. private JTextField textYmax;
  30. protected JTextField textXmax;
  31. protected JTextField nazwaPliku;
  32. List<Integer> x = new ArrayList<Integer>();
  33. List<Integer> y = new ArrayList<Integer>();
  34. //int punkty[][];
  35. int Nx;
  36. int Ny;
  37. int Xmin;
  38. int Xmax;
  39. int Ymin;
  40. int Ymax;
  41.  
  42. public void wczytaj(JTextField field){
  43. String name = field.getText();
  44. boolean koniec = false;
  45. try{
  46. File file = new File(name);
  47. Scanner scc = new Scanner(file);
  48. while(!koniec){
  49. if(scc.hasNext())
  50. {
  51. x.add(scc.nextInt());
  52. y.add(scc.nextInt());
  53. }
  54. else
  55. koniec=true;
  56. }
  57. } catch(FileNotFoundException e){
  58. e.printStackTrace();
  59. }
  60.  
  61. }
  62. void aktualizuj(){
  63. Nx= Integer.parseInt(textNx.getText());
  64. Ny= Integer.parseInt(textNy.getText());
  65. Xmin= Integer.parseInt(textXmin.getText());
  66. Xmax= Integer.parseInt(textXmax.getText());
  67. Ymin= Integer.parseInt(textYmin.getText());
  68. Ymax= Integer.parseInt(textYmax.getText());
  69. }
  70.  
  71. /**
  72. * Launch the application.
  73. */
  74. public static void main(String[] args) {
  75. EventQueue.invokeLater(new Runnable() {
  76. public void run() {
  77. try {
  78. GUI frame = new GUI();
  79. frame.setVisible(true);
  80. } catch (Exception e) {
  81. e.printStackTrace();
  82. }
  83. }
  84. });
  85. }
  86.  
  87. /**
  88. * Create the frame.
  89. */
  90. public GUI() {
  91. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  92. setBounds(100, 100, 594, 414);
  93. contentPane = new JPanel();
  94. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  95. setContentPane(contentPane);
  96. contentPane.setLayout(new MigLayout("", "[][grow][::100px][::100px][]", "[][grow][][]"));
  97.  
  98. Wykres panel = new Wykres();
  99. contentPane.add(panel, "cell 1 1,grow");
  100.  
  101. JPanel panel_4 = new JPanel();
  102. contentPane.add(panel_4, "cell 2 1,grow");
  103. panel_4.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
  104.  
  105. JLabel lblNewLabel_1 = new JLabel("xMax");
  106. panel_4.add(lblNewLabel_1);
  107.  
  108. JLabel lblNewLabel = new JLabel("New label");
  109. panel_4.add(lblNewLabel);
  110.  
  111. JPanel panel_3 = new JPanel();
  112. contentPane.add(panel_3, "cell 3 1,grow");
  113. panel_3.setLayout(new MigLayout("", "[86px]", "[20px][20px][20px][20px][20px][20px][20px][][][]"));
  114.  
  115. textNx = new JTextField();
  116. panel_3.add(textNx, "cell 0 0,alignx left,aligny top");
  117. textNx.setColumns(10);
  118.  
  119. textNy = new JTextField();
  120. panel_3.add(textNy, "cell 0 2,alignx left,aligny top");
  121. textNy.setColumns(10);
  122.  
  123. textXmin = new JTextField();
  124. panel_3.add(textXmin, "cell 0 3,alignx left,aligny top");
  125. textXmin.setColumns(10);
  126.  
  127. textXmax = new JTextField();
  128. panel_3.add(textXmax, "cell 0 5,alignx left,aligny top");
  129. textXmax.setColumns(10);
  130.  
  131. textYmin = new JTextField();
  132. panel_3.add(textYmin, "cell 0 7,alignx left,aligny top");
  133. textYmin.setColumns(10);
  134.  
  135. textYmax = new JTextField();
  136. panel_3.add(textYmax, "cell 0 9,alignx left,aligny top");
  137. textYmax.setColumns(10);
  138.  
  139. JPanel panel_2 = new JPanel();
  140. FlowLayout flowLayout = (FlowLayout) panel_2.getLayout();
  141. flowLayout.setAlignment(FlowLayout.LEFT);
  142. contentPane.add(panel_2, "cell 1 2,grow");
  143.  
  144. JButton btnWczytaj = new JButton("Wczytaj plik");
  145. btnWczytaj.addActionListener(new ActionListener() {
  146. public void actionPerformed(ActionEvent arg0) {
  147. wczytaj(nazwaPliku);
  148. System.out.println(x.get(1));
  149. }
  150. });
  151. panel_2.add(btnWczytaj);
  152.  
  153. nazwaPliku = new JTextField();
  154. panel_2.add(nazwaPliku);
  155. nazwaPliku.setColumns(10);
  156.  
  157.  
  158.  
  159. JButton btnUpdate = new JButton("Aktualizuj dane");
  160. btnUpdate.addActionListener(new ActionListener() {
  161. public void actionPerformed(ActionEvent arg0) {
  162. aktualizuj();
  163. }
  164. });
  165. contentPane.add(btnUpdate, "cell 3 2");
  166.  
  167. JPanel panel_1 = new JPanel();
  168. FlowLayout flowLayout_1 = (FlowLayout) panel_1.getLayout();
  169. flowLayout_1.setAlignment(FlowLayout.RIGHT);
  170. contentPane.add(panel_1, "cell 1 3,grow");
  171.  
  172. JButton btnRysuj = new JButton("Rysuj");
  173. btnRysuj.addActionListener(new ActionListener() {
  174. public void actionPerformed(ActionEvent arg0) {
  175. panel.przekaz(Nx, Ny, Xmin, Xmax, Ymin, Ymax);
  176. panel.przekazPunkty(x, y);
  177. panel.repaint();
  178. }
  179. });
  180. panel_1.add(btnRysuj);
  181.  
  182. JButton btnPrzerysuj = new JButton("Przerysuj");
  183. btnPrzerysuj.addActionListener(new ActionListener() {
  184. public void actionPerformed(ActionEvent arg0) {
  185. }
  186. });
  187. panel_1.add(btnPrzerysuj);
  188. }
  189.  
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement