well… thats great if im wanting to zoom in on an image, but im working with an array of rectangles (the pixels that are drawn)
or should i convert that arraylist of rectangles to a jpg somehow, and just draw ontop of the jpeg (great except when they erase and area)
question: should i just figure out the size of my image, and do some math with that + the zoom ratio and then size the rectangles accordingly? or is there a easier way.
heres my code:
Main Class
package version01;
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class SeqyPaint{
JFrame frame;
JPanel panel;
public SeqyPaint(){
frame = new JFrame("Seqy Paint");
frame.setSize(100,100);
//panel = new JPanel(new FlowLayout());
addWidgets(frame.getContentPane());
//frame.getContentPane().add(panel);
//frame.pack();
frame.setSize(500,500);
frame.setVisible(true);
}
public void addWidgets(Container container){
DrawingArea drawing = new DrawingArea(this);
container.add(drawing);
}
public static void createAndShowGUI(){
SeqyPaint sp = new SeqyPaint();
}
public static void main(String[] args){
javax.swing.SwingUtilities.invokeLater(new Runnable(){
public void run(){
createAndShowGUI();
}
});
}
}
Drawing canvas
package version01;
import javax.swing.JComponent;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class DrawingArea extends JComponent implements MouseListener{
SeqyPaint controller;
ArrayList pixels;
public DrawingArea(SeqyPaint controller){
this.controller = controller;
pixels = new ArrayList();
addMouseListener(this);
}
public void paintComponent(Graphics g){
g.setColor(Color.BLUE);
g.fillRect(0,0,getWidth(), getHeight());
g.setColor(Color.GREEN);
g.drawRect(0,0,100,100);
drawPixels(g);
}
public void drawPixels(Graphics g){
for(int i=0;i<pixels.size();i++){
Pixel t = (Pixel)pixels.get(i);
g.setColor(new Color(t.R, t.B, t.G));
g.fillOval(t.p.x, t.p.y, 10, 10);
}
}
public void addPixel(MouseEvent e){
Pixel t = new Pixel();
t.R = 100;
t.G = 255;
t.B = 45;
t.p = e.getPoint();
pixels.add(t);
}
public void mouseEntered(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseClicked(MouseEvent e){
addPixel(e);
repaint();
}
public void mouseExited(MouseEvent e){}
}
Pixel (the rectangle)
package version01;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Pixel{
int R, B, G;
Point p;
public Pixel(){
}
}