import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.awt.image.*; public class Pildiredaktor2 extends Applet { Joonistusala ala=new Joonistusala(); public Pildiredaktor2(){ setLayout(new BorderLayout()); add(ala, BorderLayout.CENTER); ala.tyhjenda(); ala.paneVarv(Color.blue); ala.joon(50, 10, 200, 20); } public static void main(String[] arg){ Frame f=new Frame("Pildiredaktor"); f.add(new Pildiredaktor2()); f.setSize(300, 300); f.setVisible(true); } class Joonistusala extends Panel{ BufferedImage pilt=new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB); Graphics2D piltg=pilt.createGraphics(); public void paint(Graphics g){ g.drawImage(pilt, 0, 0, this); } public void tyhjenda(){ Color abivarv=piltg.getColor(); piltg.setColor(Color.white); piltg.fillRect(0, 0, 300, 300); piltg.setColor(abivarv); repaint(); } public void paneVarv(Color varv){ piltg.setColor(varv); } public void joon(int x1, int y1, int x2, int y2){ piltg.drawLine(x1, y1, x2, y2); repaint(); } } }