Stworzenie w javie ProgressMonitor


(Vegossj2) #1

Czytam toturiale i nie bardzo czaje jak dorobić do programu ProgressMonitor :frowning:

Stworzyłem programik który zadany obraz przekształca o macierz tranfrormacji.

klasa główna odpowiedzialna za wygląd

import java.awt.event.KeyEvent;

import javax.swing.ProgressMonitor;

import javax.swing.UIManager;



public class Macierz extends javax.swing.JFrame {


    Engine en = new Engine();

    public String file1;

    public String file2;

    private ProgressMonitor progressMonitor;


    public Macierz() {

        initComponents();

    }


    @SuppressWarnings("unchecked")

    // 

    private void initComponents() {


        jPanel1 = new javax.swing.JPanel();

        Wejscie = new javax.swing.JTextField();

        M22 = new javax.swing.JTextField();

        M12 = new javax.swing.JTextField();

        M02 = new javax.swing.JTextField();

        M01 = new javax.swing.JTextField();

        M11 = new javax.swing.JTextField();

        M21 = new javax.swing.JTextField();

        M20 = new javax.swing.JTextField();

        M10 = new javax.swing.JTextField();

        M00 = new javax.swing.JTextField();

        Img1 = new Obraz();

        Kat = new javax.swing.JTextField();

        jPanel2 = new javax.swing.JPanel();

        X = new javax.swing.JTextField();

        Y = new javax.swing.JTextField();

        Wyjcie = new javax.swing.JTextField();

        Metoda = new javax.swing.JComboBox();

        Transform = new javax.swing.JButton();

        Img2 = new Obraz();


        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        setTitle("Macierz");

        setBackground(new java.awt.Color(204, 255, 204));


        jPanel1.setBackground(new java.awt.Color(204, 255, 255));


        Wejscie.setText("c:\\trawa.jpg");

        Wejscie.addKeyListener(new java.awt.event.KeyAdapter() {

            public void keyReleased(java.awt.event.KeyEvent evt) {

                WejscieKeyReleased(evt);

            }

        });


        M22.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        M22.setText("1");


        M12.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        M12.setText("0");


        M02.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        M02.setText("0");


        M01.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        M01.setText("0");


        M11.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        M11.setText("1");


        M21.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        M21.setText("0");


        M20.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        M20.setText("0");


        M10.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        M10.setText("0");


        M00.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        M00.setText("1");


        javax.swing.GroupLayout Img1Layout = new javax.swing.GroupLayout(Img1);

        Img1.setLayout(Img1Layout);

        Img1Layout.setHorizontalGroup(

            Img1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGap(0, 183, Short.MAX_VALUE)

        );

        Img1Layout.setVerticalGroup(

            Img1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGap(0, 220, Short.MAX_VALUE)

        );


        Kat.setText("0");

        Kat.addKeyListener(new java.awt.event.KeyAdapter() {

            public void keyReleased(java.awt.event.KeyEvent evt) {

                KatKeyReleased(evt);

            }

        });


        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

        jPanel1.setLayout(jPanel1Layout);

        jPanel1Layout.setHorizontalGroup(

            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(jPanel1Layout.createSequentialGroup()

                .addContainerGap()

                .addComponent(M00, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                .addComponent(M10, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                .addComponent(M20, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addContainerGap(32, Short.MAX_VALUE))

            .addComponent(Img1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

            .addGroup(jPanel1Layout.createSequentialGroup()

                .addContainerGap()

                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addComponent(Wejscie, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)

                    .addGroup(jPanel1Layout.createSequentialGroup()

                        .addComponent(M01, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addComponent(M11, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addComponent(M21, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

                        .addComponent(Kat))

                    .addComponent(M02, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addGroup(jPanel1Layout.createSequentialGroup()

                        .addGap(49, 49, 49)

                        .addComponent(M12, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addComponent(M22, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)))

                .addContainerGap())

        );

        jPanel1Layout.setVerticalGroup(

            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()

                .addComponent(Img1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(M00, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(M10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(M20, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(M01, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(M11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(M21, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(Kat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(M02, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(M12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(M22, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                .addComponent(Wejscie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addContainerGap())

        );


        jPanel2.setBackground(new java.awt.Color(204, 255, 204));


        X.setText("100");


        Y.setText("100");


        Wyjcie.setText("C:\\wynik.bmp");


        Metoda.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sklaowanie", "Interpolacja dwulinowa", "Interpolacja bikubiczna" }));


        Transform.setText("Transformuj");

        Transform.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                TransformActionPerformed(evt);

            }

        });


        Img2.setBackground(new java.awt.Color(255, 255, 255));


        javax.swing.GroupLayout Img2Layout = new javax.swing.GroupLayout(Img2);

        Img2.setLayout(Img2Layout);

        Img2Layout.setHorizontalGroup(

            Img2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGap(0, 216, Short.MAX_VALUE)

        );

        Img2Layout.setVerticalGroup(

            Img2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGap(0, 217, Short.MAX_VALUE)

        );


        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);

        jPanel2.setLayout(jPanel2Layout);

        jPanel2Layout.setHorizontalGroup(

            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addComponent(Img2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

            .addGroup(jPanel2Layout.createSequentialGroup()

                .addContainerGap()

                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(jPanel2Layout.createSequentialGroup()

                        .addComponent(X, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)

                        .addComponent(Y, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))

                    .addComponent(Wyjcie, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)

                    .addComponent(Transform, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)

                    .addComponent(Metoda, javax.swing.GroupLayout.Alignment.TRAILING, 0, 196, Short.MAX_VALUE))

                .addContainerGap())

        );

        jPanel2Layout.setVerticalGroup(

            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()

                .addComponent(Img2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(X, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(Y, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                .addComponent(Wyjcie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                .addComponent(Metoda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                .addComponent(Transform)

                .addContainerGap())

        );


        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        getContentPane().setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

        );


        pack();

    }// 


    private void TransformActionPerformed(java.awt.event.ActionEvent evt) {                                          

        long start = System.currentTimeMillis();

        progressMonitor = new ProgressMonitor(Macierz.this,"przerysowywanie","",0,200);

        progressMonitor.setMillisToDecideToPopup(10);

        GetVar();

        Namaluj1(file1);

        en.transform();

        ((Obraz)Img2).obrazek = en.getImg2();

        repaint();

        en.zapis(file2);

        long stop = System.currentTimeMillis();

        System.out.println("Czas działania " + (stop-start) + " ms");

    }                                         


    void Namaluj1(String file){

        en.setImg(file);

        ((Obraz)Img1).obrazek = en.getImg1();

        repaint();

    }

     // 

    void GetVar(){

        float[][] m = new float[3][3];

        m[0][0] = Float.parseFloat(M00.getText().trim());

        m[0][1] = Float.parseFloat(M01.getText().trim());

        m[0][2] = Float.parseFloat(M02.getText().trim());

        m[1][0] = Float.parseFloat(M10.getText().trim());

        m[1][1] = Float.parseFloat(M11.getText().trim());

        m[1][2] = Float.parseFloat(M12.getText().trim());

        m[2][0] = Float.parseFloat(M20.getText().trim());

        m[2][1] = Float.parseFloat(M21.getText().trim());

        m[2][2] = Float.parseFloat(M22.getText().trim());

        en.setMatrix(m);

        en.setReslution(Integer.parseInt(X.getText().trim()), Integer.parseInt(Y.getText().trim()));

        file1 = Wejscie.getText().trim();

        file2 = Wyjcie.getText().trim();

        en.setType(Metoda.getSelectedIndex());

    }

    // 



    private void WejscieKeyReleased(java.awt.event.KeyEvent evt) {                                    

        if(KeyEvent.VK_ENTER==evt.getKeyCode()){

            Namaluj1(Wejscie.getText().trim());

        }

    }                                   


    private void KatKeyReleased(java.awt.event.KeyEvent evt) {                                

        if(KeyEvent.VK_ENTER==evt.getKeyCode()){


            float tmp = Float.parseFloat(Kat.getText().trim());

            tmp = (float) (tmp * Math.PI / 180);

           // double t = Math.cos(tmp);

            M00.setText(Math.cos(tmp)+"");

            M11.setText(Math.cos(tmp)+"");

            M10.setText(Math.sin(tmp)+"");

            M01.setText(-Math.sin(tmp)+"");


        }

    }                               


    public static void main(String args[]) {

        try {

            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

            }

        catch(Exception e) {

            throw new RuntimeException(e);

        }

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                new Macierz().setVisible(true);

            }

        });

    }


    // Variables declaration - do not modify                     

    private javax.swing.JPanel Img1;

    private javax.swing.JPanel Img2;

    private javax.swing.JTextField Kat;

    private javax.swing.JTextField M00;

    private javax.swing.JTextField M01;

    private javax.swing.JTextField M02;

    private javax.swing.JTextField M10;

    private javax.swing.JTextField M11;

    private javax.swing.JTextField M12;

    private javax.swing.JTextField M20;

    private javax.swing.JTextField M21;

    private javax.swing.JTextField M22;

    private javax.swing.JComboBox Metoda;

    private javax.swing.JButton Transform;

    private javax.swing.JTextField Wejscie;

    private javax.swing.JTextField Wyjcie;

    private javax.swing.JTextField X;

    private javax.swing.JTextField Y;

    private javax.swing.JPanel jPanel1;

    private javax.swing.JPanel jPanel2;

    // End of variables declaration                   


}

klasa pomocnicza odwalająca całą robotę robiąca to w 2 wątkach

import java.awt.Color;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import javax.swing.JComponent;

import javax.swing.ProgressMonitor;

import javax.swing.SwingWorker;


public class Engine {

    private float[][] m =new float[3][3];

    private int resX , resY;

    private BufferedImage img1 = null;

    private BufferedImage img2 = null;

    private int type;



// 

    public void transform() {

        img2 = new BufferedImage(resX, resY, BufferedImage.TYPE_INT_RGB);


        Runnable r1 = new Rysowanie(0);

        Runnable r2 = new Rysowanie(1);

        Thread T1 = new Thread(r1);

        Thread T2 = new Thread(r2);


        T1.start();

        T2.start();

        while (T1.isAlive() || T2.isAlive()) {

            try {

                Thread.sleep(10);

            } catch (InterruptedException ex) {

                System.out.println("błąd ze spaniem");

            }

        }

        System.gc();

    }// 


// 

    private Color getPix(int x, int y) {

        Color color;

        try {

            color = new Color(img1.getRGB(x, y));

        } catch (Exception ex) {

            color = new Color(200, 200, 200);

        }

        return color;

    }// 


// 

    private int skalowanie(float x, float y) {

        return getPix((int) x, (int) y).getRGB();

    }// 


// 

    private int dwuliniowe(float x, float y){

        int intX = (int)x;

        int intY = (int)y;


        Color a = getPix(intX,intY);

        Color b = getPix(intX,intY+1);

        Color c = getPix(intX+1,intY);

        Color d = getPix(intX+1,intY+1);


        float beta;

                if ((x-intX)<0) beta = 1+(x-intX);

                else beta = (x-intX);//dopisać coś na krawędzie

        float alfa;

                if ((y-intY)<0) alfa=1+(y-intY);

                else alfa= y-intY ;


        Color xab = new Color((int)((alfa)*b.getRed()+(1-alfa)*a.getRed()),

                (int)((alfa)*b.getGreen()+(1-alfa)*a.getGreen()),

                (int)((alfa)*b.getBlue()+(1-alfa)*a.getBlue()));

        Color xcd = new Color((int)((alfa)*d.getRed()+(1-alfa)*c.getRed()),

                (int)((alfa)*d.getGreen()+(1-alfa)*c.getGreen()),

                (int)((alfa)*d.getBlue()+(1-alfa)*c.getBlue()));

        Color xwynik = new Color((int)(beta*xcd.getRed()+(1-beta)*xab.getRed()),

                (int)(beta*xcd.getGreen()+(1-beta)*xab.getGreen()),

                (int)(beta*xcd.getBlue()+(1-beta)*xab.getBlue()));

        return xwynik.getRGB();

    }

        // 


// 

    private int bikubiczne(float x, float y) { //nie działa do końca poprawnie

        int intX = (int) x;

        int intY = (int) y;

        Color q00 = getPix(intX-1,intY-1);

        Color q01 = getPix(intX-1,intY);

        Color q02 = getPix(intX-1,intY+1);

        Color q03 = getPix(intX-1,intY+2);

        Color q10 = getPix(intX,intY-1);

        Color q11 = getPix(intX,intY);

        Color q12 = getPix(intX,intY+1);

        Color q13 = getPix(intX,intY+2);

        Color q20 = getPix(intX+1,intY-1);

        Color q21 = getPix(intX+1,intY);

        Color q22 = getPix(intX+1,intY+1);

        Color q23 = getPix(intX+1,intY+2);

        Color q30 = getPix(intX+2,intY-1);

        Color q31 = getPix(intX+2,intY);

        Color q32 = getPix(intX+2,intY+1);

        Color q33 = getPix(intX+2,intY+2);

        int[][] r = {

            {q00.getRed(),q10.getRed(),q20.getRed(),q30.getRed()},

            {q01.getRed(),q11.getRed(),q21.getRed(),q31.getRed()},

            {q02.getRed(),q12.getRed(),q22.getRed(),q32.getRed()},

            {q03.getRed(),q13.getRed(),q23.getRed(),q33.getRed()}

        };

        int[][] g = {

            {q00.getGreen(),q10.getGreen(),q20.getGreen(),q30.getGreen()},

            {q01.getGreen(),q11.getGreen(),q21.getGreen(),q31.getGreen()},

            {q02.getGreen(),q12.getGreen(),q22.getGreen(),q32.getGreen()},

            {q03.getGreen(),q13.getGreen(),q23.getGreen(),q33.getGreen()}

        };

        int[][] b = {

            {q00.getBlue(),q10.getBlue(),q20.getBlue(),q30.getBlue()},

            {q01.getBlue(),q11.getBlue(),q21.getBlue(),q31.getBlue()},

            {q02.getBlue(),q12.getBlue(),q22.getBlue(),q32.getBlue()},

            {q03.getBlue(),q13.getBlue(),q23.getBlue(),q33.getBlue()}

        };


        int red = bicubicInterpolate(r,x-intX,y-intY);

        int green = bicubicInterpolate(g,x-intX,y-intY);

        int blue = bicubicInterpolate(b,x-intX,y-intY);

        Color px ;

        try {px = new Color(red,green,blue);}

        catch (Exception ex) {

            px = new Color(200, 200, 200);

        }

        return px.getRGB();



    }


 private int bicubicInterpolate (int[][] p, double x, double y) {//kod znaleziony na http://www.paulinternet.nl/?page=bicubic

	double a00 = p[1][1];

	double a01 = p[1][2] - p[1][1]/2 - p[1][0]/3 - p[1][3]/6;

	double a02 = p[1][0]/2 - p[1][1] + p[1][2]/2;

	double a03 = p[1][1]/2 - p[1][0]/6 - p[1][2]/2 + p[1][3]/6;

	double a10 = p[2][1] - p[1][1]/2 - p[0][1]/3 - p[3][1]/6;

	double a11 = p[0][0]/9 + p[0][1]/6 - p[0][2]/3 + p[0][3]/18 + p[1][0]/6 + p[1][1]/4 - p[1][2]/2 + p[1][3]/12 - p[2][0]/3 - p[2][1]/2 + p[2][2] - p[2][3]/6 + p[3][0]/18 + p[3][1]/12 - p[3][2]/6 + p[3][3]/36;

	double a12 = p[0][1]/3 - p[0][0]/6 - p[0][2]/6 - p[1][0]/4 + p[1][1]/2 - p[1][2]/4 + p[2][0]/2 - p[2][1] + p[2][2]/2 - p[3][0]/12 + p[3][1]/6 - p[3][2]/12;

	double a13 = p[0][0]/18 - p[0][1]/6 + p[0][2]/6 - p[0][3]/18 + p[1][0]/12 - p[1][1]/4 + p[1][2]/4 - p[1][3]/12 - p[2][0]/6 + p[2][1]/2 - p[2][2]/2 + p[2][3]/6 + p[3][0]/36 - p[3][1]/12 + p[3][2]/12 - p[3][3]/36;

	double a20 = p[0][1]/2 - p[1][1] + p[2][1]/2;

	double a21 = p[0][2]/2 - p[0][1]/4 - p[0][0]/6 - p[0][3]/12 + p[1][0]/3 + p[1][1]/2 - p[1][2] + p[1][3]/6 - p[2][0]/6 - p[2][1]/4 + p[2][2]/2 - p[2][3]/12;

	double a22 = p[0][0]/4 - p[0][1]/2 + p[0][2]/4 - p[1][0]/2 + p[1][1] - p[1][2]/2 + p[2][0]/4 - p[2][1]/2 + p[2][2]/4;

	double a23 = p[0][1]/4 - p[0][0]/12 - p[0][2]/4 + p[0][3]/12 + p[1][0]/6 - p[1][1]/2 + p[1][2]/2 - p[1][3]/6 - p[2][0]/12 + p[2][1]/4 - p[2][2]/4 + p[2][3]/12;

	double a30 = p[1][1]/2 - p[0][1]/6 - p[2][1]/2 + p[3][1]/6;

	double a31 = p[0][0]/18 + p[0][1]/12 - p[0][2]/6 + p[0][3]/36 - p[1][0]/6 - p[1][1]/4 + p[1][2]/2 - p[1][3]/12 + p[2][0]/6 + p[2][1]/4 - p[2][2]/2 + p[2][3]/12 - p[3][0]/18 - p[3][1]/12 + p[3][2]/6 - p[3][3]/36;

	double a32 = p[0][1]/6 - p[0][0]/12 - p[0][2]/12 + p[1][0]/4 - p[1][1]/2 + p[1][2]/4 - p[2][0]/4 + p[2][1]/2 - p[2][2]/4 + p[3][0]/12 - p[3][1]/6 + p[3][2]/12;

	double a33 = p[0][0]/36 - p[0][1]/12 + p[0][2]/12 - p[0][3]/36 - p[1][0]/12 + p[1][1]/4 - p[1][2]/4 + p[1][3]/12 + p[2][0]/12 - p[2][1]/4 + p[2][2]/4 - p[2][3]/12 - p[3][0]/36 + p[3][1]/12 - p[3][2]/12 + p[3][3]/36;


	double x2 = x * x;

	double x3 = x2 * x;

	double y2 = y * y;

	double y3 = y2 * y;


	return (int)(a00 + a01 * y + a02 * y2 + a03 * y3 +

	       a10 * x + a11 * x * y + a12 * x * y2 + a13 * x * y3 +

	       a20 * x2 + a21 * x2 * y + a22 * x2 * y2 + a23 * x2 * y3 +

	       a30 * x3 + a31 * x3 * y + a32 * x3 * y2 + a33 * x3 * y3);

}

    // //inty sa za duze i wychodzi czarny


// 

    private BufferedImage getimg(String file) {

        try {

            img1 = javax.imageio.ImageIO.read(new File(file));

        } catch (IOException ex) {

            System.out.println("błąd wczytania obrazka " + ex);

        }

        return img1;

    }

    // 


// 

    public void setMatrix(float[][] mat) {//ustawienie macierzy transformacji

        MatrixCalculator matrix = new MatrixCalculator();

        try {

            m = matrix.Inverse(mat);

        } catch (Exception ex) {

            System.out.println("macierzy nie da się odwrócić");

        }


    }

     public void setReslution(int x, int y){//ustawienie rozdzielczości obrazka

        resX =x;

        resY =y;

     }


     public void setImg(String img){//ustawienie obrazka wejsciowego

        img1 = getimg(img);

     }


     public void setType(int z){//ustawienie metody 1-skalowanie, 2- dwulinowe, 3- bikubiczne

         type = z;

     }


     public BufferedImage getImg1(){//pobranie obr 1

        return img1;

     }


     public BufferedImage getImg2(){//pobranie obr 2

        return img2;

     }


    public void zapis(String file) {//zapis obrazka 2 na wskazane miejsce

        try {

            String tmp = file.substring(file.length() - 3);

            ImageIO.write(img2, tmp, new File(file));

        } catch (IOException ex) {

            System.out.println("błąd zapisu");

        }

    }



    // 


// 

    class Rysowanie implements Runnable

        {

        public int firstY =0;

        Rysowanie(int y){

            firstY = y;

        }

        public void run() {

            float oldX,oldY;

            for(int y =firstY;y
                for(int x =0;x
                    float w = m[2][0]*x+m[2][1]*x+m[2][2];

                    oldX = m[0][0]*x+m[0][1]*y+m[0][2];

                    oldY = m[1][0]*x+m[1][1]*y+m[1][2];

                    oldX /=w;

                    oldY /=w;

                    switch(type){

                            case 0 : img2.setRGB(x,y,skalowanie(oldX,oldY));break;

                            case 1 : img2.setRGB(x,y,dwuliniowe(oldX,oldY));break;

                            case 2 : img2.setRGB(x,y,bikubiczne(oldX,oldY));break;

                    }

                }

        }

        }


    }// 


}

Jak do tego dopisać ładne okienko które będzie pokazywać ile się wykonało. Zaznaczam że slaby jestem w Swingu i wygląd robię netbeansem