Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************************/
- //klasa Program
- package coaAWT;
- import java.awt.*;
- import java.awt.event.*;
- public class Program extends Frame {
- Panel p1,p2,p3,p4;
- TextField[] txt=new TextField[3];
- Crtez c;
- Program(){
- setBounds(100,100,500,600);
- this.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- dispose();
- }
- });
- this.setLayout(new GridLayout(2,1));
- p1=new Panel();
- p1.setLayout(new GridLayout(1, 1));
- p2=new Panel();
- p2.add(new Label("tmin,tmax,dt:"));
- p2.add(txt[0]=new TextField("0"));
- p2.add(txt[1]=new TextField("10"));
- p2.add(txt[2]=new TextField("0.01"));
- c=new Crtez(new Spirala(0.5,1,0),Color.RED,Double.parseDouble(txt[0].getText()),Double.parseDouble(txt[1].getText()),Double.parseDouble(txt[2].getText()));
- c.setBackground(Color.orange);
- txt[0].addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- c.setminT(Double.parseDouble(txt[0].getText()));
- repaint();
- }
- });
- txt[1].addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- c.setmaxT(Double.parseDouble(txt[1].getText()));
- repaint();
- }
- });
- txt[2].addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- c.setKorak(Double.parseDouble(txt[2].getText()));
- repaint();
- }
- });
- p1.add(c);
- add(p2);
- add(p1);
- setVisible(true);
- }
- public static void main(String[] args) {
- new Program();
- }
- }
- /**************************************************************************/
- //Klasa Crtez
- package coaAWT;
- import java.awt.*;
- import java.awt.event.*;
- @SuppressWarnings("serial")
- public class Crtez extends Canvas {
- private Kriva kriva;
- private Color boja;
- private double minT, maxT, korak;
- public Crtez(Kriva k, Color b, double m, double mx, double kk) {
- kriva = k;
- boja = b;
- minT = m;
- maxT = mx;
- korak = kk;
- repaint();
- }
- public void paint(Graphics g) {
- g.drawString("PISEM PISEM PISEM", 100, 100);
- g.setColor(boja);
- double start = minT;
- double end = maxT;
- int x1, x2, y1, y2;
- Tacka t1 = kriva.izracunaj(start);
- x1 = (int) ((t1.getX()+10)*getWidth()/20);
- y1 = (int) ((10 - t1.getY())*getHeight()/20);
- while (start < end) {
- Tacka t2 = kriva.izracunaj(start);
- start += korak;
- x2 = (int) ((t2.getX()+10)*getWidth()/20);
- y2 = (int) ((10 - t2.getY())*getHeight()/20);
- g.drawLine(x1, y1, x2, y2);
- x1 = x2;
- y1 = y2;
- }
- }
- public void setminT(double m) {
- minT = m;
- repaint();
- }
- public void setmaxT(double m) {
- maxT = m;
- repaint();
- }
- public void setKorak(double m) {
- korak = m;
- repaint();
- }
- public void setBoja(Color b) {
- boja = b;
- repaint();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement