ImageManager program
<p>I am working on a project where I have to create an image manager program in Java. The program will have the following features in it: Program should take image from the user as input. Then it should display the image in panel(1), and in panel(2) it should give the user an options of changing width, height, hgap, vgap, top margin and left margin of the image with an 'OK' button at the end including an 'action listener' feature. Using the above mentioned features we will get the grids on the image. Now if the user clicks on the particular grid then that particular image should get extracted into a folder.
I am attaching the program which we have done so far. </p>

<p>The difficulties we are facing are: we are not able to insert a <code>JScrollPane</code> for the image. As well as we are unaware of how to add action listeners to the grids so that we can extract that particular image.</p>

<pre><code>package project_image_manager_imp_files;

import javax.swing.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.io.IOException;

class SidePanel1 extends JPanel implements ActionListener {

    JTextField top_margin = new JTextField(10);
    JTextField left_margin = new JTextField(10);
    JTextField Width = new JTextField(10);
    JTextField Height = new JTextField(10);
    JTextField Vgap = new JTextField(10);
    JTextField Hgap = new JTextField(10);
    JLabel j1 = new JLabel("Top margin");
    JLabel j2 = new JLabel("Left margin");
    JLabel j3 = new JLabel("Width");
    JLabel j4 = new JLabel("Height");
    JLabel j5 = new JLabel("Vertical gap");
    JLabel j6 = new JLabel("Horizontal gap");
    JButton b = new JButton("OK");

    public SidePanel1() {
        this.setBackground(Color.black);
        Dimension d1 = new Dimension(1000, 1000);
        this.setMaximumSize(d1);
        this.setPreferredSize(d1);

        JPanel p = new JPanel();
        JScrollPane vertical = new JScrollPane();
        vertical.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        add(vertical);
        vertical.setVerticalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        add(vertical);


        //showCoo.build(c);
        //c.add(p);
        //p.setOpaque(false);
        //t1.addActionListener(new JTextFieldEventClass() );
        //b.addActionListener(new JTextFieldEventClass() );

        // String s=t3.getText();
        //int c=Integer.parseInt(s);
        p.add(j1);
        p.add(top_margin);
        p.add(j2);
        p.add(left_margin);
        p.add(j3);
        p.add(Width);
        p.add(j4);
        p.add(Height);
        p.add(j5);
        p.add(Vgap);
        p.add(j6);
        p.add(Hgap);
        p.add(b);
        p.setLayout(new GridLayout(7, 2));
        b.addActionListener(this);
        JFrame frame = new JFrame();
        frame.setLayout(new GridLayout(1, 2));
        frame.setBounds(200, 200, 600, 400);
        frame.setTitle("Hello World Test");
        frame.setResizable(true);
        //frame.setSize (500, 300);
        Container c = frame.getContentPane();
        frame.setLayout(new BorderLayout());
        frame.add(this, BorderLayout.WEST);
        frame.add(p, BorderLayout.EAST);
        frame.pack();
        frame.setVisible(true);
        frame.setResizable(true);
    }
    int height;
    int width;
    int hgap;
    int vgap;
    int tm;
    int lm;

    public void paintComponent(Graphics g) {

        super.paintComponent(g);
        g.drawImage(Toolkit.getDefaultToolkit().getImage("images1.jpg"), 0, 0, this);
        Graphics2D g2d = (Graphics2D) g.create();
        //File f=new File("images1.jpg");
        //BufferedImage im=ImageIO.read(f);

        int frame_width = getWidth();
        int frame_height = getHeight();

        for (int j = 0; j &lt; frame_height; j++) {
            int y = tm + (height * j) + (vgap * j);
            for (int i = 0; i &lt; frame_width; i++) {
                int x = lm + (width * i) + (hgap * i);

                g.drawRect(x, y, width, height);
            }
        }
    }

    public static void main(String[] argv) {
        //static JScrollBar scrollbar;

        SidePanel1 panel = new SidePanel1();
        panel.setLayout(new FlowLayout());


        //scrollbar = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        //panel.add(scrollbar);
        try {
            while (true) {
                Thread.sleep(100);
                ///.out.println("("+MouseInfo.getPointerInfo().getLocation().x+", "+MouseInfo.getPointerInfo().getLocation().y+")");
            }
        } catch (InterruptedException e) {}
    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
        width = Integer.parseInt(Width.getText());
        height = Integer.parseInt(Height.getText());
        hgap = Integer.parseInt(Hgap.getText());
        vgap = Integer.parseInt(Vgap.getText());
        lm = Integer.parseInt(left_margin.getText());
        tm = Integer.parseInt(top_margin.getText());
        repaint();
    }
}
</code></pre>
