Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication9;
- import java.util.Timer;
- import java.util.TimerTask;
- public class JavaApplication9 {
- Pot pot;
- Pot initPot;
- Timer timer;
- public static void main(String[] args) {
- JavaApplication9 app = new JavaApplication9();
- app.init();
- app.run();
- }
- public void init() {
- pot = new Pot();
- pot.init();
- pot.setParams(1, 2, 3, 4);
- timer = new Timer();
- }
- public void run() {
- try {
- pot.initPot = (Pot) pot.clone();
- initPot = (Pot) pot.clone();
- } catch (CloneNotSupportedException ex) {
- System.out.println("Объект не может быть клонированным.");
- }
- timer.schedule(new timerAction(), 1000);
- timer.schedule(new timerAction(), 1000);
- timer.schedule(new timerAction(), 1000);
- }
- class timerAction extends TimerTask {
- @Override
- public void run() {
- pot.setParams(pot.params.param1 + 1,
- pot.params.param2 + 1,
- pot.params.param3 + 1,
- pot.params.param4 + 1);
- System.out.println("pot.initPot: " + pot.initPot.params.param1);
- System.out.println("initPot: " + initPot.params.param1);
- }
- }
- }
- public class Pot implements Cloneable {
- PotParams params;
- Pot initPot;
- public void init() {
- params = new PotParams();
- }
- public void setParams(double p1, double p2, double p3, double p4) {
- params.param1 = p1;
- params.param2 = p2;
- params.param3 = p3;
- params.param4 = p4;
- }
- @Override
- public Pot clone() throws CloneNotSupportedException {
- return (Pot) super.clone();
- }
- }
- public class PotParams {
- public double param1;
- public double param2;
- public double param3;
- public double param4;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement