Skip to content

Instantly share code, notes, and snippets.

@AlexFrazer
Created October 20, 2012 15:47
Show Gist options
  • Save AlexFrazer/3923660 to your computer and use it in GitHub Desktop.
Save AlexFrazer/3923660 to your computer and use it in GitHub Desktop.
Grid maker
package Grid;
/**
* for artists, makes a super easy grid to follow.
* @Alex "Crowz" Frazer
*/
import java.awt.image.BufferedImage;
import java.awt.FlowLayout;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import javax.imageio.ImageIO;
public class GridFriend extends JFrame
{
/*variables*/
private int height=0;
private int width=0;
private double h_division=0;
private double v_division=0;
private BufferedImage finalImage=null;
private ImageIcon img;
private JButton make;
private JButton browse;
private JButton color;
private JTextField filename;
private JTextField h_divide;
private JTextField v_divide;
private JTextField dir;
private JTextField output;
final JFileChooser filec = new JFileChooser();
//constructor
public GridFriend() {
super("Grid Maker"); //title of the application
setLayout(new FlowLayout());
/** instantiating the variables */
h_divide=new JTextField("enter horizontal divisions");
v_divide=new JTextField("enter vertical divisions");
browse=new JButton("browse");
color=new JButton("Choose Color");
dir=new JTextField("Write file to here");
filename= new JTextField("file name");
make=new JButton("Finish");
output=new JTextField("picture height: " + height + " " +"picture width: "+width+ " "+"Horizontal divisions: " +h_division+" "+"Vertical Divisions: "+v_division);
/** adding to the panel */
add(h_divide);
add(v_divide);
add(filename);
add(dir);
add(color);
add(browse);
add(make);
add(output);
/** action listener */
Actionhandler handler= new Actionhandler();
browse.addActionListener(handler);
color.addActionListener(handler);
}
private class Actionhandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
//browse for file
if(e.getSource()==browse) {
try {
int val = filec.showOpenDialog(GridFriend.this);
/** convert the item to a BufferedImage */
if(val==JFileChooser.APPROVE_OPTION) {
File unfiltered_picture = filec.getSelectedFile();
finalImage = ImageIO.read(unfiltered_picture);
height=finalImage.getHeight();
width=finalImage.getWidth();
} else {
}
} catch(IOException exception) {
exception.printStackTrace();
}
}
//open the color browser to change the lines
if(e.getSource()==color) {
}
if(e.getSource()==make) {
/** write the file to the specified directory
try {
ImageIO.write(finalImage, "jpg", new File());
} catch (IOException exception) {
exception.printStackTrace();
}*/
}
if(e.getSource()==h_divide) {
double h=Double.valueOf(h_divide.getText());
h_division=width/h;
}
if(e.getSource()==v_divide) {
double v=Double.valueOf(v_divide.getText());
v_division=height/v;
}
}
}
/**public BufferedImage grid(BufferedImage img) {
for(int i=0; i<height; i++) {
}
for(int j=0; j<width; j++) {
}
}*/
}
package Grid;
import javax.swing.JFrame;
public class GUI
{
public static void main(String [] args) {
GridFriend grid = new GridFriend();
grid.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
grid.setSize(700, 1000);
grid.setVisible(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment