Created
February 22, 2020 19:05
-
-
Save MinSomai/98e78ef7383c274ec886fdbc9deb331d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package hw; | |
| import java.awt.Color; | |
| import java.awt.Dimension; | |
| import java.awt.Graphics; | |
| import java.awt.Graphics2D; | |
| import java.awt.event.MouseEvent; | |
| import java.awt.event.MouseListener; | |
| import java.awt.image.BufferedImage; | |
| import javax.swing.JFrame; | |
| import javax.swing.JPanel; | |
| public class BoundryFillAlgorithm13 extends JPanel implements MouseListener{ | |
| private BufferedImage image,image1; | |
| private Graphics2D g2; | |
| public static void main(String[] args) { | |
| JFrame frame=new JFrame("First"); | |
| frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
| BoundryFillAlgorithm13 fill=new BoundryFillAlgorithm13(); | |
| frame.add(fill); | |
| frame.pack(); | |
| frame.setVisible(true); | |
| } | |
| public BoundryFillAlgorithm13() { | |
| image=new BufferedImage(500,500,BufferedImage.TYPE_INT_RGB); | |
| setPreferredSize(new Dimension(image.getWidth(),image.getHeight())); | |
| setMinimumSize(getPreferredSize()); | |
| g2=image.createGraphics(); | |
| g2.setColor(Color.BLACK); | |
| g2.drawRect(25,25,90,90); | |
| addMouseListener(this); | |
| image1=new BufferedImage(500,500,BufferedImage.TYPE_INT_RGB); | |
| setPreferredSize(new Dimension(image1.getWidth(),image1.getHeight())); | |
| setMinimumSize(getPreferredSize()); | |
| g2=image.createGraphics(); | |
| g2.setColor(Color.WHITE); | |
| g2.drawRect(10, 10, 120, 120); | |
| addMouseListener(this); | |
| } | |
| @Override | |
| public void paintComponent(Graphics g) { | |
| g.drawImage(image, 0, 0, null); | |
| } | |
| public void boundaryFill(int x,int y,int BC,int FC) { | |
| if(image.getRGB(x,y)!=BC&&image.getRGB(x,y)!=FC) { | |
| update(getGraphics()); | |
| image.setRGB(x,y,Color.red.getRGB()); | |
| boundaryFill(x+1,y,FC,BC); | |
| boundaryFill(x-1,y,FC,BC); | |
| boundaryFill(x,y+1,FC,BC); | |
| boundaryFill(x,y-1,FC,BC); | |
| } | |
| } | |
| public void mouseClicked(MouseEvent e) { | |
| boundaryFill(e.getX(),e.getY(),Color.WHITE.getRGB(),Color.red.getRGB()); | |
| } | |
| public void mousePressed(MouseEvent e) { | |
| // TODO Auto-generated method stub | |
| } | |
| public void mouseReleased(MouseEvent e) { | |
| // TODO Auto-generated method stub | |
| } | |
| public void mouseEntered(MouseEvent e) { | |
| // TODO Auto-generated method stub | |
| } | |
| public void mouseExited(MouseEvent e) { | |
| // TODO Auto-generated method stub | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment