Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. class ciara{
  7. private int x1;
  8. private int y1;
  9. private int x2;
  10. private int y2;
  11.  
  12. public ciara(int X1, int Y1, int X2, int Y2){
  13. x1 = X1;
  14. y1 = Y1;
  15. x2 = X2;
  16. y2 = Y2;
  17. }
  18.  
  19. public void nakreli(Graphics g){
  20. g.drawLine(x1, y1, x2, y2);
  21. }
  22.  
  23.  
  24. }
  25.  
  26. class platno extends Canvas{
  27. private ArrayList<ciara> lines = new ArrayList <ciara>();
  28. private long pocet = 0;
  29.  
  30. public void pridajCiaru(int X1, int Y1, int X2, int Y2){
  31. ciara l = new ciara(X1, Y1, X2, Y2);
  32. lines.add(l);
  33. }
  34.  
  35. @Override
  36. public void paint(Graphics g){
  37. for(ciara l: lines)
  38. l.nakreli(g);
  39. }
  40. }
  41.  
  42.  
  43.  
  44. public class zadanie1 {
  45.  
  46.  
  47. private void readSubor(){
  48. FileInputStream subor = null;
  49. try{
  50. subor = new FileInputStream("lines.txt");
  51. BufferedReader zoSuboru = new BufferedReader(new InputStreamReader(subor));
  52.  
  53. int pocetCiar = Integer.parseInt(zoSuboru.readLine());
  54.  
  55. int[] vektor = new int[pocetCiar*4];
  56.  
  57. for (int i=0; i<(pocetCiar*4); i++)
  58. vektor[i] = Integer.parseInt(zoSuboru.readLine());
  59.  
  60. zoSuboru.close();
  61. }
  62. catch(Exception e){
  63. System.out.println("Nemozem nacitat zo suboru.");
  64. }
  65. }
  66.  
  67. public static void main(String[] args) throws FileNotFoundException {
  68.  
  69.  
  70.  
  71. Frame f = new Frame();
  72. platno p = new platno();
  73. f.setSize(800, 600);
  74. f.add("Center", p);
  75. p.pridajCiaru(30, 30, 100, 100);
  76. //p.pridajCiaru(vektor[1], vektor[2], vektor[3], vektor[4]);
  77. f.addWindowListener(new WindowAdapter(){
  78. @Override
  79. public void windowClosing(WindowEvent we){
  80. System.exit(0);
  81. }});
  82. f.setVisible(true);
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement