Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- import java.util.*;
- class ciara{
- private int x1;
- private int y1;
- private int x2;
- private int y2;
- public ciara(int X1, int Y1, int X2, int Y2){
- x1 = X1;
- y1 = Y1;
- x2 = X2;
- y2 = Y2;
- }
- public void nakreli(Graphics g){
- g.drawLine(x1, y1, x2, y2);
- }
- }
- class platno extends Canvas{
- private ArrayList<ciara> lines = new ArrayList <ciara>();
- private long pocet = 0;
- public void pridajCiaru(int X1, int Y1, int X2, int Y2){
- ciara l = new ciara(X1, Y1, X2, Y2);
- lines.add(l);
- }
- @Override
- public void paint(Graphics g){
- for(ciara l: lines)
- l.nakreli(g);
- }
- }
- public class zadanie1 {
- private void readSubor(){
- FileInputStream subor = null;
- try{
- subor = new FileInputStream("lines.txt");
- BufferedReader zoSuboru = new BufferedReader(new InputStreamReader(subor));
- int pocetCiar = Integer.parseInt(zoSuboru.readLine());
- int[] vektor = new int[pocetCiar*4];
- for (int i=0; i<(pocetCiar*4); i++)
- vektor[i] = Integer.parseInt(zoSuboru.readLine());
- zoSuboru.close();
- }
- catch(Exception e){
- System.out.println("Nemozem nacitat zo suboru.");
- }
- }
- public static void main(String[] args) throws FileNotFoundException {
- Frame f = new Frame();
- platno p = new platno();
- f.setSize(800, 600);
- f.add("Center", p);
- p.pridajCiaru(30, 30, 100, 100);
- //p.pridajCiaru(vektor[1], vektor[2], vektor[3], vektor[4]);
- f.addWindowListener(new WindowAdapter(){
- @Override
- public void windowClosing(WindowEvent we){
- System.exit(0);
- }});
- f.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement